SYNOPSIS

     use preload;
    
     # Foo::Bar will be require'd when $ENV{PRELOAD} is true
     preload Foo::Bar;
    
     sub mysub {
         # Foo::Bar will be require'd when $ENV{PRELOAD} is false
         load Foo::Bar;
     }

DESCRIPTION

    STATUS: Experimental, interface will likely change.

    When running a script, especially one that has to start quickly, it's
    desirable to delay loading modules until it's actually used, to reduce
    startup overhead.

    When running a (preforking) daemon, it's usually desirable to preload
    modules at startup, so the daemon can then service clients without any
    further delay from loading modules, and the loading before forking
    means child processes can share the module code (reduced memory usage).

    This pragma module tries to offer the best of both worlds. This
    statement:

     use preload;

    will declare a constant PRELOAD (currently set to $ENV{PRELOAD}) and
    introduce two new keywords: preload and load. preload is defined to be:

     if (PRELOAD) { require $module }

    this means it will become a no-op when PRELOAD is false. On the other
    hand, load is defined to be:

     unless (PRELOAD) { require $module }

    this means it will become a no-op when PRELOAD is true.

    With this module you can avoid run-time penalty associated with
    conditional loading.

SEE ALSO

    prefork

    Dist::Zilla::Plugin::Preload

