#! perl -slw use strict; { package Test1; ## This is the parent class which inherits from nothing sub new{ my $class = shift; return bless { __PACKAGE__ => 'test1 attribute value' }, $class; } sub whatAmI{ __PACKAGE__ }; ## No SUPER->whatAmI to call! ## No SUPER->selfRef. sub selfRef{ shift } 1; } { package Test2; our @ISA = 'Test1'; ## A subclass which inherits from Test1. sub new{ my $class = shift; my $self = $class->SUPER::new; $self->{ __PACKAGE__ } = 'test2 attribute value'; return bless $self, $class; } sub whatAmI{ shift->SUPER::whatAmI() . '->' . __PACKAGE__; }; sub superRef{ shift->SUPER::selfRef; } sub selfRef{ shift } 1; } { package Test3; our @ISA = 'Test2'; ## A sub-subclass which inherits from Test2 sub new{ my $class = shift; my $self = $class->SUPER::new; $self->{ __PACKAGE__ } = 'test3 attribute data'; return bless $self, $class; } sub whatAmI{ shift->SUPER::whatAmI() . '->' . __PACKAGE__; }; sub selfRef{ shift } sub superRef{ shift->SUPER::selfRef; } 1; } package main; my $obj = Test3->new; print 'I am a ', $obj->whatAmI, $/; print 'My instance id is ', $obj, $/; print 'My instance id in the class is ', $obj->selfRef, $/; print 'My instance id in my parent class is ', $obj->superRef, $/; print 'My instance id in my grandparents class is ', $obj->superRef->superRef, $/; __END__ P:\test>332433 I am a Test1->Test2->Test3 My instance id is Test3=HASH(0x18360e0) My instance id in the class is Test3=HASH(0x18360e0) My instance id in my parent class is Test3=HASH(0x18360e0) My instance id in my grandparents class is Test3=HASH(0x18360e0)