From: Arthur Axel 'fREW' Schmidt Date: Sun, 7 Nov 2010 04:27:21 +0000 (-0500) Subject: Documentation for Sub::Defer X-Git-Tag: 0.009001~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8213644a92fd8b62cb7a34577ce61d73ae85a0b3;p=gitmo%2FMoo.git Documentation for Sub::Defer --- diff --git a/lib/Sub/Defer.pm b/lib/Sub/Defer.pm index 816190e..c3e4089 100644 --- a/lib/Sub/Defer.pm +++ b/lib/Sub/Defer.pm @@ -35,3 +35,44 @@ sub defer_sub { } 1; + +=pod + +=head1 SYNOPSIS + + use Sub::Defer; + + my $deferred = defer_sub 'Logger::time_since_first_log' => sub { + my $t = time; + 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. + +=head1 DESCRIPTION + +These subroutines provide the user with a convenient way to defer create of +subroutines and methods until they are first called. + +=head1 SUBROUTINES + +=head2 defer_sub + + my $coderef = defer_sub $name => sub { ... }; + +RIBASUSHI FIX ME PLEASE!!!! + +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. + +=head2 undefer_sub + + my $coderef = undefer_sub \&Foo::name; + +If the passed coderef has been L this will "undefer" it. +If the passed coderef has not been deferred, this will just return it. + +If this is confusing, take a look at the example in the L.