]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blob - samples/try.pl
Show unwind() and want_at() in the synopsys and the samples
[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 @things
25 my $what = zap(); # @what contains @things
26
27 print "zap() returns @what in list context and $what in scalar context\n";