+Note that destructors associated with the variable will B<not> be called when C<temp> sets the temporary value, but only at the natural end of life of the variable.
+They will trigger after any destructor associated with the replacement 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
+
+my $wiz;
+$wiz = Variable::Magic::wizard(
+ data => sub { $_[1] },
+ set => sub {
+ my ($token, $var) = @_;
+ &Variable::Magic::dispell($token, $wiz);
+ if (ref $var eq 'ARRAY') {
+ @$var = @$$token;
+ } else {
+ %$var = %$$token;
+ }
+ return;
+ },
+ free => sub {
+ my ($token, $var) = @_;
+ # We need Variable::Magic 0.51 so that dispell in free does not crash.
+ &Variable::Magic::dispell($token, $wiz);
+ if (ref $var eq 'ARRAY') {
+ @$var = ();
+ } else {
+ %$var = ();
+ }
+ },
+);
+
+sub temp (\[$@%]) :lvalue {
+ my $var = $_[0];
+ my $target = Scope::Upper::UP;
+ my $ret;
+ my $type = ref $var;
+ if ($type eq 'ARRAY') {
+ my @save = @$var;
+ &Scope::Upper::reap(sub { @$var = @save } => $target);
+ my $token;
+ Variable::Magic::cast($token, $wiz, $var);
+ $ret = \$token;
+ } elsif ($type eq 'HASH') {
+ my %save = %$var;
+ &Scope::Upper::reap(sub { %$var = %save } => $target);
+ my $token;
+ Variable::Magic::cast($token, $wiz, $var);
+ $ret = \$token;
+ } else { # $type eq 'SCALAR' || $type eq 'REF'
+ my $save = $$var;
+ &Scope::Upper::reap(sub { $$var = $save } => $target);
+ $$var = undef;
+ $ret = $var;
+ }
+ $$ret;
+}
+
+=head2 C<set_temp>
+
+ set_temp $var;
+ set_temp $var => $value;
+
+ set_temp @var;
+ set_temp @var => \@value;
+
+ set_temp %var;
+ set_temp %var => \%value;
+
+A non-lvalue variant of L</temp> that can be used with any version of C<perl>.