Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by f00li5h (Chaplain)
on Jul 18, 2009 at 22:15 UTC ( [id://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;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-16 15:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found