X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fsub-defer.t;h=ba7f042b879f2aa0fd1ee5297855990a07ccf21f;hb=2f425b5770149d4ed2e59da001c3be052cbd6bc1;hp=767556014cf45d4816af8ab6dae207f883cdca36;hpb=eae82931c70bed45915ee6785db2a11cb4b16f0e;p=gitmo%2FMoo.git diff --git a/t/sub-defer.t b/t/sub-defer.t index 7675560..ba7f042 100644 --- a/t/sub-defer.t +++ b/t/sub-defer.t @@ -4,12 +4,12 @@ use Sub::Defer; my %made; -my $one_defer = defer 'Foo::one' => sub { +my $one_defer = defer_sub 'Foo::one' => sub { die "remade - wtf" if $made{'Foo::one'}; $made{'Foo::one'} = sub { 'one' } }; -my $two_defer = defer 'Foo::two' => sub { +my $two_defer = defer_sub 'Foo::two' => sub { die "remade - wtf" if $made{'Foo::two'}; $made{'Foo::two'} = sub { 'two' } }; @@ -27,7 +27,7 @@ is($one_defer->(), 'one', 'one (deferred) still runs'); is(Foo->one, 'one', 'one (undeferred) runs'); -is(my $two_made = undefer($two_defer), $made{'Foo::two'}, 'make two'); +is(my $two_made = undefer_sub($two_defer), $made{'Foo::two'}, 'make two'); is($two_made, \&Foo::two, 'two installed'); @@ -37,6 +37,21 @@ is($two_made->(), 'two', 'two (undeferred) runs'); my $three = sub { 'three' }; -is(undefer($three), $three, 'undefer non-deferred is a no-op'); +is(undefer_sub($three), $three, 'undefer non-deferred is a no-op'); + +my $four_defer = defer_sub 'Foo::four' => sub { + sub { 'four' } +}; +is($four_defer, \&Foo::four, 'four defer installed'); + +# somebody somewhere wraps up around the deferred installer +no warnings qw/redefine/; +my $orig = Foo->can('four'); +*Foo::four = sub { + $orig->() . ' with a twist'; +}; + +is(Foo->four, 'four with a twist', 'around works'); +is(Foo->four, 'four with a twist', 'around has not been destroyed by first invocation'); done_testing;