Commit | Line | Data |
58b07c77 |
1 | use strict; |
2 | use warnings; |
3 | use Test::More tests => 6; |
4 | |
5 | BEGIN { use_ok('B::Hooks::EndOfScope') } |
6 | |
7 | BEGIN { |
8 | ok(exists &on_scope_end, 'on_scope_end imported'); |
9 | is(prototype('on_scope_end'), '&', '.. and has the right prototype'); |
10 | } |
11 | |
12 | our ($i, $called); |
13 | |
14 | BEGIN { $i = 0 } |
15 | |
16 | sub foo { |
17 | BEGIN { |
18 | on_scope_end { $called = 1; $i = 42 }; |
19 | on_scope_end { $i = 1 }; |
20 | }; |
21 | |
22 | is($i, 1, 'value still set at runtime'); |
23 | } |
24 | |
25 | BEGIN { |
26 | ok($called, 'first callback invoked'); |
27 | is($i, 1, '.. but the second is invoked later') |
28 | } |
29 | |
30 | foo(); |