my ($target, $maker, $undeferred_ref) = @{
$DEFERRED{$deferred}||return $deferred
};
+ return ${$undeferred_ref}
+ if ${$undeferred_ref};
${$undeferred_ref} = my $made = $maker->();
# make sure the method slot has not changed since deferral time
# _install_coderef calls are not necessary --ribasushi
*{_getglob($target)} = $made;
}
- push @{$DEFERRED{$made} = $DEFERRED{$deferred}}, $made;
+ $DEFERRED{$made} = $DEFERRED{$deferred};
return $made;
}
goto &{$undeferred ||= undefer_sub($deferred_string)};
};
$deferred_string = "$deferred";
- $DEFERRED{$deferred} = [ $target, $maker, \$undeferred ];
+ $DEFERRED{$deferred} = [ $target, $maker, \$undeferred, $deferred ];
_install_coderef($target => $deferred) if defined $target;
return $deferred;
}
use strictures 1;
use Test::More;
+use Test::Fatal;
use Sub::Defer;
my %made;
is(my $two_made = undefer_sub($two_defer), $made{'Foo::two'}, 'make two');
+is exception { undefer_sub($two_defer) }, undef,
+ "repeated undefer doesn't regenerate";
+
is($two_made, \&Foo::two, 'two installed');
is($two_defer->(), 'two', 'two (deferred) still runs');