6 use Test::More tests => 8 + 18 + 4 + 8 + 11 + 5 + 17;
8 use Scope::Upper qw<reap UP HERE>;
12 sub add { local $_; my $y = $_[0]; reap sub { $x += $y } => $_[1] }
19 is($x, 0, '1 didn\'t run');
22 is($x, 0, '1 and 2 didn\'t run');
24 is($x, 2, '1 didn\'t run, 2 ran');
27 is($x, 2, '1 and 3 didn\'t run, 2 ran');
29 is($x, 6, '1 didn\'t run, 2 and 3 ran');
31 is($x, 7, '1, 2 and 3 ran');
39 is($_, 3, '$_ has the right value');
42 is($_, 3, '$_ has the right value');
44 is($x, 0, '1 didn\'t run');
45 is($_, 5, '$_ has the right value');
48 is($_, 5, '$_ has the right value');
50 is($_, 7, '$_ has the right value');
51 is($x, 0, '1 and 2 didn\'t run');
53 is($x, 2, '1 didn\'t run, 2 ran');
54 is($_, 5, '$_ has the right value');
57 is($_, 9, '$_ has the right value');
60 is($_, 11, '$_ has the right value');
61 is($x, 2, '1 and 3 didn\'t run, 2 ran');
63 is($x, 6, '1 didn\'t run, 2 and 3 ran');
64 is($_, 5, '$_ has the right value');
66 is($x, 7, '1, 2 and 3 ran');
67 is($_, 3, '$_ has the right value');
77 is($x, 0, '1 and 2 didn\'t run');
79 is($x, 3, '1 and 2 ran');
90 is($_, 5, '$_ has the right value');
93 is($_, 7, '$_ has the right value');
94 is($x, 0, '1 and 2 didn\'t run');
96 is($_, 9, '$_ has the right value');
98 is($x, 3, '1 and 2 ran');
99 is($_, 3, '$_ has the right value');
109 is($x, 0, '1 didn\'t run');
111 is($x, 0, '1 didn\'t run');
118 is($x, 1, '2 didn\'t run');
120 is($x, 1, '2 didn\'t run');
123 is($x, 1, '2 and 3 didn\'t run');
125 is($x, 1, '2 and 3 didn\'t run');
127 is($x, 5, '2 didn\'t run, 3 ran');
129 is($x, 7, '2 and 3 ran');
133 sub bleh { add 2 => UP; }
140 is($x, 0, '1 didn\'t run');
142 is($x, 0, '1 didn\'t run');
149 is($_, 7, '$_ has the right value');
152 is($_, 9, '$_ has the right value');
154 is($_, 9, '$_ has the right value');
160 is($_, 7, '$_ has the right value');
161 is($x, 0, '1, 2 didn\'t run');
163 is($x, 0, '1, 2, 3, 4 didn\'t run');
164 is($_, 7, '$_ has the right value');
166 is($_, 7, '$_ has the right value');
174 is($_, 3, '$_ has the right value');
177 is($_, 5, '$_ has the right value');
178 is($x, 0, '1 didn\'t run');
181 is($x, 2, '1, 3, 4 and 5 didn\'t run, 2 ran');
182 is($_, 5, '$_ has the right value');
184 is($x, 22, '1 and 4 didn\'t run, 2, 3 and 5 ran');
186 is($x, 30, '1 didn\'t run, 2, 3, 4 and 5 ran');