Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: Re: •Re: It's a dog, but what kind? (polymorphism , in Perl OO)

by flyingmoose (Priest)
on Mar 24, 2004 at 00:43 UTC ( #339262=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: •Re: It's a dog, but what kind? (polymorphism , in Perl OO)
in thread It's a dog, but what kind? (polymorphism , in Perl OO)

As you say, it's also possible to load all the subclasses before anything is called, but that could get very inefficient fast.
Understood. It could be a killer. As a non-perl example, Sun did something like this with java import in 1.4.x, and we saw numerous performance issues -- and we ended up reimplementing lazy loading of some plugins with reflection (i.e. equivalent of symbol tables) -- ugly!
My favored solution would be to map a breed via a hash:
Great idea, chief! I'd probably use both the hash and require for purity's sake -- and call the import explicitly. You might (I'm theorizing) save a little performance from not using eval at all in that case. But yeah, then you would lose the exception catching (eval block)???


Comment on Re: Re: Re: •Re: It's a dog, but what kind? (polymorphism , in Perl OO)
•Re^5: It's a dog, but what kind? (polymorphism , in Perl OO)
by hardburn (Abbot) on Mar 24, 2004 at 14:10 UTC

    The only problem with require in this case is that if you use a variable for the module name, you have to specify the path to the module, not the bare name. Using eval STRING is the accepted idiom around this problem. Yes, it is slow, but it's probably minimal unless you're doing it in a tight loop. In this example, the error handling aspects of eval are a non-factor, since we're just dieing with the error message anyway. Of course, your own code may or may not do that.

    ----
    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2014-04-17 05:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (439 votes), past polls