in reply to Re: Identify the package a subroutine is being called from
in thread Identify the package a subroutine is being called from

The debugger certain can get the calling arguments, even if @_ has been modified (i.e. shifted).

Here's a solution using Devel::StackTrace:

use Devel::StackTrace; sub calling_object { my $t = Devel::StackTrace->new; my $f; $f = $t->next_frame for (1..4); ($f->args)[0] } sub e { my $x = shift; print "x = $x\n"; d('humma'); } sub d { print "I was called by object ", calling_object(), "\n"; } e('a', 'b', 'c');

Replies are listed 'Best First'.
Re^3: Identify the package a subroutine is being called from
by jettero (Monsignor) on Jun 06, 2008 at 17:50 UTC
    Holy crap. That's exactly what I wanted. I should have asked years ago.

    -Paul