1 package Variable::Temp;
10 Variable::Temp - Temporarily change the value of a variable.
25 use Variable::Temp 'temp';
37 This module provides an utility routine that can be used to temporarily change the value of a variable, until the end of the current scope is reached where the original value of the variable is restored.
38 It is similar to C<local>, except that it can be applied onto lexicals as well as globals, and that it replaces values by copying the new value into the container variable instead of by aliasing.
51 Temporarily replace the value of the lexical or global variable C<$var> by C<$value>, or by C<undef> if C<$value> is omitted, until the end of the current scope.
52 Any subsequent assignments to C<$var> in the current (or any inferior) scope will not affect the original value which will be restored into the variable at scope end.
53 Several C<temp> calls can be made onto the same variable, and the restore are processed in reverse order.
55 Note that destructors associated with C<$var> will B<not> be called when C<temp> sets the temporary value, but only at the natural end of life of the variable (i.e. at the end of the scope).
56 They will trigger after any destructor associated with the replacement C<$var>.
60 sub temp (\$) :lvalue {
63 &Scope::Upper::reap(sub { $$var = $save } => Scope::Upper::UP);
69 The function L</temp> is only exported on request by passing C<'temp'> to the module import list.
76 our %EXPORT_TAGS = ();
77 our @EXPORT_OK = 'temp';
81 Currently only applies to scalar variables.
89 L<Exporter> (core since perl 5).
99 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
101 You can contact me by mail or on C<irc.perl.org> (vincent).
105 Please report any bugs or feature requests to C<bug-variable-temp at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Variable-Temp>.
106 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
110 You can find documentation for this module with the perldoc command.
112 perldoc Variable::Temp
114 =head1 COPYRIGHT & LICENSE
116 Copyright 2015 Vincent Pit, all rights reserved.
118 This program is free software; you can redistribute it and/or modify it
119 under the same terms as Perl itself.
123 1; # End of Variable::Temp