autouse
use autouse "Carp" => qw(carp croak); carp "this carp was predeclared and autoused";
This pragma provides a mechanism for runtime demand loading of a
particular module only when a function from that module really gets
called. It does this by providing a stub function that replaces itself
with the real call once triggered. This is similar in spirit to the way
the standard AutoLoader and SelfLoader modules behave. In short, it’s a performance hack to help
make your Perl program start up faster (on average) by avoiding
compilation of modules that might never ever be called during a given
execution run.
How autouse behaves depends on
whether the module is already loaded. For example, if the module Module is already loaded, then the
declaration:
use autouse "Module" => qw(func1 func2($;$) Module::func3);
is equivalent to the simple import of two functions:
use Module qw(func1 func2);
This assumes that Module defines
func2 with prototype ($;$), and that func1 and func3 have no prototypes. (More generally, this
also assumes that Module uses Exporter’s standard import
method; otherwise, a fatal error is raised.) In any event, it completely
ignores Module::func3 since that is
presumably already declared.
If, on the other hand, Module has
not yet been loaded when the autouse
pragma is parsed, the pragma declares functions func1 and func2 to be in the current package. It also
declares a function Module::func3 (which could be construed as mildly antisocial, were it not for the fact that the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access