/usr/share/doc/libscope-upper-perl/examples/try.pl is in libscope-upper-perl 0.30-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #!/usr/bin/perl
use strict;
use warnings;
use blib;
use Scope::Upper qw<unwind want_at :words>;
sub try (&) {
my @result = shift->();
my $cx = SUB UP; # Point to the sub above this one
unwind +(want_at($cx) ? @result : scalar @result) => $cx;
}
sub zap {
try {
my @things = qw<a b c>;
return @things; # returns to try() and then outside zap()
};
print "NOT REACHED\n";
}
my @stuff = zap(); # @stuff contains qw<a b c>
my $stuff = zap(); # $stuff contains 3
print "zap() returns @stuff in list context and $stuff in scalar context\n";
{
package Uplevel;
use Scope::Upper qw<uplevel CALLER>;
sub target {
faker(@_);
}
sub faker {
uplevel {
my $sub = (caller 0)[3];
print "$_[0] from $sub()\n";
} @_ => CALLER(1);
}
target('hello'); # "hello from Uplevel::target()"
}
|