X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=samples%2Ftry.pl;fp=samples%2Ftry.pl;h=d49c18345b1b308d46241670df4d2c0714a460e5;hb=086bb57f3e5a02fc333105c08b3ce99318f94fe6;hp=0000000000000000000000000000000000000000;hpb=700ce600c7f40f6889a4b11f21fe45eff6040335;p=perl%2Fmodules%2FScope-Upper.git diff --git a/samples/try.pl b/samples/try.pl new file mode 100644 index 0000000..d49c183 --- /dev/null +++ b/samples/try.pl @@ -0,0 +1,27 @@ +#!perl + +use strict; +use warnings; + +use blib; + +use Scope::Upper qw/unwind want_at :words/; + +sub try (&) { + my @result = shift->(); + my $cx = SUB UP SUB; + 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 @what = zap(); # @what contains @things +my $what = zap(); # @what contains @things + +print "zap() returns @what in list context and $what in scalar context\n";