10 use Scope::Upper qw/reap localize localize_elem localize_delete :words/;
12 die 'run this script with some arguments!' unless @ARGV;
14 sub desc { shift->{desc} }
19 # First localize $x so that it gets destroyed last
20 localize '$x' => bless({ desc => $desc }, __PACKAGE__) => UP;
24 my $x = do { no strict 'refs'; ${$pkg.'::x'} }; # Get the $x in the scope
25 print $x->desc . ": done\n";
26 } => SCOPE 1; # same as UP here
28 localize_elem '%SIG', '__WARN__' => sub {
30 my $x = do { no strict 'refs'; ${$pkg.'::x'} }; # Get the $x in the scope
31 CORE::warn($x->desc . ': ' . join('', @_));
32 } => UP CALLER 0; # same as UP here
34 # delete last @ARGV element
35 localize_delete '@ARGV', -1 => UP SUB HERE; # same as UP here
45 # $x is now a X object, and @ARGV has one element less
46 warn 'what'; # warns "pie: what at ..."
47 warn "\@ARGV contains [@ARGV]";
48 } # "pie: done" is printed