GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  SUB::DEFER (3)

.ds Aq ’

NAME

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

CONTENTS

SYNOPSIS



 use Sub::Defer;

 my $deferred = defer_sub Logger::time_since_first_log => sub {
    my $t = time;
    sub { time - $t };
 };

  Logger->time_since_first_log; # returns 0 and replaces itself
  Logger->time_since_first_log; # returns time - $t



DESCRIPTION

These subroutines provide the user with a convenient way to defer creation of subroutines and methods until they are first called.

SUBROUTINES

    defer_sub



 my $coderef = defer_sub $name => sub { ... };



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.

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.

Exported by default.

    undefer_sub



 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.

    undefer_all



 undefer_all();



This will undefer all defered 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.

    undefer_package



  undefer_package($package);



This undefers all defered subs in a package.

Not exported by default.

SUPPORT

See Moo for support and contact information.

AUTHORS

See Moo for authors.

COPYRIGHT AND LICENSE

See Moo for the copyright and license.
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 SUB::DEFER (3) 2016-03-04

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.