Sophie

Sophie

distrib > Fedora > 13 > x86_64 > by-pkgid > 91856d34881f72dd72343cf9a5462396 > files > 5

perl-B-Hooks-EndOfScope-0.08-3.fc13.noarch.rpm

use strict;
use warnings;
use Test::More tests => 6;

BEGIN { use_ok('B::Hooks::EndOfScope') }

BEGIN {
    ok(exists &on_scope_end, 'on_scope_end imported');
    is(prototype('on_scope_end'), '&', '.. and has the right prototype');
}

our ($i, $called);

BEGIN { $i = 0 }

sub foo {
    BEGIN {
        on_scope_end { $called = 1; $i = 42 };
        on_scope_end { $i = 1 };
    };

    is($i, 1, 'value still set at runtime');
}

BEGIN {
    ok($called, 'first callback invoked');
    is($i, 1, '.. but the second is invoked later')
}

foo();