dsheroh has asked for the wisdom of the Perl Monks concerning the following question:
I have a couple applications which currently use a class hierarchy with an abstract MyNamespace::Event base class and half a dozen MyNamespace::Event::Foo subclasses which actually do things. I'll be adding more of them in the future. A lot more. And I don't want to have the headaches of trying to keep everything updated to be aware of every subclass each time I add a new one.
I suppose I could just create one huge module which contains all of them, but that has its own issues. What I'd ideally like to be able to do is use MyNamespace::Event::*, but, as I expected, that doesn't work.
The closest thing I've been able to find to a solution is to find the plugin directory, get a list of the files there, and then require each one. While it would work, I don't like it. Multiple apps means I can't just use a subdirectory of the app directory without duplicating all relevant files, plus I want to leave them in @INC anyhow for times when I'm dealing with simple side tasks that only need to use a couple of them without needing to load up everything. require also lacks a little of use's functionality, although I'm not sure whether I'll ever need to worry about exporting from this section of the namespace, so that may not matter anyhow.
Are there any other options or is foreach my $file (glob('/some/dir/*')) { require $file } pretty much the only way to do this?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Polymorphic Plugins
by Fletch (Bishop) on Jul 11, 2007 at 20:43 UTC | |
by dsheroh (Monsignor) on Jul 11, 2007 at 21:12 UTC | |
|
Re: Polymorphic Plugins
by jZed (Prior) on Jul 11, 2007 at 20:44 UTC |