Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Identify the package a subroutine is being called from

by pc88mxer (Vicar)
on Jun 06, 2008 at 17:37 UTC ( [id://690713]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://690713]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-03-28 21:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found