If you need to do this outside of the TOOLS package, you're doing something very wrong. The code that's using the $tools object should not need to know or care what $tool's inheritance chain is. If your TOOL's Callme() cannot work without also using AGENT::Callme(), then you should set it up so that AGENT::Callme is called automatically from TOOL::Callme, not rely on the user to do it for you. Same goes for new().my $tools = new TOOLS; $tools->SUPER::Callme(); # it should call the AGENT::Callme $tools->Callme();
As explained by someone else above, you can't (and shouldn't) use SUPER outside of the package that is the subclass.package TOOLS; sub new { my ($package) = @_; my $self = $package->SUPER::new(); # do other stuff, or remove this whole sub if # you're not acutally doing anything in this # method and let AGENT's new() method do all the work. return $self; } sub Callme { my ($self) = @_; $self->SUPER::Callme(); # do stuff. }
In reply to Re: How to do basic inheritance in Perl OO?
by Joost
in thread How to do basic inheritance in Perl OO?
by opensourcer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |