I don't seem to have any trouble with what I think you want. Does the following code work for you?
#!/usr/bin/perl use strict; use warnings; package Parent; sub new { bless {}, shift; } sub DESTROY {} sub AUTOLOAD { our $AUTOLOAD; my $self = shift; print "Parent called for '$AUTOLOAD' on $self\n"; } package Child; our @ISA = 'Parent'; sub AUTOLOAD { our $AUTOLOAD; my $self = shift; my ($method) = $AUTOLOAD =~ /::(\w+)$/; my $parent = "SUPER::$method"; return $self->$parent( @_ ) unless $method =~ /^kid_/; print "Child called for '$method' on $self\n"; } package Grandchild; our @ISA = 'Child'; sub AUTOLOAD { our $AUTOLOAD; my $self = shift; my ($method) = $AUTOLOAD =~ /::(\w+)$/; my $parent = "SUPER::$method"; return $self->$parent( @_ ) unless $method =~ /^grandkid_/; print "Grandchild called for '$method' on $self\n"; } package main; print "Constructors\n"; my $p = Parent->new(); my $k = Child->new(); my $gc = Grandchild->new(); print "Calling foo() on all\n"; $p->foo(); $k->foo(); $gc->foo(); print "Calling kid_foo() on child and grandchild\n"; $k->kid_foo(); $gc->kid_foo(); print "Calling grandkid_foo() on grandchild\n"; $gc->grandkid_foo();
In reply to Re: More then one AUTOLOAD in a class hierarchy.
by chromatic
in thread More then one AUTOLOAD in a class hierarchy.
by ced
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |