package Parent;
...
sub AUTOLOAD {
my $self = shift @_;
(my $method = $AUTOLOAD) =~ s/^.*:://;
return if $method eq "DESTROY";
if ( $method eq 'parent_method' ) {
# do something
}
}
...
package Child;
...
sub AUTOLOAD {
my $self = shift @_;
(my $method = $AUTOLOAD) =~ s/^.*:://;
return if $method eq "DESTROY";
if ( $method eq 'child_method' ) {
# do something
}
}
####
package Child;
...
sub AUTOLOAD {
my $self = shift @_;
(my $method = $AUTOLOAD) =~ s/^.*:://;
return if $method eq "DESTROY";
if ( $method eq 'child_method' ) {
# do something
}
...
else {
$self->SUPER::AUTOLOAD($method, @_);
}
}
####
package Parent;
...
sub AUTOLOAD {
my $self = shift @_;
my $method;
if ( defined $AUTOLOAD ) {
($method = $AUTOLOAD) =~ s/.*:://;
}
else {
$method = shift @_;
}
...
}
####
# in Child::AUTOLOAD()
# instead of $self->SUPER::AUTOLOAD($method, @_);
my $super_method = 'SUPER::' . $method;
$self->$super_method(@_);