NAME
Tools::Module - Looking up module information / loading at runtime
SYNOPSIS
use Tools::Module qw[can_use check_install requires];
my $use_list = {
CPANPLUS => 0.05,
LWP => 5.60,
'Test::More' => undef,
};
print can_load( modules => $use_list )
? 'all modules loaded succesfully'
: 'failed to load required modules';
my $rv = check_install( module => 'LWP', verion => 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');
### reset the 'can_load' cache
undef $Tools::Module::CACHE;
### don't have Tools::Module issue warnings -- default is '1'
$Tools::Module::VERBOSE = 0;
DESCRIPTION
Tools::Module provides simple ways to query and possibly load any of the modules you have installed on your system during runtime.
It is able to load multiple modules at once or none at all if one of them was not able to load. It also takes care of any error checking and so forth.
Methods
check_install
check_install
allows you to verify if a certain module is installed or not. You may call it with the following arguments:
- module
-
The name of the module you wish to verify -- this is a required key
- version
-
The version this module needs to be -- this is optional
- verbose
-
Whether or not to be verbose about what it is doing -- it will default to $Tools::Module::VERBOSE
It will return undef if it was not able to find where the module was installed, or a hash reference with the following keys if it was able to find the file:
- file
-
Full path to the file that contains the module
- version
-
The version number of the installed module - this will be
undef
if the module had no or an unparsable version number. - uptodate
-
A boolean value indicating whether or not the module was found to be at least the version you specified. If you did not specify a version, uptodate will always be true if the module was found. If no parsable version was found in the module, uptodate will also be true, since
check_install
had no way to verify clearly.
can_load
can_load
will take a list of modules, optionally with version numbers and determine if it is able to load them. If it can load *ALL* of them, it will. If one or more are unloadable, none will be loaded.
This is particularly usefull if you have More Than One Way (tm) to solve a problem in a program, and only wish to continue down a path if all modules could be loaded, and not load them if they couldn't.
This function uses the load
function from Tools::Load under the hood.
can_load
takes the following arguments:
- modules
-
This is a hashref of module/version pairs. The version indicates the minimum version to load. If no version is provided, any version is assumed to be good enough.
- verbose
-
This controls whether warnings should be printed if a module failed to load. The default is to use the value of $Tools::Module::VERBOSE.
- nocache
-
can_load
keeps it's results in a cache, so it will not load the same module twice, nor will it attempt to load a module that has already failed to load before. By default,can_load
will check it's cache, but you can override that by settingnocache
to true.
requires
requires
can tell you what other modules a particular module requires. This is particularly usefull when you're intending to write a module for public release and are listing it's prerequisites.
requires
takes but one argument: the name of a module. It will then first check if it can actually load this module, and return undef if it can't. Otherwise, it will return a list of modules and pragma's that would have been loaded on the module's behalf.
Note: The list require
returns has originated from your current perl and your current install.
Global Variables
The behaviour of Tools::Module can be altered by changing the following global variables:
$Tools::Term::VERBOSE
This controls whether Tools::Module will issue warnings and explenations as to why certain things may have failed. If you set it to 0, Tools::Module will not output any warnings. The default is 1;
$Tools::Term::CACHE
This holds the cache of the can_load
function. If you explicitly want to remove the current cache, you can set this variable to undef
See Also
Tools::Load
AUTHOR
This module by Jos Boumans <kane@cpan.org>.
COPYRIGHT
This module is copyright (c) 2002 Jos Boumans <kane@cpan.org>. All rights reserved.
This library is free software; you may redistribute and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 371:
You forgot a '=back' before '=head2'