In a comment on my UNIVERSAL::can module, someone asked "Why would a class override
Easy. Suppose your code is paranoid about the objects it receives to certain methods. You want to make sure that you don't call invalid methods on invalid invocants.
That's fine. That's good. You don't want your code to break.
Of course, you're totally fine breaking my code. What if I look carefully at the interface and behavior you require from such an object and write a proxy object that does absolutely everything right? There are lots of reasons to do this -- caching, autouse trampolines, testing with Test::MockObject, logging, debugging.
If I don't override
isa() in my class, your code vomits messily even if my object does exactly what your code needs it to do because all you care about is that the object you receive inherits from some base class. Yippee. You broke my code for no good reason.
That's why Perl 6 has roles and suggests that
does() is the question you should ask of a potential invocant instead of
isa(). That's why you can override
isa() in Perl 5.
If your code doesn't allow that (say -- if you use
UNIVERSAL::isa() as a function, not a method), your code is broken and wrong. Please fix it.
(Still don't believe me? Go break your own code for a change:
download Acme::UNIVERSAL::new and replace all of your constructor calls with calls to
UNIVERSAL::new(). If that doesn't make the problem abundantly clear, I don't know what else to say.)
Update: removed a clause that may have given offense. I apologize to everyone who read the previous version.