7 our @EXPORT = qw(defer_sub undefer_sub);
13 my ($target, $maker, $undeferred_ref) = @{
14 $DEFERRED{$deferred}||return $deferred
16 ${$undeferred_ref} = my $made = $maker->();
17 if (defined($target)) {
18 no warnings 'redefine';
19 *{_getglob($target)} = $made;
25 my ($target, $maker) = @_;
29 goto &{$undeferred ||= undefer_sub($deferred_string)};
31 $deferred_string = "$deferred";
32 $DEFERRED{$deferred} = [ $target, $maker, \$undeferred ];
33 *{_getglob $target} = $deferred if defined($target);
45 my $deferred = defer_sub 'Logger::time_since_first_log' => sub {
50 What the above does is set the Logger::time_since_first_log subroutine to be
51 the codref that was passed to it, but then after it gets run once, it becomes
56 These subroutines provide the user with a convenient way to defer create of
57 subroutines and methods until they are first called.
63 my $coderef = defer_sub $name => sub { ... };
65 RIBASUSHI FIX ME PLEASE!!!!
67 Given name to install a subroutine into and a coderef that returns a coderef,
68 this function will set up the subroutine such that when it is first called it
69 will be replaced with the returned coderef.
73 my $coderef = undefer_sub \&Foo::name;
75 If the passed coderef has been L<deferred|/defer_sub> this will "undefer" it.
76 If the passed coderef has not been deferred, this will just return it.
78 If this is confusing, take a look at the example in the L</SYNOPSIS>.