NAME
Best - Fallbackable module loader
SYNOPSIS
# Load the best available YAML module with default imports
use Best qw/YAML::Syck YAML/;
use Best [ qw/YAML::Syck YAML/ ]; # also works
# Load a YAML module and import some symbols
use Best [ [ qw/YAML::Syck YAML/ ], qw/DumpFile LoadFile/ ];
# Load a CGI module but import nothing
use Best [ [ qw/CGI::Simple CGI/ ], [] ];
DESCRIPTION
Often there are several possible providers of some functionality your program needs, but you don't know which is available at the run site. For example, one of the modules may be implemented with XS, or not in the core Perl distribution and thus not necessarily installed.
Best attempts to load modules from a list, stopping at the first successful load and failing only if no alternative was found.
FUNCTIONS
Most of the functionality Best provides is on the use
line; there is only one callable functions as such (see which
below)
If the arguments are either a simple list or a reference to a simple list, the elements are taken to be module names and are loaded in order with their default import function called. Any exported symbols are installed in the caller package.
If the arguments are a listref with a listref as its first element, this interior list is treated as the specification of modules to attempt loading, in order; the rest of the arguments are treated as options to pass on to the loaded module's import function.
To specify a null import (use Some::Module ()
), pass a zero-element listref as the argument list. In the pathological case where you really want to load a module and pass it []
as an argument, specify [ [] ]
as the argument list to Best.
- which
-
In some cases--for example, class methods in OO modules--you want to know which module Best has successfully loaded. Call
<Best-
which>> with the first in your list of module alternatives; the return value is a string containing the name of the loaded module.
DEPLOYMENT ISSUES
If you want to use Best because you aren't sure your target machine has some modules installed, you may wonder what might warrant the assumption that Best.pm
would be available, since it isn't a core module itself.
One solution is to use Inline::Module to inline Best.pm
in your source code. If you don't know this module, check it out -- after you learn what it does, you may decide you don't need Best at all! (If your fallback list includes XS modules, though, you may need to stick with us.)
SEE ALSO
AUTHOR
Gaal Yahas, <gaal at forum2.org>
BUGS
Please report any bugs or feature requests to bug-template-patch at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Best. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Best
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
RT: CPAN's request tracker
Search CPAN
COPYRIGHT & LICENSE
Copyright 2006 Gaal Yahas, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.