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

[perl #47113] UNIVERSAL::can is wrong for unloaded classes

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
June 22, 2012 13:09
Subject:
[perl #47113] UNIVERSAL::can is wrong for unloaded classes
Message ID:
rt-3.6.HEAD-5009-1340395775-1436.47113-15-0@perl.org
On Fri Jun 22 12:50:38 2012, doy@tozt.net wrote:
> On Fri, Jun 22, 2012 at 12:35:32PM -0700, Father Chrysostomos via RT
wrote:
> > On Fri Jun 22 12:14:55 2012, doy wrote:
> > > I've pushed a fix for this to the doy/universal branch. It's pretty
> > > straightforward, but some of the tests in t/op/universal.t were
testing
> > > for this behavior explicitly (checking that can() was false before a
> > > package existed and true afterwards), so I'm not sure if this is
> > > reasonable to just change directly. I am in favor of making this
change
> > > though, so any input is welcome.
> > 
> > I think $class->can('can') is a fairly popular way to see whether a
> > class is loaded.
> 
> But (as mst pointed out on #p5p) it doesn't do that at all:
> 
> $ perl -E'package Foo::Bar; say Foo->can("can")'
> CODE(0x1f4a220)
> 
> (since namespaces nest). And having $foo->can("can") not die and yet not
> return anything really seems nonsensical. This feels analogous to the
> defined(@array) issue, to me - people may be using it, but it really
> doesn't do what they think it does, and using it in this way can cause a
> lot of subtle bugs.

Fairy nuff. :-)

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=47113

Thread Previous | 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