in reply to How to get code of the calling function or object

This might not be quite right but might offer a jump off. Update: Eliya's answer and example is better.

use warnings; use strict; my $hai = O::HAI->new({ arg => "KTHX" }); BEGIN { package O::HAI; use B::Deparse; use Moose; has "arg" => isa => "Str", is => "ro"; sub BUILD { my ( $package, $filename, $line, $subroutine ) = caller(4); my $sub_ref = do { no strict "refs"; \&{join("::",$package,$subroutine)}; }; my $deparse = B::Deparse->new("-p", "-sC"); my $caller = $deparse->coderef2text($sub_ref); print $caller, $/; } }
{ package Moose::Object; use warnings; use strict 'refs'; (my $class = shift(@_)); (my $real_class = (&Scalar::Util::blessed($class) || $class)); (my $params = $real_class->BUILDARGS(@_)); return('Class::MOP::Class'->initialize($real_class)->new_object($p +arams)); }