6 use Test::More tests => 13 + 3;
8 use Scope::Upper qw<unwind SCOPE CALLER>;
20 1, unwind('from', 'the', 'sub', 'c' => SCOPE $l1);
30 my @c = (1 .. 12, c());
31 is $x, 3, '$x in b after c()';
38 is $x, 1, '$x in a after b()';
44 is_deeply [ a() ], [ 1 .. 12, 'in c', 'in b', 'in a' ],
49 is_deeply [ a() ], [ 1 .. 12, qw<eval from the sub c>, 'in b', 'in a' ],
54 is_deeply [ a() ], [ qw<eval from the sub c>, 'in a' ],
59 is_deeply [ a() ], [ 1 .. 12, qw<from the sub c>, 'in b', 'in a' ],
64 is_deeply [ a() ], [ qw<from the sub c>, 'in a' ],
67 # Unwinding while unwinding
69 package Scope::Upper::TestGuard;
73 bless { cb => $_[0] }, $class;
82 my $desc = 'unwinding while unwinding';
88 my $guard = Scope::Upper::TestGuard->new(sub {
91 unwind @_ => CALLER(1);
93 fail "$desc (second): not reached";
95 is_deeply \@res, [ qw<a b c> ], "$desc (second): correct returned values";
97 unwind @_ => CALLER(1);
99 fail "$desc (first): not reached";
101 is_deeply \@res, [ qw<y z> ], "$desc (first): correct returned values";
103 is $@, '', "$desc: did not croak";