Thanks, but no that's not it. I'm not having a problem calling methods in
the superclass/parentclass - I'm already doing that in the example code I
posted using a reference retreived from ->can(). I could use SUPER:: (If I
was just calling a method on the parent) but checking if the parent has the
capability is safer. Also, calling SUPER:: on the original object wont allow
you to propogate the call all the way up the heirarchy. If the parent then
calls $self->SUPER:: it is calling itself.

My problem is with $self that is retreived high up in the inheritance tree
not being an object of the callers type, but rather of whatever type the
caller got when it did a my $self = shift @_; At present I'm either using
__PACKAGE__ or bless (to bless an object into the current package) to ensure
that the called method gets a 'caller()' object type when doing my $self =
shift @_; Is there a better way to do this?


-----Original Message-----
From: Jeff 'japhy/Marillion' Pinyan [mailto:[EMAIL PROTECTED]]
Sent: Thursday, July 19, 2001 10:15 PM
To: Mark Maunder
Cc: Beginners@Perl. Org
Subject: Re: Is __PACKAGE__->method() the best way...


On Jul 19, Mark Maunder said:

>I'm using __PACKAGE__->method() to call a method that exists in a class
>higher up the inheritance tree when $self in the current method is a
blessed
>object from a class lower down the inheritance tree (relative to the class
>in which I'm doing the __PACKAGE__->method() call). The reason I'm calling
>__PACKAGE__ is because I want $self in the called method to refer to the
>caller rather than the object with exists lower down the heirarchy. I'm
>probably not making much sense, so I've included a working example below.

I think you mean to do something like this:

  package Generic;

  sub foo { ... }
  sub bar { ... }

  package Specific;

  @ISA = 'Generic';

  sub foo { ... }

A Specific object will use Specific::foo(), but Generic::bar().  If you
need to get to Generic::foo(), then you'd use

  sub foo {
    my $self = shift;
    if ($needed) {
      $self->SUPER::foo(@_);
    }
  }

--
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**      Manning Publications, Co, is publishing my Perl Regex book      **


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to