# # Parent Object Dog # package Dog; use vars qw/$AUTOLOAD/; sub AUTOLOAD { my ($self, $autoload) = @_; my @attributes = qw / bone /; my $attr = $AUTOLOAD; # If called through Husky, retrieve the original $AUTOLOAD $attr ||= $autoload; $attr =~ s!(.*?)::!!; return unless $attr =~ /[^A-Z]/; # Get rid of DESTROY if ($attr =~ m!get_(.*)! and grep { /^$1$/ } @attributes) { print "Bonga\n"; return $self->{$1}; } } sub new { my $class = shift; return bless {}, $class; } # # Object Husky, A Husky is a Dog ;) # package Husky; #=pod use vars qw/$AUTOLOAD/; sub AUTOLOAD { my $self = shift; my @attributes = qw / eyes /; my $attr = $AUTOLOAD; $attr =~ s!(.*?)::!!; return unless $attr =~ /[^A-Z]/; # Get rid of DESTROY if ($attr =~ m!get_(.*)! and grep { /^$1$/ } @attributes) { print "Bongo\n"; return $self->{$1}; } $self->SUPER::AUTOLOAD($AUTOLOAD); } #=cut use base 'Dog'; # # Main package # package Main; my $billou = new Husky; print "Get bone : \n"; $billou->get_bone; print "Get eyes : \n"; $billou->get_eyes;