1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
use strict;
use warnings;
use Test::More tests => 20;
BEGIN { use_ok('B::Hooks::OP::Check::EntersubForCV') }
sub foo { 'affe' }
sub bar { 'birne' }
my ($i, $cv);
BEGIN {
$i = 0;
$cv = \&foo;
}
sub entersub_cb {
my ($code) = @_;
$i++;
is($code->(), 'affe', 'got the right coderef');
}
foo();
my @id;
BEGIN {
is($i, 0, 'no callback yet');
push @id, B::Hooks::OP::Check::EntersubForCV::register($cv, \&entersub_cb);
is($i, 0, 'no callback after registration');
}
foo();
bar();
BEGIN {
is($i, 1, 'simple callback');
$i = 0;
}
my $x = \&foo;
BEGIN {
is($i, 0, '\&foo does not issue a callback');
$i = 0;
}
&foo;
&foo();
BEGIN {
TODO: {
local $TODO = 'TODO';
is($i, 2, '&foo and &foo() issue a callback');
}
$i = 0;
}
foo();
bar();
foo();
BEGIN {
is($i, 2, 'multiple callbacks');
push @id, B::Hooks::OP::Check::EntersubForCV::register($cv, \&entersub_cb);
is($i, 2, 'no callback after multiple registrations');
$i = 0;
}
foo();
bar();
foo();
BEGIN {
is($i, 4, 'multiple callbacks for multiple entersubs');
B::Hooks::OP::Check::EntersubForCV::unregister(pop @id);
$i = 0;
}
foo();
bar();
foo();
BEGIN {
is($i, 2, 'deregistration');
B::Hooks::OP::Check::EntersubForCV::unregister(pop @id);
$i = 0;
}
foo();
bar();
foo();
BEGIN {
is($i, 0, 'no callbacks after removing all registers');
}
|