Calling UNIVERSAL::can() as a function is allowed.
chromatic at wgz.org
Wed Nov 21 23:54:08 GMT 2007
On Wednesday 21 November 2007 15:25:55 Dirk Koopman wrote:
> > I figured out the other day that the Right Approach was probably to warn
> > only if there's an overridden can/isa that Broken Code doesn't call. I'm
> > going to make that the default behavior of UNIVERSAL::can and
> > UNIVERSAL::isa very shortly, perhaps even this afternoon.
> Remind me again why someone would, in the reasonably normal course of OO
> programming, want to override either can() or isa()? This is now purely
> for my education BTW as, in my case (the start of this thread),
> overriding isn't occurring and couldn't easily anyway.
Test::MockObject and Test::MockObject::Extends use both because they're
proxies. They stand in for real objects, and there's no sense in making you
define everything just to override a few bits and pieces.
Overriding can() is vitally important if you do any kind of dynamic method
dispatch with AUTOLOAD or other techniques.
Overriding isa() is useful in proxy and delegation systems, at least until
people start using DOES() instead. T::MO and T::MO::E do it to work around
code which assumes that manual type-checking via inheritance is useful in
Perl 5. It isn't, but their code does it anyway.
More information about the london.pm