tomgracey has asked for the wisdom of the Perl Monks concerning the following question:
Hi All
I am sure this is a really simple question but cant figure out how to search for it (I'm not the sharpest stick in the box with Perl anyway tbh). This is a general Perl question, but I am using Moose so a Moose solution would be ok. Suppose I have 2 classes:
package Parent; use Moose; sub who_am_i{ return __PACKAGE__; } package Child; extends 'Parent'; ... some specific Child methods ...
Now if I do
my $child = Child->new; print $child->who_am_i;
I get Parent not Child. (At least this is what seems to happen from my experimentation. Unless I am doing something wrong!)
Is there a way the who_am_i method can be placed in the parent class, but return the package name of the actual initiated class (the child) ?
Sorry for such a basic question!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: find the package name of an inherited object from inside the parent
by Corion (Patriarch) on Jul 07, 2013 at 08:33 UTC | |
by tomgracey (Scribe) on Jul 07, 2013 at 09:27 UTC | |
|
Re: find the package name of an inherited object from inside the parent
by moritz (Cardinal) on Jul 07, 2013 at 09:15 UTC |