tags:

views:

56

answers:

2

I have written a Perl API and it is used by many programs across teams. I want to track all programs calling my API method. I want to have something like the below

 debug("The calling method is ",  $XXXX); 

How to get $XXXX ?

+7  A: 

perldoc -f caller.

print "The calling function is", (caller 1)[3], "\n";
hobbs
Thanks hobbs. That was useful
Nirmal Singh Raja Reegan
+2  A: 

Also see the functions in the Carp module, which wrap the caller function and can serve as a sort of warn function with caller information.

use Carp qw(carp cluck);

carp "This function was called from ";  # caller info will be appended to output

cluck "The full stack trace up to this point is ";
mobrule
Thanks mobrule. This is more than what I expected. Cool, thanks!
Nirmal Singh Raja Reegan