1Module::Load::ConditionaPle(r3lpmP)rogrammers ReferenceMoGduuildee::Load::Conditional(3pm)
2
3
4
6 Module::Load::Conditional - Looking up module information / loading at
7 runtime
8
10 use Module::Load::Conditional qw[can_load check_install requires];
11
12
13 my $use_list = {
14 CPANPLUS => 0.05,
15 LWP => 5.60,
16 'Test::More' => undef,
17 };
18
19 print can_load( modules => $use_list )
20 ? 'all modules loaded successfully'
21 : 'failed to load required modules';
22
23
24 my $rv = check_install( module => 'LWP', version => 5.60 )
25 or print 'LWP is not installed!';
26
27 print 'LWP up to date' if $rv->{uptodate};
28 print "LWP version is $rv->{version}\n";
29 print "LWP is installed as file $rv->{file}\n";
30
31
32 print "LWP requires the following modules to be installed:\n";
33 print join "\n", requires('LWP');
34
35 ### allow M::L::C to peek in your %INC rather than just
36 ### scanning @INC
37 $Module::Load::Conditional::CHECK_INC_HASH = 1;
38
39 ### reset the 'can_load' cache
40 undef $Module::Load::Conditional::CACHE;
41
42 ### don't have Module::Load::Conditional issue warnings --
43 ### default is '1'
44 $Module::Load::Conditional::VERBOSE = 0;
45
46 ### The last error that happened during a call to 'can_load'
47 my $err = $Module::Load::Conditional::ERROR;
48
50 Module::Load::Conditional provides simple ways to query and possibly
51 load any of the modules you have installed on your system during
52 runtime.
53
54 It is able to load multiple modules at once or none at all if one of
55 them was not able to load. It also takes care of any error checking and
56 so forth.
57
60 );
61 "check_install" allows you to verify if a certain module is installed
62 or not. You may call it with the following arguments:
63
64 module
65 The name of the module you wish to verify -- this is a required key
66
67 version
68 The version this module needs to be -- this is optional
69
70 verbose
71 Whether or not to be verbose about what it is doing -- it will
72 default to $Module::Load::Conditional::VERBOSE
73
74 It will return undef if it was not able to find where the module was
75 installed, or a hash reference with the following keys if it was able
76 to find the file:
77
78 file
79 Full path to the file that contains the module
80
81 dir Directory, or more exact the @INC entry, where the module was
82 loaded from.
83
84 version
85 The version number of the installed module - this will be "undef"
86 if the module had no (or unparsable) version number, or if the
87 variable $Module::Load::Conditional::FIND_VERSION was set to true.
88 (See the "GLOBAL VARIABLES" section below for details)
89
90 uptodate
91 A boolean value indicating whether or not the module was found to
92 be at least the version you specified. If you did not specify a
93 version, uptodate will always be true if the module was found. If
94 no parsable version was found in the module, uptodate will also be
95 true, since "check_install" had no way to verify clearly.
96
97 $bool = can_load( modules => { NAME => VERSION [,NAME => VERSION] },
98 [verbose => BOOL, nocache => BOOL] )
99 "can_load" will take a list of modules, optionally with version numbers
100 and determine if it is able to load them. If it can load *ALL* of them,
101 it will. If one or more are unloadable, none will be loaded.
102
103 This is particularly useful if you have More Than One Way (tm) to solve
104 a problem in a program, and only wish to continue down a path if all
105 modules could be loaded, and not load them if they couldn't.
106
107 This function uses the "load" function from Module::Load under the
108 hood.
109
110 "can_load" takes the following arguments:
111
112 modules
113 This is a hashref of module/version pairs. The version indicates
114 the minimum version to load. If no version is provided, any version
115 is assumed to be good enough.
116
117 verbose
118 This controls whether warnings should be printed if a module failed
119 to load. The default is to use the value of
120 $Module::Load::Conditional::VERBOSE.
121
122 nocache
123 "can_load" keeps its results in a cache, so it will not load the
124 same module twice, nor will it attempt to load a module that has
125 already failed to load before. By default, "can_load" will check
126 its cache, but you can override that by setting "nocache" to true.
127
128 @list = requires( MODULE );
129 "requires" can tell you what other modules a particular module
130 requires. This is particularly useful when you're intending to write a
131 module for public release and are listing its prerequisites.
132
133 "requires" takes but one argument: the name of a module. It will then
134 first check if it can actually load this module, and return undef if it
135 can't. Otherwise, it will return a list of modules and pragmas that
136 would have been loaded on the module's behalf.
137
138 Note: The list "require" returns has originated from your current perl
139 and your current install.
140
142 The behaviour of Module::Load::Conditional can be altered by changing
143 the following global variables:
144
145 $Module::Load::Conditional::VERBOSE
146 This controls whether Module::Load::Conditional will issue warnings and
147 explanations as to why certain things may have failed. If you set it to
148 0, Module::Load::Conditional will not output any warnings. The default
149 is 0;
150
151 $Module::Load::Conditional::FIND_VERSION
152 This controls whether Module::Load::Conditional will try to parse (and
153 eval) the version from the module you're trying to load.
154
155 If you don't wish to do this, set this variable to "false". Understand
156 then that version comparisons are not possible, and
157 Module::Load::Conditional can not tell you what module version you have
158 installed. This may be desirable from a security or performance point
159 of view. Note that $FIND_VERSION code runs safely under "taint mode".
160
161 The default is 1;
162
163 $Module::Load::Conditional::CHECK_INC_HASH
164 This controls whether "Module::Load::Conditional" checks your %INC hash
165 to see if a module is available. By default, only @INC is scanned to
166 see if a module is physically on your filesystem, or avialable via an
167 "@INC-hook". Setting this variable to "true" will trust any entries in
168 %INC and return them for you.
169
170 The default is 0;
171
172 $Module::Load::Conditional::CACHE
173 This holds the cache of the "can_load" function. If you explicitly want
174 to remove the current cache, you can set this variable to "undef"
175
176 $Module::Load::Conditional::ERROR
177 This holds a string of the last error that happened during a call to
178 "can_load". It is useful to inspect this when "can_load" returns
179 "undef".
180
182 "Module::Load"
183
185 Please report bugs or other issues to
186 <bug-module-load-conditional@rt.cpan.org>.
187
189 This module by Jos Boumans <kane@cpan.org>.
190
192 This library is free software; you may redistribute and/or modify it
193 under the same terms as Perl itself.
194
195
196
197perl v5.10.1 2009-02-25 Module::Load::Conditional(3pm)