[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] alien method calls



John Porter wrote:
> I didn't realize until today that method names are only looked up
> in the objects's inheritance tree if unqualified.  If qualified
> (and it goes without saying that Fully Qualified is the only kind),
> the fully named sub is called, regardless of the class of the object.
> Somewhat unexpected -- though not unpleasant.
> 
>   sub Foo::goo { print ref($_[0])," Foo::goo\n"; }
> 
>   sub Moo::goo { print ref($_[0])," Moo::goo\n"; }
> 
>   my $o = bless {}, 'Foo';
> 
>   $o->goo();          # prints "Moo Foo::goo"
> 
>   $o->Moo::goo();     # prints "Moo Moo::goo"

Well, it's more useful if there is at least some relation between the classes.
I suspect that this feature exists mainly so you can say:

  sub stuff{
    $self->SUPER::stuff(@_);
    # Do extra stuff here
  }

but I do have some production code which does this:

sub EJ::handle_trans{
  # Set up self
  $self->{siteuri}=$self->siteuri;
  $self->{jnluri}=$self->Info::siteuri;
  # More setup stuff
}

You can see it in action at http://www.iop.org/EJ/

However, the method isn't necessarily the one which was explicitly named.
That's just where the method search starts. You could end up calling a method
in a superclass of the one you named.

-- 
	Peter Haworth	pmh@edison.ioppublishing.com
"Master, does Emacs have the Buddha nature?" the novice asked.
The Chief Priest had been in the temple for many years and could be
relied upon to know these things.  He thought for several minutes before
replying, "I don't see why not.  It's got bloody well everything else."


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe