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
|
use strict;
use warnings FATAL => 'all';
use Test::More tests => 12;
use Function::Parameters {
fun_cx => { defaults => 'function', install_sub => 'jamitin' },
fun_rx => { defaults => 'function', install_sub => 'jamitin', runtime => 1 },
};
use Hash::Util qw(fieldhash);
my %watcher;
BEGIN { fieldhash %watcher; }
my $calls;
BEGIN { $calls = 0; }
sub jamitin {
my ($name, $body) = @_;
$watcher{$body} = $name;
$calls++;
}
my $forceclosure;
BEGIN {
is $calls, 0;
is_deeply \%watcher, {};
}
BEGIN {
jamitin 'via_sub_cx', sub { $forceclosure };
}
BEGIN {
is $calls, 1;
is_deeply \%watcher, {};
}
fun_cx via_fun_cx(@) { $forceclosure }
BEGIN {
is $calls, 2;
is_deeply \%watcher, {};
}
BEGIN {
$calls = 0;
}
is $calls, 0;
is_deeply \%watcher, {};
jamitin 'via_sub_rx', sub { $forceclosure };
is $calls, 1;
is_deeply \%watcher, {};
fun_rx via_fun_rx(@) { $forceclosure }
is $calls, 2;
TODO: {
local $TODO = 'bug/leak: runtime-installed subs are kept alive somehow';
is_deeply \%watcher, {};
}
|