Pathologically Eclectic Rubbish Lister | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Actually you'd want to walk the symbol table looking for @ISA in various packages which refer back (directly or indirectly) to your superclass, not @INC. But it sounds like you're trying to do an abstract factory pattern, in which case a cleaner mechanism would be to provide a callback in the top level factory package which implementing subclasses call to register themselves (e.g. in your MyLogFactory::Parser::Foo module it calls MyLogFactory->registerParser( 'Foo' => 'MyLogFactory::Parser::Foo' );, which then makes MyLogFactory->parserFor( 'Foo' ) return an instance of MyLogFactory::Parser::Foo). (Granted in perl you could have my $parserClass = 'MyLogFactory::Parser::Foo' and $parserClass->new straight in the calling code and would work too . . .; unlike (say) C++ you don't need to register a hard pointer to the constructor since the client code can dynamically instantiate itself with just the package name :) Update: tweaked trailing parenthetical's wording to clarify.
The cake is a lie. In reply to Re: How to identify available subclasses?
by Fletch
|
|