[cgiapp] packages autouse?

Jaldhar H. Vyas jaldhar at braincells.com
Fri Jun 12 11:12:43 EDT 2009


On Fri, 12 Jun 2009, Richard Jones wrote:

> Can Module::Pluggable be used as an alternative to Module::Find? I load all 
> my Model::DB classes up front in a BEGIN block in MyApp::Base, like this:
>
> BEGIN {
>  use Module::Find;
>
>  Module::Find::setmoduledirs('path/to/lib');
>  Module::Find::useall MyApp::DB;
> }
>
> use Module::Pluggable
>  require => 1,
>  search_dirs => [ 'path/to/lib/MyApp/DB' ]
>
> For this to work I need the Module::Pluggable equivalent of useall().

Does this (from the docs) do the trick?

<quote>
Or if you want to instantiate each plugin rather than just return the
        name

            package MyClass;
            use Module::Pluggable instantiate => 'new';

        and then

            # whatever is passed to 'plugins' will be passed
            # to 'new' for each plugin
            my @plugins = $mc->plugins(@options);
</quote>

For non object-oriented modules you could combine require and instantiate 
=> import for an equivalent to use.

-- 
Jaldhar H. Vyas <jaldhar at braincells.com>


More information about the cgiapp mailing list