.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "load 3pm"
.TH load 3pm "2019-12-14" "perl v5.30.0" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
load \- control when subroutines will be loaded
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use load; # default, same as \*(Aqautoload\*(Aq
\&
\& use load \*(Aqautoload\*(Aq; # export AUTOLOAD handler to this namespace
\&
\& use load \*(Aqondemand\*(Aq; # load subroutines after _\|_END_\|_ when requested, default
\&
\& use load \*(Aqnow\*(Aq; # load subroutines after _\|_END_\|_ now
\&
\& use load (); # same as qw(dontscan inherit)
\&
\& use load \*(Aqdontscan\*(Aq; # don\*(Aqt scan module until it is really needed
\&
\& use load \*(Aqinherit\*(Aq; # do NOT export AUTOLOAD handler to this namespace
.Ve
.SH "VERSION"
.IX Header "VERSION"
This documentation describes version 0.24.
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
The \*(L"load\*(R" pragma allows a module developer to give the application developer
more options with regards to optimize for memory or \s-1CPU\s0 usage. The \*(L"load\*(R"
pragma gives more control on the moment when subroutines are loaded and start
taking up memory. This allows the application developer to optimize for \s-1CPU\s0
usage (by loading all of a module at compile time and thus reducing the
amount of \s-1CPU\s0 used during the execution of an application). Or allow the
application developer to optimize for memory usage, by loading subroutines
only when they are actually needed, thereby however increasing the amount of
\&\s-1CPU\s0 needed during execution.
.PP
The \*(L"load\*(R" pragma combines the best of both worlds from AutoLoader and
SelfLoader. And adds some more features.
.PP
In a situation where you want to use as little memory as possible, the \*(L"load\*(R"
pragma (in the context of a module) is a drop-in replacement for AutoLoader.
But for situations where you want to have a module load everything it could
ever possibly need (e.g. when starting a mod_perl server in pre-fork mode), the
\&\*(L"load\*(R" pragma can be used (in the context of an application) to have all
subroutines of a module loaded without having to make any change to the source
of the module in question.
.PP
So the typical use inside a module is to have:
.PP
.Vb 2
\& package Your::Module;
\& use load;
.Ve
.PP
in the source. And to place all subroutines that you want to be loadable on
demand after the (first) _\|_END_\|_.
.PP
If an application developer decides that all subroutines should be loaded
at compile time, (s)he can say in the application:
.PP
.Vb 2
\& use load \*(Aqnow\*(Aq;
\& use Your::Module;
.Ve
.PP
This will cause the subroutines of Your::Module to all be loaded at compile
time.
.SH "MODES OF OPERATION"
.IX Header "MODES OF OPERATION"
There are basically two places where you can call the \*(L"load\*(R" pragma:
.SS "inside a module"
.IX Subsection "inside a module"
When you call the \*(L"load\*(R" pragma inside a module, you're basically enabling that
module for having an external control when certain subroutines will be loaded.
As with AutoLoader, any subroutines that should be loaded on demand, should be
located \fBafter\fR an _\|_END_\|_ line.
.PP
If no parameters are specified with the \f(CW\*(C`use load\*(C'\fR, then the \*(L"autoload\*(R"
parameter is assumed. Whether the module's subroutines are loaded at compile
time or on demand, is determined by the calling application. If the
application doesn't specify anything specific, the \*(L"ondemand\*(R" keyword will
also be assumed.
.SS "inside an application"
.IX Subsection "inside an application"
When you call the \*(L"load\*(R" pragma inside an application, you're basically
specifying when subroutines will be loaded by \*(L"load\*(R" enhanced modules. As an
application developer, you can basically use two keywords: \*(L"ondemand\*(R" and
\&\*(L"now\*(R".
.PP
If an application does not call the \*(L"load\*(R" pragma, the \*(L"ondemand\*(R" keyword will
be assumed. With \*(L"ondemand\*(R", subroutines will only be loaded when they are
actually executed. This saves memory at the expense of extra \s-1CPU\s0 the first
time the subroutine is called.
.PP
The \*(L"now\*(R" keyword indicates that all subroutines of all modules that are
enhanced with the \*(L"load\*(R" pragma, will be loaded at compile time (thus using
more memory, but \fBnot\fR having an extra \s-1CPU\s0 overhead the first time the
subroutine is executed).
.SH "KEYWORDS"
.IX Header "KEYWORDS"
The following keywords are recognized with the \f(CW\*(C`use\*(C'\fR command:
.SS "ondemand"
.IX Subsection "ondemand"
The \*(L"ondemand\*(R" keyword indicates that subroutines, of modules that are enhanced
with the \*(L"load\*(R" pragma, will only be loaded when they are actually called.
.PP
If the \*(L"ondemand\*(R" keyword is used in the context of an application, all
modules that are subsequently \f(CW\*(C`use\*(C'\fRd, will be forced to load subroutines
only when they are actually called (unless the module itself forces a specific
setting).
.PP
If the \*(L"ondemand\*(R" keyword is used in the context of a module, it indicates
that the subroutines of that module, should \fBalways\fR be loaded when they are
actually needed. Since this takes away the choice from the application
developer, the use of the \*(L"ondemand\*(R" keyword in module context is not
encouraged. See also the now and dontscan keywords.
.SS "now"
.IX Subsection "now"
The \*(L"now\*(R" keyword indicates that subroutines, of modules that are enhanced
with the \*(L"load\*(R" pragma, will be loaded at compile time.
.PP
If the \*(L"now\*(R" keyword is used in the context of an application, all modules
that are subsequently \f(CW\*(C`use\*(C'\fRd, will be forced to load all subroutines at
compile time (unless the module forces a specific setting itself).
.PP
If the \*(L"now\*(R" keyword is used in the context of a module, it indicates that the
subroutines of that module, should \fBalways\fR be loaded at compile time. Since
this takes away the choice from the application developer, the use of the
\&\*(L"now\*(R" keyword in module context is not encouraged. See also the ondemand
keyword.
.SS "dontscan"
.IX Subsection "dontscan"
The \*(L"dontscan\*(R" keyword only makes sense when used in the context of a module.
Normally, when a module that is enhanced with the \*(L"load\*(R" pragma is compiled,
the source after the _\|_END_\|_ is scanned for the locations of the subroutines.
This makes the compiling of modules a little slower, but allows for a faster
(initial) lookup of (yet) unloaded subroutines during execution.
.PP
If the \*(L"dontscan\*(R" keyword is specified, this scanning of the source is
skipped at compile time. However, as soon as an attempt is made to ececute
a subroutine from this module, then first the scanning of the source is
performed, before the subroutine in question is loaded.
.PP
So, you should use the \*(L"dontscan\*(R" keyword if you are reasonably sure that you
will only need subroutines from the module in special cases. In all other
cases it will make more sense to have the source scanned at compile time.
.PP
The \*(L"dontscan\*(R" keyword will be ignored if an application developer forces
subroutines to be loaded at compile time with the now keyword.
.SS "autoload"
.IX Subsection "autoload"
The \*(L"autoload\*(R" keyword only makes sense when used in the context of a module.
It indicates that a generic \s-1AUTOLOAD\s0 subroutine will be exported to the
module's namespace. It is selected by default if you use the \*(L"load\*(R" pragma
without parameters in the source of a module. See also the inherit keyword
to \fBnot\fR export the generic \s-1AUTOLOAD\s0 subroutine.
.SS "inherit"
.IX Subsection "inherit"
The \*(L"inherit\*(R" keyword only makes sense when used in the context of a module.
It indicates that \fBno\fR \s-1AUTOLOAD\s0 subroutine will be exported to the module's
namespace. This can e.g. be used when you need to have your own \s-1AUTOLOAD\s0
routine. That \s-1AUTOLOAD\s0 routine should then contain:
.PP
.Vb 2
\& $load::AUTOLOAD = $sub;
\& goto &load::AUTOLOAD;
.Ve
.PP
to access the \*(L"load\*(R" pragma functionality. Another case to use the \*(L"inherit\*(R"
keyword would be in a sub-class of a module which also is \*(L"load\*(R" enhanced.
In that case, the inheritance will cause the \s-1AUTOLOAD\s0 subroutine of the base
class to be used, thereby accessing the \*(L"load\*(R" pragma automagically (and hence
the naming of the keyword of course). See also the autoload keyword to
have the module use the generic \s-1AUTOLOAD\s0 subroutine.
.SS "AutoLoader"
.IX Subsection "AutoLoader"
The \*(L"AutoLoader\*(R" keyword enables AutoLoader emulation mode. It basically
takes over the functionality of the AutoLoader module (which is part of
Perl's core, and which is used by many of Perl's core modules).
.PP
Use of AutoLoader emulation mode usually only makes sense in a mod_perl
prefork environment (in combination with the \*(L"now\*(R" keyword), or a threaded
Perl environment.
.PP
It basically adds the flexibility of subroutine loading options of the \*(L"load\*(R"
pragma to the existing codebase of Perl's core and \s-1CPAN\s0 modules. It is
typically invoked from the command line:
.PP
.Vb 1
\& perl \-Mload=AutoLoader
.Ve
.PP
or in a mod_perl configuration:
.PP
.Vb 4
\&
\& use load qw(AutoLoader now); # as early as possible
\& # rest of modules to be loaded
\&
.Ve
.PP
The AutoLoader emulation mode has the further advantage for modules being
developed with AutoLoader, as it is possible to run the module before having
to have installed the module (which is normally a requirement with using
AutoLoader).
.PP
Please note that AutoLoader emulation will only work properly for any modules
loaded \fBafter\fR the \*(L"load\*(R" module is loaded. It is therefore important to
activate the AutoLoader as soon as possible, before \fBany\fR other modules have
been loaded. Of particular interest in this respect are the threads and
the ifdef modules.
.SH "REQUIRED MODULES"
.IX Header "REQUIRED MODULES"
.Vb 1
\& (none)
.Ve
.SH "DIFFERENCES WITH SIMILAR MODULES"
.IX Header "DIFFERENCES WITH SIMILAR MODULES"
There are a number of (core) modules that more or less do the same thing as
the \*(L"load\*(R" pragma.
.SS "AutoSplit / AutoLoader"
.IX Subsection "AutoSplit / AutoLoader"
The \*(L"load\*(R" pragma is very similar to the AutoSplit / AutoLoader combination.
The main difference is that the splitting takes place when the \*(L"load\*(R" import
is called in a module and that there are no external files created. Instead,
just the offsets and lengths are recorded in a hash (when \*(L"ondemand\*(R" is active)
or all the source after _\|_END_\|_ is eval'led (when \*(L"now\*(R" is active).
.PP
From a module developer point of view, the advantage is that you do not need to
install a module before you can test it. From an application developer point
of view, you have the flexibility of having everything loaded now or later (on
demand).
.PP
From a memory usage point of view, the \*(L"load\*(R" offset/length hash takes up more
memory than the equivalent AutoLoader setup. On the other hand, accessing the
source of a subroutine may generally be faster because the file is more likely
to reside in the operating system's buffers already.
.PP
As an extra feature, the \*(L"load\*(R" pragma allows an application to force all
subroutines to be loaded at compile time, which is not possible with AutoLoader.
.PP
The \*(L"AutoLoader emulation\*(R" mode causes AutoLoader to be replaced by \*(L"load\*(R",
increasing further flexibility in loading options (which can be particularly
important in the \*(L"mod_perl prefork\*(R" situation) and ease of use during
development of modules using AutoLoader (as you don't need to install the
module before you can test it).
.SS "SelfLoader"
.IX Subsection "SelfLoader"
The \*(L"load\*(R" pragma also has some functionality in common with the SelfLoader
module. But it gives more granularity: with SelfLoader, all subroutines that
are not loaded directly, will be loaded if \fBany\fR not yet loaded subroutine is
requested. It also adds complexities if your module needs to use the <\s-1DATA\s0>
handle. So the \*(L"load\*(R" pragma gives more flexibility and fewer development
complexities. And of course, an application can force all subroutines to be
loaded at compile time when needed with the \*(L"load\*(R" pragma.
.SH "UNIVERSAL::can"
.IX Header "UNIVERSAL::can"
To ensure the functioning of the \->can class method and &UNIVERSAL::can,
the \*(L"load\*(R" pragma hijacks the standard UNIVERSAL::can routine so that it
can check whether the subroutine/method that you want to check for, actually
exists and have a code reference to it returned. This has a side effect that
you the subroutine checked for, is loaded. You can use this side effect to
load subroutines without calling them.
.PP
.Vb 1
\& Your::Module\->can( \*(Aqloadthisnow\*(Aq );
.Ve
.PP
will load the subroutine \*(L"loadthisnow\*(R" of the Your::Module module without
actually calling it.
.SH "CAVEATS"
.IX Header "CAVEATS"
Currently you may not have multiple packages in the same file, nor can you
have fully qualified subroutine names.
.PP
The parser that looks for package names and subroutines, is not very smart.
This is intentionally so, as making it smarter will make it a lot slower, but
probably still not smart enough. Therefore, the \f(CW\*(C`package\*(C'\fR and \f(CW\*(C`sub\*(C'\fR's
\&\fBmust\fR be at the start of a line. And the name of the \f(CW\*(C`sub\*(C'\fR \fBmust\fR be on
the same line as the \f(CW\*(C`sub\*(C'\fR.
.SH "EXAMPLES"
.IX Header "EXAMPLES"
Some code examples. Please note that these are just a part of an actual
situation.
.SS "base class"
.IX Subsection "base class"
.Vb 2
\& package Your::Module;
\& use load;
.Ve
.PP
Exports the generic \s-1AUTOLOAD\s0 subroutine and adheres to whatever the application
developer specifies as mode of operation.
.SS "sub class"
.IX Subsection "sub class"
.Vb 3
\& package Your::Module::Adapted;
\& @ISA = qw(Your::Module);
\& use load ();
.Ve
.PP
Does \fBnot\fR export the generic \s-1AUTOLOAD\s0 subroutine, but inherits it from its
base class. Also implicitely specifies the \*(L"dontscan\*(R" keyword, causing the
source of the module to be scanned only when the first not yet loaded
subroutine is about to be executed. If you only want to have the \*(L"inherit\*(R"
keyword functionality, then you must specify that explicitly:
.PP
.Vb 3
\& package Your::Module::Adapted;
\& @ISA = qw(Your::Module);
\& use load \*(Aqinherit\*(Aq;
.Ve
.SS "custom \s-1AUTOLOAD\s0"
.IX Subsection "custom AUTOLOAD"
.Vb 2
\& package Your::Module;
\& use load \*(Aqinherit\*(Aq;
\&
\& sub AUTOLOAD {
\& if (some condition) {
\& $load::AUTOLOAD = $Your::Module::AUTOLOAD;
\& goto &load::AUTOLOAD;
\& }
\& # do your own stuff
\& }
.Ve
.PP
If you want to use your own \s-1AUTOLOAD\s0 subroutine, but still want to use the
functionality offered by the \*(L"load\*(R" pragma, you can use the above construct.
.SS "mod_perl prefork"
.IX Subsection "mod_perl prefork"
.Vb 2
\& use load qw(AutoLoader now);
\& use Your::Module;
.Ve
.PP
In pre-fork mod_perl applications (the default mod_perl applications before
mod_perl 2.0), it is advantageous to load all possible subroutines when the
Apache process is started. This is because the operating system will share
memory using a process called \*(L"Copy On Write\*(R". So even though it will take
more memory initially, that memory loss is easily evened out by the gains of
having everything shared. Loading a not yet loaded subroutine in that
situation, will cause otherwise shared memory to become unshared. Thereby
increasing the overall memory usage, because the amount that becomes unshared
is typically a lot more than the extra memory used by the subroutine (which
is caused by fragmentation of allocated memory).
.PP
The \fBAutoLoader\fR emulation mode causes all modules that use \f(CW\*(C`AutoLoader\*(C'\fR to
be handled by \f(CW\*(C`load\*(C'\fR. In combination with the \*(L"now\*(R" mode, this means that
many system modules will also be loaded completely at server startup (causing
a grow in initial use of memory, but sharing more memory means that overall
memory usage is significantly reduced.
.SS "threaded applications and mod_perl worker"
.IX Subsection "threaded applications and mod_perl worker"
.Vb 1
\& use Your::Module;
.Ve
.PP
Threaded Perl applications, of which mod_perl applications using the \*(L"worker\*(R"
module are a special case, function best when subroutines are only loaded when
they are actually needed. This is caused by the nature of the threading model
of Perl, in which all data-structures are \fBcopied\fR to each thread (essentially
forcing them to become unshared as far as the operating system is concerned).
.PP
Benchmarks have shown that the overhead of the extra \s-1CPU\s0 is easily offset by
the reduction of the amount of data that needs to be copied (and processed)
when a thread is created.
.PP
A little additional memory reduction can be achieved with the AutoLoader
emulation mode: this will prevent the AutoLoader module to be loaded (but
have its functionality handled by the \*(L"load\*(R" pragma).
.SH "SOURCE FILTERS"
.IX Header "SOURCE FILTERS"
If your module wants to use \*(L"load\*(R" to load subroutines on demand \fBand\fR that
module needs a source filter (which is usually activated with a \*(L"use\*(R"
statement), then those modules need to be used when the source of the
subroutine is compiled. The class method \*(L"register\*(R" is intended to be
used from such a module, typicallly like this:
.PP
.Vb 6
\& sub import {
\& my $package = caller();
\& load\->register( $package,_\|_PACKAGE_\|_ ) # register caller\*(Aqs package
\& if defined( $load::VERSION ) # if load.pm loaded
\& and $load::VERSION > 0.11; # and recent enough
\& }
.Ve
.PP
The first parameter is the name of the package \fBin\fR which subroutines need
extra modules \*(L"use\*(R"d. The second parameter is the name of the module that
needs to be \*(L"use\*(R"d.
.SH "TODO"
.IX Header "TODO"
The coordinates of a subroutine in a module (start,number of bytes) are stored
in a hash in the load namespace. Ideally, this information should be stored in
the stash of the module to which they apply. Then the internals that check
for the existence of a subroutine, would see that the subroutine doesn't exist
(yet), but that there is an offset and length (and implicitely, a file from
\&\f(CW%INC\fR) from which the source could be read and evalled.
.PP
Loading all of the subroutines should maybe be handled inside the Perl parser,
having it skip _\|_END_\|_ when the global \*(L"now\*(R" flag is set.
.PP
Possibly we should use the <\s-1DATA\s0> handle from a module if there is one, or dup
it and use that, rather than opening the file again.
.PP
Add SelfLoader emulation mode.
.SH "MODULE RATING"
.IX Header "MODULE RATING"
If you want to find out how this module is appreciated by other people, please
check out this module's rating at (if
there are any ratings for this module). If you like this module, or otherwise
would like to have your opinion known, you can add your rating of this module
at .
.SH "ACKNOWLEDGEMENTS"
.IX Header "ACKNOWLEDGEMENTS"
Frank Tolstrup for helping ironing out all of the Windows related issues.
.SH "AUTHOR"
.IX Header "AUTHOR"
Elizabeth Mattijsen, .
.PP
Please report bugs to .
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2010, 2012 Elizabeth
Mattijsen . All rights reserved. This program is free
software; you can redistribute it and/or modify it under the same terms
as Perl itself.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
AutoLoader, SelfLoader, ifdef, threads.