Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by pc88mxer (Vicar)
on Jun 06, 2008 at 17:37 UTC ( #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');


Comment on Re^2: Identify the package a subroutine is being called from
Select or Download Code
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
Node Status?
node history
Node Type: note [id://690713]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (14)
As of 2015-07-01 16:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (8 votes), past polls