8 my $one_defer = defer_sub 'Foo::one' => sub {
9 die "remade - wtf" if $made{'Foo::one'};
10 $made{'Foo::one'} = sub { 'one' }
13 my $two_defer = defer_sub 'Foo::two' => sub {
14 die "remade - wtf" if $made{'Foo::two'};
15 $made{'Foo::two'} = sub { 'two' }
18 is($one_defer, \&Foo::one, 'one defer installed');
19 is($two_defer, \&Foo::two, 'two defer installed');
21 is($one_defer->(), 'one', 'one defer runs');
23 is($made{'Foo::one'}, \&Foo::one, 'one made');
25 is($made{'Foo::two'}, undef, 'two not made');
27 is($one_defer->(), 'one', 'one (deferred) still runs');
29 is(Foo->one, 'one', 'one (undeferred) runs');
31 is(my $two_made = undefer_sub($two_defer), $made{'Foo::two'}, 'make two');
33 is exception { undefer_sub($two_defer) }, undef,
34 "repeated undefer doesn't regenerate";
36 is($two_made, \&Foo::two, 'two installed');
38 is($two_defer->(), 'two', 'two (deferred) still runs');
40 is($two_made->(), 'two', 'two (undeferred) runs');
42 my $three = sub { 'three' };
44 is(undefer_sub($three), $three, 'undefer non-deferred is a no-op');
46 my $four_defer = defer_sub 'Foo::four' => sub {
49 is($four_defer, \&Foo::four, 'four defer installed');
51 # somebody somewhere wraps up around the deferred installer
52 no warnings qw/redefine/;
53 my $orig = Foo->can('four');
55 $orig->() . ' with a twist';
58 is(Foo->four, 'four with a twist', 'around works');
59 is(Foo->four, 'four with a twist', 'around has not been destroyed by first invocation');