7.2.2 AutoLoader - Load Functions Only on Demandpackage GoodStuff; use Exporter; use AutoLoader; @ISA = qw(Exporter AutoLoader);
The AutoLoader module provides a standard mechanism for
delayed loading of functions stored in separate files on disk.
Each file has the same name as the function (plus a
.al
), and
comes from a directory named after the package (with the
auto/
directory).
For example, the function named
A module using the AutoLoader should have the special marker
When a subroutine not yet in memory is called, the
Lexicals declared with
my
in the
main block of a package using the AutoLoader will not be visible to autoloaded
functions, because the given lexical scope ends at the
The AutoLoader is a counterpart to the SelfLoader module. Both delay the loading
of subroutines, but the SelfLoader accomplishes this by storing the subroutines
right there in the module file rather than in separate files elsewhere. While
this avoids the use of a hierarchy of disk files and the associated I/O for each
routine loaded, the SelfLoader suffers a disadvantage in the one-time parsing of
the lines after AutoLoader, on the other hand, only reads code as it is requested, and in many cases should be faster. But it requires a mechanism like AutoSplit to be used to create the individual files. On systems with restrictions on file name length, the file corresponding to a subroutine may have a shorter name than the routine itself. This can lead to conflicting filenames. The AutoSplit module will warn of these potential conflicts when used to split a module. See the discussion of autoloading in Chapter 5 . Also see the AutoSplit module, a utility that automatically splits a module into a collection of files for autoloading. |
|