2 Variable::Temp - Temporarily change the value of a variable.
8 use Variable::Temp 'temp';
19 This module provides an utility routine that can be used to temporarily
20 change the value of a variable, until the end of the current scope is
21 reached where the original value of the variable is restored. It is
22 similar to "local", except that it can be applied onto lexicals as well
23 as globals, and that it replaces values by copying the new value into
24 the container variable instead of by aliasing.
31 Temporarily replace the value of the lexical or global variable $var by
32 $value, or by "undef" if $value is omitted, until the end of the current
33 scope. Any subsequent assignments to $var in the current (or any
34 inferior) scope will not affect the original value which will be
35 restored into the variable at scope end. Several "temp" calls can be
36 made onto the same variable, and the restore are processed in reverse
39 Note that destructors associated with $var will not be called when
40 "temp" sets the temporary value, but only at the natural end of life of
41 the variable (i.e. at the end of the scope). They will trigger after any
42 destructor associated with the replacement $var.
45 The function "temp" is only exported on request by passing 'temp' to the
49 Currently only applies to scalar variables.
56 Exporter (core since perl 5).
64 Vincent Pit, "<perl at profvince.com>", <http://www.profvince.com>.
66 You can contact me by mail or on "irc.perl.org" (vincent).
69 Please report any bugs or feature requests to "bug-variable-temp at
70 rt.cpan.org", or through the web interface at
71 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Variable-Temp>. I will
72 be notified, and then you'll automatically be notified of progress on
73 your bug as I make changes.
76 You can find documentation for this module with the perldoc command.
78 perldoc Variable::Temp
81 Copyright 2015 Vincent Pit, all rights reserved.
83 This program is free software; you can redistribute it and/or modify it
84 under the same terms as Perl itself.