NAME
Module::Loader - Load modules dynamically and installs missing ones
DESCRIPTION
This module does exactly what it says on the tin. It's a module loader. You can load multiple modules in one go by importing them with Module::Loader, or load a single one with load_module
, which also accepts an array to pass to the module. Module::Loader comes with some import options to switch on/off verbose information and the optional ability to automatically download any missing modules once the script exists. Please be aware this feature is still under heavy development and needs some tweaking. For it to work properly you'll want to make sure you don't need sudo to install modules (ie: App::perlbrew).
SYNOPSIS
use Module::Loader qw/
Goose
Try::Tiny
/;
Or to load a single module
BEGIN {
load_module 'Moose';
load_module 'Try::Tiny';
load_module 'Goose' => qw/:Debug :UseMoose/;
}
TRIGGERS
Module::Loader has 3 tiggers, which are all OFF by default. Triggers can be turned on by passing it as an import option when you use Module::Loader
. All options MUST have a ':' in front of them or it will try to load it as a module.
use Module::Loader qw/
:InstallMissing
:Complain
Goose
/;
:InstallMissing
- Once the script exists, :InstallMissing will attempt to fetch any missing modules via cpanm (App::cpanminus).
:Complain
- This will turn on some minor verbose information, pretty much just saying it couldn't find a module without printing out the entire contents of @INC to your screen.
:Moan
- This trigger switches on :Complain, but will also display the normal ugly Perl errors for a bit more information in case you need it.
EXPORTED METHODS
load_module
This method, well, it loads a module. The difference between this and the other one is this can take an optional array to pass to the module on load, and you can use it to dynamically load other modules in your code.
load_module 'ThisModule';
load_module 'ThatModule => qw/exported_method something_else/;
is_module_loaded
Simply performs a little test to see if the specified module is loaded. Returns 1 on success, or 0 on failure
if (is_module_loaded 'Goose') {
print "It's loaded!\n";
}
else {
print "Module not loaded :-(\n";
load_module 'Goose';
}
BUGS
Please e-mail brad@geeksware.net
AUTHOR
Brad Haywood <brad@geeksware.net>
COPYRIGHT & LICENSE
Copyright 2011 the above author(s).
This sofware is free software, and is licensed under the same terms as perl itself.