NAME
preload - Load and preload modules
VERSION
This document describes version 0.020 of preload (from Perl distribution preload), released on 2019-03-19.
SYNOPSIS
use preload;
# Foo::Bar will be require'd when $ENV{PERL_PRELOAD_MODULES} is true
preload Foo::Bar;
sub mysub {
# Foo::Bar will be require'd when $ENV{PERL_PRELOAD_MODULES} 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{PERL_PRELOAD_MODULES}
) 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.
ENVIRONMENT
PERL_PRELOAD_MODULES
Boolean.
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/preload.
SOURCE
Source repository is at https://github.com/perlancar/perl-preload.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=preload
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
SEE ALSO
AUTHOR
perlancar <perlancar@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2019, 2015 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.