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";
In reply to Re: Object loading at runtime
by mugwumpjism
in thread Object loading at runtime
by benrwebb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |