On 03/01/2008, chromatic <[EMAIL PROTECTED]> wrote:
> On Thursday 03 January 2008 09:58:28 demerphq wrote:
>
> > And thinking about it more i think that was the whole point of the
> > weird call, Im guessing here, but probably this code isnt in a method
> > which means that he doesnt have access to SUPER so, he passes it into
> > can() which does.
> >
> > The following one liner demonstrates what the author of
> > Template::Timer was (correctly) doing. Note that it doesnt matter if
> > you define B::foo or not.
> >
> > $ perl -le'@B::ISA=qw(A); sub A::foo {print "in A::foo"} package B;
> > sub foo {print "in B::foo"} __PACKAGE__->can("SUPER::foo")->();'
> > in A::foo
>
> Is that documented anywhere to work?  I couldn't find it.  In fact, it
> contradicts the documentation of can():
>
>         "can" checks if the object or class has a method called "METHOD".
>         If it does then a reference to the sub is returned. If it does not
>         then undef is returned.  This includes methods inherited or
>         imported by $obj, "CLASS", or "VAL".

Even if it isnt explicitly documented I take it as being implicitly
documented by the fact that SUPER::  is documented (in perltoot at
least) to have no meaning except inside of a method call. So if you
arent inside of a method call how are you to get access to an objects
overloaded method? And i dont think "you don't" is a good answer as
its clearly useful to do in dynamically constructed classes.

As for the documentation, ive probably been in front of this machine
for too long today so im not seeing the contradiction. Are you basing
this on the bit where it says 'called "METHOD"'?  Personally I dont
think that paragraph goes a long way towards settling things either
way.

OTOH Looking through the sources a bit it looks to me like this is
pretty deliberate behaviour. UNIVERSAL::can() is just a wrapper around
gv_fetchmethod_autoload() which is internally documented to respect
SUPER::.

Also consider the case of $obj->$method(). Unless we want

$method='SUPER::foo';
$obj->can($method)->()

to do something different than

$method='SUPER::foo';
$obj->$method()

I think it has to respect SUPER.

I think when you add up the incidental evidence like things like above
the only rational conclusion is that the native ->can() *is* doing the
right thing.

Yves



-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

Reply via email to