Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: import() when require-d module name is variable

by f00li5h (Chaplain)
on Jul 18, 2009 at 22:15 UTC ( #781385=note: print w/ replies, xml ) Need Help??


in reply to import() when require-d module name is variable

eval qq{ use $module_name }; die "can't $module_name because: $@";

Then perl does all the "finding it" magic ... and you still get to decide the module name at run time...

You could also loop over many alternate modules and ignore failures until you find one you want, but for that you might want Module::Find or similar too ...

use Module::Find qw[ useall ]; my @plugins = useall q/Foo::Bar/; for my $plugin_name (@plugins) { eval qq/require $plugin_name/; my $plugin = $plugin_name->new(); }

Although here my modules are pure OO, so they don't get imported

@_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;


Comment on Re: import() when require-d module name is variable
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://781385]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2014-07-11 23:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (236 votes), past polls