MODULE::LOAD::CONDITIONAL(3perl)
๐ธ NAME ๐ธ
Module::Load::Conditional โ looking up module information, and loading modules at runtime ๐ โจ
(Yeah, the header up top squishes it to Module...itional(3perl) because terminals have no chill about column width. It's still our girl. And it lives in the Perl Programmers Reference Guide ๐)
โจ SYNOPSIS โจ
use Module::Load::Conditional qw[can_load check_install requires];
my $use_list = {
CPANPLUS => 0.05,
LWP => 5.60,
'Test::More' => undef,
};
print can_load( modules => $use_list )
? 'all modules loaded successfully'
: 'failed to load required modules';
my $rv = check_install( module => 'LWP', version => 5.60 )
or print 'LWP is not installed!';
print 'LWP up to date' if $rv->{uptodate};
print "LWP version is $rv->{version}\n";
print "LWP is installed as file $rv->{file}\n";
print "LWP requires the following modules to be installed:\n";
print join "\n", requires('LWP');
### allow M::L::C to peek in your %INC rather than just
### scanning @INC
$Module::Load::Conditional::CHECK_INC_HASH = 1;
### reset the 'can_load' cache
undef $Module::Load::Conditional::CACHE;
### don't have Module::Load::Conditional issue warnings --
### default is '1'
$Module::Load::Conditional::VERBOSE = 0;
### The last error that happened during a call to 'can_load'
my $err = $Module::Load::Conditional::ERROR;
๐ DESCRIPTION ๐
Okay so Module::Load::Conditional gives you the cutest little ways to query โ and then possibly load โ literally any of the modules you've got installed on your system, all at runtime. No cap. ๐ซถ
And here's the iconic part: it can load a whole squad of modules at once, or it can load none of them if even one of them refused to load. It also handles all the error checking and so forth for you, so you don't have to do it yourself. Main character energy, honestly. ๐
๐ฎ Methods ๐ฎ
๐ซ $href = check_install( module => NAME [, version => VERSION, verbose => BOOL ] );
check_install is your vibe check for one specific question: is this module installed or not? You call it with these args, bestie:
moduleโ the name of the module you wanna verify. This one is a required key, no skipping ๐versionโ the version this module needs to be. This one is optional ๐verboseโ whether or not to be verbose about what it's doing. Defaults to$Module::Load::Conditional::VERBOSE
So what does it give back? If it couldn't find where the module was installed, you get undef. But if it did find the file, you get a hash reference with these keys:
fileโ full path to the file that contains the module ๐๏ธdirโ the directory, or more exactly the@INCentry, the module was loaded fromversionโ the version number of the installed module. This isundefif the module had no version number (or an unparsable one), or if the variable$Module::Load::Conditional::FIND_VERSIONwas set to true. (Scroll down to the GLOBAL VARIABLES section for the tea ๐ต)uptodateโ a boolean telling you whether the module was found to be at least the version you specified. If you didn't specify a version,uptodateis always true as long as the module was found. And if no parsable version was found in the module,uptodatewill also be true, becausecheck_installhad no way to verify it clearly. ๐คทโโ๏ธ
Also peep $Module::Load::Conditional::DEPRECATED, which affects the outcome of this value ๐
๐ซ $bool = can_load( modules => { NAME => VERSION [,NAME => VERSION] }, [verbose => BOOL, nocache => BOOL, autoload => BOOL] )
can_load takes a list of modules, optionally with version numbers attached, and figures out if it can load them. And the rule is ALL or NOTHING: if it can load ALL of them, it will. If one or more of them are unloadable, then none get loaded. Periodt. ๐
This is so useful when you've got More Than One Way (tm) to solve a problem in your program, and you only wanna keep walking down a path if every module on that path could be loaded โ and not load them at all if they couldn't.
Under the hood it uses the load function or the autoload_remote function from Module::Load ๐ง
can_load takes these arguments:
modulesโ a hashref of module/version pairs. The version is the minimum version to load. If no version is given, any version is assumed to be good enough. Slay. โจverboseโ controls whether warnings get printed when a module fails to load. Default is to use the value of$Module::Load::Conditional::VERBOSE.nocacheโcan_loadkeeps its results in a cache, so it won't load the same module twice, and it won't even try to load a module that already failed to load before. By defaultcan_loadchecks that cache, but you can override it by settingnocacheto true. ๐ซ๐๏ธautoloadโ controls whether it imports the functions of a loaded module into the caller package. The default is no importing of any functions. For the details, go read theautoloadfunction and theautoload_remotefunction fromModule::Load๐
๐ซ @list = requires( MODULE );
requires tells you what other modules a particular module requires. This is lowkey perfect when you're writing a module for public release and you're listing out its prerequisites ๐
requires takes but one argument: the name of a module. It will then first check if it can actually load that module, and return undef if it can't. Otherwise, it returns a list of modules and pragmas that would have been loaded on that module's behalf. ๐
Note: the list require returns originated from your current perl and your current install. iykyk.
๐ง Global Variables ๐ง
The behaviour of Module::Load::Conditional can be altered by changing these global variables:
๐ $Module::Load::Conditional::VERBOSE
This controls whether Module::Load::Conditional issues warnings and explanations about why certain things may have failed. Set it to 0 and Module::Load::Conditional will not output any warnings. The default is 0;
๐ Okay so fun little detail: the SYNOPSIS up top says the default is'1', and the POD down here says the default is0. Both of those sentences are straight from the source, so make of that what you will. Not my business, I just report. ๐
๐ $Module::Load::Conditional::FIND_VERSION
This controls whether Module::Load::Conditional tries to parse (and eval) the version out of the module you're trying to load. ๐
If you don't wanna do that, set this variable to false. But understand: version comparisons become impossible, and Module::Load::Conditional can't tell you what module version you have installed. From a security or performance point of view, that might be exactly what you want. Note that the $FIND_VERSION code runs safely under taint mode. ๐ก๏ธ
The default is 1;
๐ $Module::Load::Conditional::CHECK_INC_HASH
This controls whether Module::Load::Conditional checks your %INC hash to see if a module is available. By default, only @INC gets scanned to see if a module is physically on your filesystem, or available via an @INC-hook. Set this variable to true and it'll trust any entries in %INC and hand them right back to you. ๐ซถ
The default is 0;
๐ $Module::Load::Conditional::FORCE_SAFE_INC
This controls whether Module::Load::Conditional sanitises @INC by removing ".". The current default setting is 0, but heads up โ this may change in a future release. ๐
๐ $Module::Load::Conditional::CACHE
This holds the cache of the can_load function. If you explicitly wanna nuke the current cache, just set this variable to undef. ๐ฅ
๐ $Module::Load::Conditional::ERROR
This holds a string of the last error that happened during a call to can_load. Super useful to inspect when can_load returns undef. ๐จ
๐ $Module::Load::Conditional::DEPRECATED
This controls whether Module::Load::Conditional checks if a dual-life core module has been deprecated. Set it to true and check_install will return false for uptodate if a dual-life module is found to be loaded from $Config{privlibexp} ๐ญ
The default is 0;
๐ See Also ๐
Module::Load
๐ BUG REPORTS ๐
Found a bug or some other issue? Please report it to <bug-module-load-conditional@rt.cpan.org>. Do it, bestie, they wanna hear from you ๐ซถ
๐ AUTHOR ๐
This module is by Jos Boumans <kane@cpan.org>. Iconic behaviour.
๐ COPYRIGHT ๐
This library is free software; you may redistribute and/or modify it under the same terms as Perl itself. โจ
Okay that's the whole page, bestie! ๐ This one's from perl v5.44.0, dated 2026-10-17 โ the Module...itional(3perl) page from the Perl Programmers Reference Guide. Go forth and conditionally load things, you absolute legend ๐
๐๐ฆ
๐ฆ where this page comes from
- arch rolling: perl 5.44.0-1 ยท Artistic-1.0-Perl AND GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms