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).
They will trigger after any destructor associated with the replacement C<$value>.
+Due to a shortcoming in the handling of the C<\$> prototype, which was addressed in C<perl> 5.14, the pseudo-statement C<temp $var = $value> will cause compilation errors on C<perl> 5.12.x and below.
+If you want your code to run on these versions of C<perl>, you are encouraged to use L</set_temp> instead.
+
=cut
sub temp (\$) :lvalue {
$$var;
}
+=head2 C<set_temp>
+
+ set_temp $var;
+ set_temp $var => $value;
+
+A non-lvalue variant of L</temp> that can be used with any version of C<perl>.
+
+=cut
+
+sub set_temp (\$;$) {
+ my $var = $_[0];
+ my $save = $$var;
+ &Scope::Upper::reap(sub { $$var = $save } => Scope::Upper::UP);
+ $$var = $_[1] if @_ >= 2;
+ return;
+}
+
=head1 EXPORT
-The function L</temp> is only exported on request by passing C<'temp'> to the module import list.
+The functions L</temp> and L</set_temp> are only exported on request by specifying their names in the module import list.
=cut
our @EXPORT = ();
our %EXPORT_TAGS = ();
-our @EXPORT_OK = 'temp';
+our @EXPORT_OK = qw<temp set_temp>;
=head1 CAVEATS