Sub::Defer - Defer generation of subroutines until they are first called




 use Sub::Defer;
    my $t = time;
    sub { time - $t };
  Logger->time_since_first_log; # returns 0 and replaces itself
  Logger->time_since_first_log; # returns time - $t








Exported by default.


 my $coderef = undefer_sub \&Foo::name;

If the passed coderef has been deferred 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 "SYNOPSIS".

Exported by default.



This will undefer all deferred subs in one go. This can be very useful in a forking environment where child processes would each have to undefer the same subs. By calling this just before you start forking children you can undefer all currently deferred subs in the parent so that the children do not have to do it. Note this may bake the behavior of some subs that were intended to calculate their behavior later, so it shouldn't be used midway through a module load or class definition.

Exported by default.



This undefers all deferred subs in a package.

Not exported by default.


See Sub::Quote for support and contact information.


See Sub::Quote for authors.


See Sub::Quote for the copyright and license.