Odin Kroeger > Module-Selector-0.10 > Module::Selector

Download:
Module-Selector-0.10.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.10   Source  

NAME ^

Module::Selector - use the first module, that works.

SYNOPSIS ^

        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 $@
        }

DESCRIPTION ^

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.

METHODS ^

new(LIST REFERENCE TO PKGS)

Creates a new object, should be given a reference to a list of module names (like File::Spec, MP3::Info, ...) as sole argument.

each

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..

rewind

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.

EXPORTS ^

None.

CAVEATS ^

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.

AUTHOR ^

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.

syntax highlighting: