10 use Scope::Upper qw/reap localize localize_elem localize_delete/;
12 sub desc { shift->{desc} }
17 # First localize $x so that it gets destroyed last
18 localize '$x' => bless({ desc => $desc }, __PACKAGE__) => 1;
22 my $x = do { no strict 'refs'; ${$pkg.'::x'} }; # Get the $x in the scope
23 print $x->desc . ": done\n";
26 localize_elem '%SIG', '__WARN__' => sub {
28 my $x = do { no strict 'refs'; ${$pkg.'::x'} }; # Get the $x in the scope
29 CORE::warn($x->desc . ': ' . join('', @_));
32 localize_delete '@ARGV', $#ARGV => 1; # delete last @ARGV element
42 # $x is now a X object, and @ARGV has one element less
43 warn 'what'; # warns "pie: what at ..."
44 } # "pie: done" is printed