| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "Module::Load::Conditional 3perl" |
| 58 |
.TH Module::Load::Conditional 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
Module::Load::Conditional \- Looking up module information / loading at runtime |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
.Vb 1 |
| 68 |
\& use Module::Load::Conditional qw[can_load check_install requires]; |
| 69 |
\& |
| 70 |
\& |
| 71 |
\& my $use_list = { |
| 72 |
\& CPANPLUS => 0.05, |
| 73 |
\& LWP => 5.60, |
| 74 |
\& \*(AqTest::More\*(Aq => undef, |
| 75 |
\& }; |
| 76 |
\& |
| 77 |
\& print can_load( modules => $use_list ) |
| 78 |
\& ? \*(Aqall modules loaded successfully\*(Aq |
| 79 |
\& : \*(Aqfailed to load required modules\*(Aq; |
| 80 |
\& |
| 81 |
\& |
| 82 |
\& my $rv = check_install( module => \*(AqLWP\*(Aq, version => 5.60 ) |
| 83 |
\& or print \*(AqLWP is not installed!\*(Aq; |
| 84 |
\& |
| 85 |
\& print \*(AqLWP up to date\*(Aq if $rv\->{uptodate}; |
| 86 |
\& print "LWP version is $rv\->{version}\en"; |
| 87 |
\& print "LWP is installed as file $rv\->{file}\en"; |
| 88 |
\& |
| 89 |
\& |
| 90 |
\& print "LWP requires the following modules to be installed:\en"; |
| 91 |
\& print join "\en", requires(\*(AqLWP\*(Aq); |
| 92 |
\& |
| 93 |
\& ### allow M::L::C to peek in your %INC rather than just |
| 94 |
\& ### scanning @INC |
| 95 |
\& $Module::Load::Conditional::CHECK_INC_HASH = 1; |
| 96 |
\& |
| 97 |
\& ### reset the \*(Aqcan_load\*(Aq cache |
| 98 |
\& undef $Module::Load::Conditional::CACHE; |
| 99 |
\& |
| 100 |
\& ### don\*(Aqt have Module::Load::Conditional issue warnings \-\- |
| 101 |
\& ### default is \*(Aq1\*(Aq |
| 102 |
\& $Module::Load::Conditional::VERBOSE = 0; |
| 103 |
\& |
| 104 |
\& ### The last error that happened during a call to \*(Aqcan_load\*(Aq |
| 105 |
\& my $err = $Module::Load::Conditional::ERROR; |
| 106 |
.Ve |
| 107 |
.SH DESCRIPTION |
| 108 |
.IX Header "DESCRIPTION" |
| 109 |
Module::Load::Conditional provides simple ways to query and possibly load any of |
| 110 |
the modules you have installed on your system during runtime. |
| 111 |
.PP |
| 112 |
It is able to load multiple modules at once or none at all if one of |
| 113 |
them was not able to load. It also takes care of any error checking |
| 114 |
and so forth. |
| 115 |
.SH Methods |
| 116 |
.IX Header "Methods" |
| 117 |
.ie n .SS "$href = check_install( module => NAME [, version => VERSION, verbose => BOOL ] );" |
| 118 |
.el .SS "\f(CW$href\fP = check_install( module => NAME [, version => VERSION, verbose => BOOL ] );" |
| 119 |
.IX Subsection "$href = check_install( module => NAME [, version => VERSION, verbose => BOOL ] );" |
| 120 |
\&\f(CW\*(C`check_install\*(C'\fR allows you to verify if a certain module is installed |
| 121 |
or not. You may call it with the following arguments: |
| 122 |
.IP module 4 |
| 123 |
.IX Item "module" |
| 124 |
The name of the module you wish to verify \-\- this is a required key |
| 125 |
.IP version 4 |
| 126 |
.IX Item "version" |
| 127 |
The version this module needs to be \-\- this is optional |
| 128 |
.IP verbose 4 |
| 129 |
.IX Item "verbose" |
| 130 |
Whether or not to be verbose about what it is doing \-\- it will default |
| 131 |
to \f(CW$Module::Load::Conditional::VERBOSE\fR |
| 132 |
.PP |
| 133 |
It will return undef if it was not able to find where the module was |
| 134 |
installed, or a hash reference with the following keys if it was able |
| 135 |
to find the file: |
| 136 |
.IP file 4 |
| 137 |
.IX Item "file" |
| 138 |
Full path to the file that contains the module |
| 139 |
.IP dir 4 |
| 140 |
.IX Item "dir" |
| 141 |
Directory, or more exact the \f(CW@INC\fR entry, where the module was |
| 142 |
loaded from. |
| 143 |
.IP version 4 |
| 144 |
.IX Item "version" |
| 145 |
The version number of the installed module \- this will be \f(CW\*(C`undef\*(C'\fR if |
| 146 |
the module had no (or unparsable) version number, or if the variable |
| 147 |
\&\f(CW$Module::Load::Conditional::FIND_VERSION\fR was set to true. |
| 148 |
(See the \f(CW\*(C`GLOBAL VARIABLES\*(C'\fR section below for details) |
| 149 |
.IP uptodate 4 |
| 150 |
.IX Item "uptodate" |
| 151 |
A boolean value indicating whether or not the module was found to be |
| 152 |
at least the version you specified. If you did not specify a version, |
| 153 |
uptodate will always be true if the module was found. |
| 154 |
If no parsable version was found in the module, uptodate will also be |
| 155 |
true, since \f(CW\*(C`check_install\*(C'\fR had no way to verify clearly. |
| 156 |
.Sp |
| 157 |
See also \f(CW$Module::Load::Conditional::DEPRECATED\fR, which affects |
| 158 |
the outcome of this value. |
| 159 |
.ie n .SS "$bool = can_load( modules => { NAME => VERSION [,NAME => VERSION] }, [verbose => BOOL, nocache => BOOL, autoload => BOOL] )" |
| 160 |
.el .SS "\f(CW$bool\fP = can_load( modules => { NAME => VERSION [,NAME => VERSION] }, [verbose => BOOL, nocache => BOOL, autoload => BOOL] )" |
| 161 |
.IX Subsection "$bool = can_load( modules => { NAME => VERSION [,NAME => VERSION] }, [verbose => BOOL, nocache => BOOL, autoload => BOOL] )" |
| 162 |
\&\f(CW\*(C`can_load\*(C'\fR will take a list of modules, optionally with version |
| 163 |
numbers and determine if it is able to load them. If it can load *ALL* |
| 164 |
of them, it will. If one or more are unloadable, none will be loaded. |
| 165 |
.PP |
| 166 |
This is particularly useful if you have More Than One Way (tm) to |
| 167 |
solve a problem in a program, and only wish to continue down a path |
| 168 |
if all modules could be loaded, and not load them if they couldn't. |
| 169 |
.PP |
| 170 |
This function uses the \f(CW\*(C`load\*(C'\fR function or the \f(CW\*(C`autoload_remote\*(C'\fR function |
| 171 |
from Module::Load under the hood. |
| 172 |
.PP |
| 173 |
\&\f(CW\*(C`can_load\*(C'\fR takes the following arguments: |
| 174 |
.IP modules 4 |
| 175 |
.IX Item "modules" |
| 176 |
This is a hashref of module/version pairs. The version indicates the |
| 177 |
minimum version to load. If no version is provided, any version is |
| 178 |
assumed to be good enough. |
| 179 |
.IP verbose 4 |
| 180 |
.IX Item "verbose" |
| 181 |
This controls whether warnings should be printed if a module failed |
| 182 |
to load. |
| 183 |
The default is to use the value of \f(CW$Module::Load::Conditional::VERBOSE\fR. |
| 184 |
.IP nocache 4 |
| 185 |
.IX Item "nocache" |
| 186 |
\&\f(CW\*(C`can_load\*(C'\fR keeps its results in a cache, so it will not load the |
| 187 |
same module twice, nor will it attempt to load a module that has |
| 188 |
already failed to load before. By default, \f(CW\*(C`can_load\*(C'\fR will check its |
| 189 |
cache, but you can override that by setting \f(CW\*(C`nocache\*(C'\fR to true. |
| 190 |
.IP autoload 4 |
| 191 |
.IX Item "autoload" |
| 192 |
This controls whether imports the functions of a loaded modules to the caller package. The default is no importing any functions. |
| 193 |
.Sp |
| 194 |
See the \f(CW\*(C`autoload\*(C'\fR function and the \f(CW\*(C`autoload_remote\*(C'\fR function from Module::Load for details. |
| 195 |
.ie n .SS "@list = requires( MODULE );" |
| 196 |
.el .SS "\f(CW@list\fP = requires( MODULE );" |
| 197 |
.IX Subsection "@list = requires( MODULE );" |
| 198 |
\&\f(CW\*(C`requires\*(C'\fR can tell you what other modules a particular module |
| 199 |
requires. This is particularly useful when you're intending to write |
| 200 |
a module for public release and are listing its prerequisites. |
| 201 |
.PP |
| 202 |
\&\f(CW\*(C`requires\*(C'\fR takes but one argument: the name of a module. |
| 203 |
It will then first check if it can actually load this module, and |
| 204 |
return undef if it can't. |
| 205 |
Otherwise, it will return a list of modules and pragmas that would |
| 206 |
have been loaded on the module's behalf. |
| 207 |
.PP |
| 208 |
Note: The list \f(CW\*(C`require\*(C'\fR returns has originated from your current |
| 209 |
perl and your current install. |
| 210 |
.SH "Global Variables" |
| 211 |
.IX Header "Global Variables" |
| 212 |
The behaviour of Module::Load::Conditional can be altered by changing the |
| 213 |
following global variables: |
| 214 |
.ie n .SS $Module::Load::Conditional::VERBOSE |
| 215 |
.el .SS \f(CW$Module::Load::Conditional::VERBOSE\fP |
| 216 |
.IX Subsection "$Module::Load::Conditional::VERBOSE" |
| 217 |
This controls whether Module::Load::Conditional will issue warnings and |
| 218 |
explanations as to why certain things may have failed. If you set it |
| 219 |
to 0, Module::Load::Conditional will not output any warnings. |
| 220 |
The default is 0; |
| 221 |
.ie n .SS $Module::Load::Conditional::FIND_VERSION |
| 222 |
.el .SS \f(CW$Module::Load::Conditional::FIND_VERSION\fP |
| 223 |
.IX Subsection "$Module::Load::Conditional::FIND_VERSION" |
| 224 |
This controls whether Module::Load::Conditional will try to parse |
| 225 |
(and eval) the version from the module you're trying to load. |
| 226 |
.PP |
| 227 |
If you don't wish to do this, set this variable to \f(CW\*(C`false\*(C'\fR. Understand |
| 228 |
then that version comparisons are not possible, and Module::Load::Conditional |
| 229 |
can not tell you what module version you have installed. |
| 230 |
This may be desirable from a security or performance point of view. |
| 231 |
Note that \f(CW$FIND_VERSION\fR code runs safely under \f(CW\*(C`taint mode\*(C'\fR. |
| 232 |
.PP |
| 233 |
The default is 1; |
| 234 |
.ie n .SS $Module::Load::Conditional::CHECK_INC_HASH |
| 235 |
.el .SS \f(CW$Module::Load::Conditional::CHECK_INC_HASH\fP |
| 236 |
.IX Subsection "$Module::Load::Conditional::CHECK_INC_HASH" |
| 237 |
This controls whether \f(CW\*(C`Module::Load::Conditional\*(C'\fR checks your |
| 238 |
\&\f(CW%INC\fR hash to see if a module is available. By default, only |
| 239 |
\&\f(CW@INC\fR is scanned to see if a module is physically on your |
| 240 |
filesystem, or available via an \f(CW\*(C`@INC\-hook\*(C'\fR. Setting this variable |
| 241 |
to \f(CW\*(C`true\*(C'\fR will trust any entries in \f(CW%INC\fR and return them for |
| 242 |
you. |
| 243 |
.PP |
| 244 |
The default is 0; |
| 245 |
.ie n .SS $Module::Load::Conditional::FORCE_SAFE_INC |
| 246 |
.el .SS \f(CW$Module::Load::Conditional::FORCE_SAFE_INC\fP |
| 247 |
.IX Subsection "$Module::Load::Conditional::FORCE_SAFE_INC" |
| 248 |
This controls whether \f(CW\*(C`Module::Load::Conditional\*(C'\fR sanitises \f(CW@INC\fR |
| 249 |
by removing "\f(CW\*(C`.\*(C'\fR". The current default setting is \f(CW0\fR, but this |
| 250 |
may change in a future release. |
| 251 |
.ie n .SS $Module::Load::Conditional::CACHE |
| 252 |
.el .SS \f(CW$Module::Load::Conditional::CACHE\fP |
| 253 |
.IX Subsection "$Module::Load::Conditional::CACHE" |
| 254 |
This holds the cache of the \f(CW\*(C`can_load\*(C'\fR function. If you explicitly |
| 255 |
want to remove the current cache, you can set this variable to |
| 256 |
\&\f(CW\*(C`undef\*(C'\fR |
| 257 |
.ie n .SS $Module::Load::Conditional::ERROR |
| 258 |
.el .SS \f(CW$Module::Load::Conditional::ERROR\fP |
| 259 |
.IX Subsection "$Module::Load::Conditional::ERROR" |
| 260 |
This holds a string of the last error that happened during a call to |
| 261 |
\&\f(CW\*(C`can_load\*(C'\fR. It is useful to inspect this when \f(CW\*(C`can_load\*(C'\fR returns |
| 262 |
\&\f(CW\*(C`undef\*(C'\fR. |
| 263 |
.ie n .SS $Module::Load::Conditional::DEPRECATED |
| 264 |
.el .SS \f(CW$Module::Load::Conditional::DEPRECATED\fP |
| 265 |
.IX Subsection "$Module::Load::Conditional::DEPRECATED" |
| 266 |
This controls whether \f(CW\*(C`Module::Load::Conditional\*(C'\fR checks if |
| 267 |
a dual-life core module has been deprecated. If this is set to |
| 268 |
true \f(CW\*(C`check_install\*(C'\fR will return false to \f(CW\*(C`uptodate\*(C'\fR, if |
| 269 |
a dual-life module is found to be loaded from \f(CW$Config{privlibexp}\fR |
| 270 |
.PP |
| 271 |
The default is 0; |
| 272 |
.SH "See Also" |
| 273 |
.IX Header "See Also" |
| 274 |
\&\f(CW\*(C`Module::Load\*(C'\fR |
| 275 |
.SH "BUG REPORTS" |
| 276 |
.IX Header "BUG REPORTS" |
| 277 |
Please report bugs or other issues to <bug\-module\-load\[email protected]>. |
| 278 |
.SH AUTHOR |
| 279 |
.IX Header "AUTHOR" |
| 280 |
This module by Jos Boumans <[email protected]>. |
| 281 |
.SH COPYRIGHT |
| 282 |
.IX Header "COPYRIGHT" |
| 283 |
This library is free software; you may redistribute and/or modify it |
| 284 |
under the same terms as Perl itself. |