in reply to Class Methods
In a class inheriting from class A, any method you declare will replace class A's method of the same name in your new class, so your class B's 123 need do nothing special. In class C, you can access the superclass's method using the special pseudo-package SUPER:::
package C; our @ISA = qw/ A /; sub 123 { my $self = shift; # let my superclass do its thing first my $result = $self->SUPER::123(@_); # now I'll do a bit ... }
Note that occasionally you may need to be careful to propagate your caller's context to the SUPER:: call, if the supermethod acts differently depending on it. Eg:
sub 123 { my $self = shift; my(@array, $scalar); if (wantarray) { @array = $self->SUPER::123(@_); } elsif (defined wantarray) { $scalar = $self->SUPER::123(@_); } else { $self->SUPER::123(@_); } # do more stuff return wantarray ? @array : $scalar; }
For more complex class hierarchies, or if generating class methods at runtime, you may find the specific semantics of SUPER:: insufficient. If so, you may also want to look at the NEXT module.
Hugo
|
|---|