laziness, impatience, and hubris | |
PerlMonks |
Re: Is "ref($class) || $class" a bad thing?by dragonchild (Archbishop) |
on Jul 12, 2004 at 16:13 UTC ( [id://373644]=note: print w/replies, xml ) | Need Help?? |
merlyn has railed against this construct for years. Do a Super Search for "cargo-cult programming" and you'll find hundreds of nodes on the topic.
Basically, that construct is saying "This method can be called as either a class or instance method". While this may be neat (for example, Test::Cmd takes advantage of this by inheriting from File::Spec), it's certainly not helpful in most cases. But, I must take exception with one of the conclusions you're implying. The error in line 14 is caused by the fact that your new() method isn't verifying that it was actually passed anything. The better solution is:
Of course, this still doesn't fully work because it doesn't take into account Foo::new( {} );, which will return an object blessed into the HASH class. So, maybe we should do something like:
That should take care of most situations I can think of. But, we're just getting stupid. :-) ------
Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose I shouldn't have to say this, but any code, unless otherwise stated, is untested
In Section
Meditations
|
|