Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How to identify available subclasses?

by Fletch (Bishop)
on Sep 08, 2008 at 14:01 UTC ( [id://709766]=note: print w/replies, xml ) Need Help??


in reply to How to identify available subclasses?

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.
The cake is a lie.
The cake is a lie.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://709766]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-16 20:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found