in reply to How best to require subclasses at runtime
I have much the same situation with an app that I wrote. The driver script needs to load a series of modules that I specify in a hash... the keys are class names, and the values are array refs with the instantiation parms.
Anyway, I just look for errors from the eval, which you can parse for keywords if you need. Then I write to a logging class, and move to the next classname.
The relevant code extract:
for my $sysName ( keys %systemList ) { ## Loop through system types $logger->msg("loading class $sysName",0); eval "require $sysName"; ## include the proper module file if ($@) { $logger->msg("Package $sysName not found.",3); next; } ## instantiate the new object my $obj = new ${sysName}( @{$systemList{$sysName}} ); ### etc... }
It may not be the "right" way, but it is working for my purposes. Good luck!
|
|---|