develooper Front page | perl.perl5.porters | Postings from January 2012

[perl #40333] overload::Overloaded depends on bad Class->can

Thread Next
Father Chrysostomos via RT
January 9, 2012 16:21
[perl #40333] overload::Overloaded depends on bad Class->can
Message ID:
On Wed Sep 13 12:05:05 2006, wrote:
> On Wednesday 13 September 2006 09:33, Joshua b.Jore wrote:
> > overload::Overloaded depends on the overloaded object's class's
> > implementation of ->can returning true for the method (). ->can is
> > part of the class implementation and might not know that () is a
> > special case to be handled. In my code I had a ->can() that always
> > returned false because I had an object with no valid methods.
> Your can() is broken.  I don't understand why you expect any other
> code to
> work with it.
> By way of analogy, how should external code cope with:
> 	sub new {}
> ?
> At least your can() should call SUPER::can() to respond affirmatively
> for the
> methods valid on *any Perl object* such as can(), isa(), and

But the whole purpose of overriding ->can is to make it work with
AUTOLOAD.  Overloading does not respect AUTOLOAD, and therefore overload
methods are not your regular methods.  So calling ->can for overload
methods is almost always wrong.  An overridden ->can could return true,
because it delegates all unknown methods to some other object (and its
own can returns SUPER::can{@_} || $that_object->can($_[1])).  That’s
perfectly reasonable, but overload::Overloaded’s current implementation
cannot handle it.


Father Chrysostomos

via perlbug:  queue: perl5 status: open

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About