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

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

Thread Next
From:
Father Chrysostomos via RT
Date:
January 9, 2012 16:21
Subject:
[perl #40333] overload::Overloaded depends on bad Class->can
Message ID:
rt-3.6.HEAD-14510-1326154890-520.40333-15-0@perl.org
On Wed Sep 13 12:05:05 2006, chromatic@wgz.org 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
> VERSION().

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
https://rt.perl.org:443/rt3/Ticket/Display.html?id=40333

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About