Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Object loading at runtime

by mugwumpjism (Hermit)
on Jun 16, 2005 at 21:31 UTC ( [id://467450]=note: print w/replies, xml ) Need Help??


in reply to Object loading at runtime

There isn't much of a penalty on eval STRING when it's a simple statement like use. Not compared to the time it takes to load the module! :)

You can always use require, but you first have to perform a transform on the module name (this is a design bug which is tidied in Perl 6):

my $module = "Some::Class"; $module =~ s{::}{/}g; $module .= ".pm"; require $module;

There will be a cargo cult disapproving of require, be sure to poke your tongue out at them, laugh and ask them why until they say "'coz" :-).

You can also look at Class::Tangram::Generator for an example of code that defers loading of modules until objects of the relevant type are created, using several different mechanisms.

$h=$ENV{HOME};my@q=split/\n\n/,`cat $h/.quotes`;$s="$h/." ."signature";$t=`cat $s`;print$t,"\n",$q[rand($#q)],"\n";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-19 03:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found