Module::Selector - use the first module, that works.
use Module::Selector; $mods = Module::Selector->new(['Some::Mod', 'Other::Mod', 'YAM']); while(defined($mod = $mods->each)) { $@ = undef; eval { $mod->do_something() }; last unless $@ } $mods->rewind; while(defined($mod = $mods->each)) { $@ = undef; eval { $mod->something_else() }; last unless $@ }
The idea behind this module is to test for a series of modules with a common interface, as to see either which module is able to do a specific task or simply to see which module is installed.
This module is especially useful if you had to test the modules, which you wish to use, multiple times otherwise, which is a bit tricky via eval.
It will try to load the given modules one by one, loading them only if needed.
Creates a new object, should be given a reference to a list of module names (like File::Spec, MP3::Info, ...) as sole argument.
File::Spec
MP3::Info
Returns the next module that was successfully imported via require, returns undef once if no other module could be imported. After that it starts again with the first module..
Resets each(), so that it starts again with the first module, even if there were other modules still availabe to test. Useful if you abort loops and want to start all over again.
each()
None.
Module::Selector saves any errors encountered when loading modules in a locally scoped hash (local to the the _try() function, which is used by each()). This is necessary, sorry.
_try()
Copyright (c) 2006 Odin Kroeger <okroeger@cpan.org>.
All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Module::Selector, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Module::Selector
CPAN shell
perl -MCPAN -e shell install Module::Selector
For more information on module installation, please visit the detailed CPAN module installation guide.