Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: $functions xor $methods

by particle (Vicar)
on Oct 30, 2002 at 01:43 UTC ( #208945=note: print w/replies, xml ) Need Help??


in reply to $functions xor $methods

i don't have time to do the legwork, but it might be possible to use some magic combination of AUTOLOAD and goto &NAME to call the parent class if the function doesn't exist in the subclass.

hope that helps, Ovid

~Particle *accelerates*

Replies are listed 'Best First'.
Re: Re: $functions xor $methods
by BUU (Prior) on Oct 30, 2002 at 03:28 UTC
    Only problem is that it requires a hardcoded 'parent' value (unless theres some way to return that?)
    sub AUTOLOAD { if(defined &{__PARENT__::$AUTOLOAD}) { goto &{__PARENT__::$AUTOLOAD} } }
    (note i left out the part about getting the right value in $AUTOLOAD, chopping out the package and stuff)
      something like this seems to work and doesn't require hardcoded names. it just grabs the first parent method (in @ISA order) it finds:
      sub AUTOLOAD { no strict; my $METHOD; ($METHOD = $AUTOLOAD) =~ s/.*:://; foreach my $PARENT (@ISA) { if(defined &{$PARENT.'::'.$METHOD}) { goto &{$PARENT.'::'.$METHOD} } } }
      either this, or use Damian's NEXT module.

      cheers,
      Aldo

      King of Laziness, Wizard of Impatience, Lord of Hubris

      SUPER::$AUTOLOAD should work.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://208945]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2022-08-11 23:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?