http://qs321.pair.com?node_id=339191


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

$self= new $breed; . . . bless $self,$breed;

I don't think this will do what you want. This will re-bless the reference into the dog package, which means that if you asked for a 'cocker' breed, any methods that dog::cocker overrides won't be called. Instead, the methods in dog will be called. Update: Read the code wrong--ignore this pargraph.

Which is really unfortunate, since it could be quite useful to override the bark method in your final example. Instead of checking if this instance has a voice attribute that is true, the subclass would already know and Do The Right Thing. That's where polymorphism starts becoming powerful.

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

Note: All code is untested, unless otherwise stated