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" elimates 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" first in @INC and if that fails,
51           we will try to find "file.pm" in @INC.  If both fail, we die with
52           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 seperator for a require on Win32 to be "/", like
57       on Unix rather than the Win32 "\". Otherwise perl will not read it's
58       own %INC accurately double load files if they are required again, or in
59       the worst case, core dump.
60
61       "Module::Load" can not do implicit imports, only explicit imports.  (in
62       other words, you always have to specify expliclity what you wish to
63       import from a module, even if the functions are in that modules'
64       @EXPORT)
65

AUTHOR

67       This module by Jos Boumans <kane@cpan.org>.
68
69       Thanks to Jonas B. Nielsen for making explicit imports work.
70
72       This module is copyright (c) 2002 Jos Boumans <kane@cpan.org>.  All
73       rights reserved.
74
75       This library is free software; you may redistribute and/or modify it
76       under the same terms as Perl itself.
77
78
79
80perl v5.8.8                       2004-06-02                   Module::Load(3)
Impressum