in reply to Is there a better way to do this?
And I really don't see any benefit to doing that in 99% of cases. (The other 1% is when you have methods which are sufficiently expensive to compile that you don't want their source code to be processed if the method isn't going to actually be used.)
It seems like it would be a lot more straightforward to just put all the code into a single module (and a single class).
That said, there are definitely ways to do the sort of thing you're asking about. The core Perl language provides the AUTOLOAD keyword to dynamically pull in (or generate) the source of not-yet-defined methods on demand. There are also several fine CPAN modules for handling plugins; I personally use all for simple plugin handling and Module::Pluggable for more complex cases.
|
|---|