This might clarify the problem with your question. If your Tinia_CanPwn class isa subclass of your Tinia_CanExtender class, as indicated by your code snippet, then there is no "parent instance". There is only one object (instance) and it is an instance of Tinia_CanPwm, that has inhereted methods from the Tinia_CanExtender class ... not from an instance of that class.
#! perl -slw use strict; { package Test1; ## This is the parent class which inherits from not +hing sub new{ my $class = shift; return bless { __PACKAGE__ => 'test1 attribute value' }, $clas +s; } 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->s +uperRef, $/; __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)
What this attempts to show is that whilst there are three classes providing methods to the instance $obj, the instance handle is the same regardless of which class you are executing a method from.
In reply to Re: Objects: how to get parent object from child $self reference ?
by BrowserUk
in thread Objects: how to get parent object from child $self reference ?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |