no warnings 'redefine';
*{_getglob($target)} = $made;
}
+ push @{$DEFERRED{$made} = $DEFERRED{$deferred}}, $made;
return $made;
}
+sub defer_info {
+ my ($deferred) = @_;
+ $DEFERRED{$deferred||''};
+}
+
sub defer_sub {
my ($target, $maker) = @_;
my $undeferred;
1;
-=pod
+=head1 NAME
+
+Sub::Defer - defer generation of subroutines until they are first called
=head1 SYNOPSIS
sub { time - $t };
};
-What the above does is set the Logger::time_since_first_log subroutine to be
-the codref that was passed to it, but then after it gets run once, it becomes
-the returned coderef.
+ Logger->time_since_first_log; # returns 0 and replaces itself
+ Logger->time_since_first_log; # returns time - $t
=head1 DESCRIPTION
-These subroutines provide the user with a convenient way to defer create of
+These subroutines provide the user with a convenient way to defer creation of
subroutines and methods until they are first called.
=head1 SUBROUTINES
my $coderef = defer_sub $name => sub { ... };
-RIBASUSHI FIX ME PLEASE!!!!
+This subroutine returns a coderef that encapsulates the provided sub - when
+it is first called, the provided sub is called and is -itself- expected to
+return a subroutine which will be goto'ed to on subsequent calls.
-Given name to install a subroutine into and a coderef that returns a coderef,
-this function will set up the subroutine such that when it is first called it
-will be replaced with the returned coderef.
+If a name is provided, this also installs the sub as that name - and when
+the subroutine is undeferred will re-install the final version for speed.
=head2 undefer_sub