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