1autouse(3pm)           Perl Programmers Reference Guide           autouse(3pm)
2
3
4

NAME

6       autouse - postpone load of modules until a function is used
7

SYNOPSIS

9         use autouse 'Carp' => qw(carp croak);
10         carp "this carp was predeclared and autoused ";
11

DESCRIPTION

13       If the module "Module" is already loaded, then the declaration
14
15         use autouse 'Module' => qw(func1 func2($;$));
16
17       is equivalent to
18
19         use Module qw(func1 func2);
20
21       if "Module" defines func2() with prototype "($;$)", and func1() has no
22       prototypes.  (At least if "Module" uses "Exporter"'s "import",
23       otherwise it is a fatal error.)
24
25       If the module "Module" is not loaded yet, then the above declaration
26       declares functions func1() and func2() in the current package.  When
27       these functions are called, they load the package "Module" if needed,
28       and substitute themselves with the correct definitions.
29

WARNING

31       Using "autouse" will move important steps of your program's execution
32       from compile time to runtime.  This can
33
34       ·   Break the execution of your program if the module you "autouse"d
35           has some initialization which it expects to be done early.
36
37       ·   hide bugs in your code since important checks (like correctness of
38           prototypes) is moved from compile time to runtime.  In particular,
39           if the prototype you specified on "autouse" line is wrong, you will
40           not find it out until the corresponding function is executed.  This
41           will be very unfortunate for functions which are not always called
42           (note that for such functions "autouse"ing gives biggest win, for a
43           workaround see below).
44
45       To alleviate the second problem (partially) it is advised to write your
46       scripts like this:
47
48         use Module;
49         use autouse Module => qw(carp($) croak(&$));
50         carp "this carp was predeclared and autoused ";
51
52       The first line ensures that the errors in your argument specification
53       are found early.  When you ship your application you should comment out
54       the first line, since it makes the second one useless.
55

AUTHOR

57       Ilya Zakharevich (ilya@math.ohio-state.edu)
58

SEE ALSO

60       perl(1).
61
62
63
64perl v5.26.3                      2018-03-01                      autouse(3pm)
Impressum