]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blob - samples/try.pl
305a0ec3bef65ec86220ecd60386bd0adf11d595
[perl/modules/Scope-Upper.git] / samples / try.pl
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use blib;
7
8 use Scope::Upper qw/unwind want_at :words/;
9
10 sub try (&) {
11  my @result = shift->();
12  my $cx = SUB UP SUB;
13  unwind +(want_at($cx) ? @result : scalar @result) => $cx;
14 }
15
16 sub zap {
17  try {
18   my @things = qw/a b c/;
19   return @things; # returns to try() and then outside zap()
20  };
21  print "NOT REACHED\n";
22 }
23
24 my @what = zap(); # @what contains qw/a b c/
25 my $what = zap(); # $what contains 3
26
27 print "zap() returns @what in list context and $what in scalar context\n";