1Module::Load(3)       User Contributed Perl Documentation      Module::Load(3)
2
3
4

NAME

6       Module::Load - runtime require of both modules and files
7

SYNOPSIS

9               use Module::Load;
10
11           my $module = 'Data:Dumper';
12           load Data::Dumper;      # loads that module
13           load 'Data::Dumper';    # ditto
14           load $module            # tritto
15
16           my $script = 'some/script.pl'
17           load $script;
18           load 'some/script.pl';      # use quotes because of punctuations
19
20           load thing;             # try 'thing' first, then 'thing.pm'
21
22           load CGI, ':standard'   # like 'use CGI qw[:standard]'
23

DESCRIPTION

25       "load" eliminates the need to know whether you are trying to require
26       either a file or a module.
27
28       If you consult "perldoc -f require" you will see that "require" will
29       behave differently when given a bareword or a string.
30
31       In the case of a string, "require" assumes you are wanting to load a
32       file. But in the case of a bareword, it assumes you mean a module.
33
34       This gives nasty overhead when you are trying to dynamically require
35       modules at runtime, since you will need to change the module notation
36       ("Acme::Comment") to a file notation fitting the particular platform
37       you are on.
38
39       "load" eliminates the need for this overhead and will just DWYM.
40

Rules

42       "load" has the following rules to decide what it thinks you want:
43
44       ·   If the argument has any characters in it other than those matching
45           "\w", ":" or "'", it must be a file
46
47       ·   If the argument matches only "[\w:']", it must be a module
48
49       ·   If the argument matches only "\w", it could either be a module or a
50           file. We will try to find "file.pm" first in @INC and if that
51           fails, we will try to find "file" in @INC.  If both fail, we die
52           with the respective error messages.
53

Caveats

55       Because of a bug in perl (#19213), at least in version 5.6.1, we have
56       to hardcode the path separator for a require on Win32 to be "/", like
57       on Unix rather than the Win32 "\". Otherwise perl will not read its own
58       %INC accurately double load files if they are required again, or in the
59       worst case, core dump.
60
61       "Module::Load" cannot do implicit imports, only explicit imports.  (in
62       other words, you always have to specify explicitly what you wish to
63       import from a module, even if the functions are in that modules'
64       @EXPORT)
65

ACKNOWLEDGEMENTS

67       Thanks to Jonas B. Nielsen for making explicit imports work.
68

BUG REPORTS

70       Please report bugs or other issues to <bug-module-load@rt.cpan.org<gt>.
71

AUTHOR

73       This module by Jos Boumans <kane@cpan.org>.
74
76       This library is free software; you may redistribute and/or modify it
77       under the same terms as Perl itself.
78
79
80
81perl v5.16.3                      2013-02-01                   Module::Load(3)
Impressum