in reply to find the package name of an inherited object from inside the parent
The Mooseish way to get the dynamic class name is $obj->meta->name:
use 5.010; package Parent; use Moose; sub who_am_I { shift->meta->name }; package Child; use Moose; extends 'Parent'; package main; say Child->new->who_am_I; __END__ Child
$obj->meta returns the metaclass instance for the object's class, and ->name returns the name (surprise, surprise).
(excursion: In Perl 6 it works basically the same, except that there is a shortcut for calling methods on the metaclass: say 1.^name says Int).
|
---|
In Section
Seekers of Perl Wisdom