da07fcd7835152d627b87becaf12211d82043c7c
[p5sagit/B-Hooks-EndOfScope-WithFallback.git] / t / 00-basic.t
1 use strict;
2 use warnings;
3 use Test::More;
4
5 BEGIN { use_ok('B::Hooks::EndOfScope::WithFallback') }
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();
31
32 done_testing;