UNIVERSAL::isa oddity?

rhesa on 2007-12-28T05:11:49

What's going on here?

   my $foo = bless [], 'foo';

# yep, it's a foo $foo->isa('foo') and print "it's a foo"; # what about the parent? $foo->SUPER::isa('foo') and print "Mommy is a foo too";


I suppose it doesn't make much sense to be asking isa() on the superclass, but huh?


Not the Superclass

chromatic on 2007-12-28T07:16:22

You're calling the parent's method, but you're still calling it on the child. The invocant doesn't change. Only the starting point for method lookup changes.

Re:Not the Superclass

rhesa on 2007-12-28T16:30:23

/me slaps his forehead...

Thanks, chromatic. That did clear up my confusion. I got a bit side-tracked by trying to figure out UNIVERSAL::DOES (and finding practical use for it), but I'll take that to perlmonks.

Thanks also for taking the time to reply in these, uhm, days of peace and celebration. For whatever it's worth, I think you guys are doing great work on Perl 6.

Re:Not the Superclass

chromatic on 2007-12-28T19:08:31

I got a bit side-tracked by trying to figure out UNIVERSAL::DOES (and finding practical use for it), but I'll take that to perlmonks.

It's a method intended explicitly for people to override if they support roles/traits. The default implementation falls back on UNIVERSAL::isa, so it answers the DOES question correctly when the how is "through inheritance".