2

Possible Duplicate:
In Perl, how can I check from which module a given function was imported?

Hi guys! I am using my weekend time to comb through our web app to get a better understanding of it. It uses numerous modules whose functions get pulled into it and my question is this.. how can I determine the module where a function originates?
Reason I ask is because I am using print STDERR lines sprinkled here and there to understand the way data moves around (it has demystified things greatly).. here's an example....

 ($file_data,$count) = lookup_files($customer,$site,'','0',$d);

What I'm not sure of is where lookup_files() is originating from. What I'd like to see is this....

 ($file_data,$count) = lookup_files($customer,$site,'','0',$d);
 print STDERR "lookup_files originates here " . <CODE TO SHOW ME WHERE lookup_files IS DEFINED>;

Any advice on where to begin would be greatly appreciated. The webapp uses tons of use modules and instead of selectively importing only what's needed, each use seems to bring all functions in.
I know my terminology might be incorrect when referring to "method", "parent" and so on in regards to Perl. If anyone would like to correct me on it that would be appreciated too. I am at best a beginner with this stuff. Janie

Community
  • 1
  • 1
Jane Wilkie
  • 1,703
  • 3
  • 25
  • 49
  • Just a note on terminology, it seems that what you're calling a "method" is normally called a "function" (a method is a special variety of function in Perl), and it would be clearer to say "Determining where a function is defined" ("parent" usually refers to the name of the function that called a given function, not where it was defined). Good question though. – j_random_hacker Jan 15 '11 at 17:13
  • @j_random_hacker: I am appreciative for all of your advice. I re-edited a lot of the above. :-) JW – Jane Wilkie Jan 15 '11 at 17:14
  • No problem :) As a general rule, either the function will be defined in the same source file, or imported using a `use` command near the top. In the latter case, if you're lucky, it will be listed explicitly in the `use` line like `use FooModule qw(foo bar lookup_files);`, but that's just a common convention. – j_random_hacker Jan 15 '11 at 17:25
  • @Eugene: Indeed it is! Sorry everyone, and thanks for this link. JW – Jane Wilkie Jan 15 '11 at 17:48

2 Answers2

5

Take a look at the core module Devel::Peek

http://perldoc.perl.org/Devel/Peek.html#A-reference-to-a-subroutine

The output of that module's functions will tell you where a subroutine comes from

Eric Strom
  • 39,821
  • 2
  • 80
  • 152
  • Thanks for this! I'm so lucky that everyone on SO is so helpful whenever I ask a question and you have been a help on more than one occasion and for that I'm thankful. JW – Jane Wilkie Jan 15 '11 at 17:32
2

One fairly easy way is to load Carp::Always. If it’s a web app, you’ll need to put it in the code. For a command line you can just perl -MCarp::Always ...

Ashley
  • 4,307
  • 2
  • 19
  • 28