Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to find the function definition in a perl codebase

Tags:

perl

I am rummaging through 7900+ lines of perl code. I needed to change a few things and things were going quite well even though i am just 36 hours into perl. I learned the basic constructs of the language and was able to get small things done. But then suddenly I have found a function call which does not have any definition anywhere. I grep'ed several times to check for all 'sub'. I could not find the functions definition. What am I missing ? Where is the definition of this function. I am quite sure this is a user defined function and not a library function(from its name i guessed this). Please help me find this function's definition.

Here is a few lines from around the function usage.

(cfg_machine_isActive($ep)) {
         staf_var_set($ep, VAR_PHASE, PHASE_PREP);
         staf_var_set($ep, VAR_PREP,  STATE_RUNNING);
      } else {
         cfg_machine_set_state($ep, STATE_FAILED);
      }
   }
   $rc = rvt_deploy_library();       #this is the function that is the problem 
   dump_states() unless ($rc != 0);

Here is the answer:

(i could not post this an answer itself cos i dont have enough reputation)

I found that the fastest way to find the definition of an imported function in perl are the following commands:

>perl.exe -d <filename>.pl

This starts the debugger. Then; do

b <name of the function/subroutine who's definition you are looking for>

in our case that would mean entering:

b rvt_deploy_library

next press 'c' to jump to the mentioned function/subroutine.

This brings the debugger to the required function. Now, you can see the line no. and location of the function/subroutine on the console.

main::rvt_deploy_library(D:/CAT/rvt/lib/rvt.pm:60): 
like image 258
Chani Avatar asked Dec 05 '22 19:12

Chani


1 Answers

There are a number of ways to declare a method in Perl. Here is an almost certainly incomplete list:

  1. The standard way, eg. sub NAME { ... }
  2. Using MooseX::Method::Signatures, method NAME (...) {...}
  3. Assignment to a typeglob, eg. *NAME = sub {...};

In addition, if the package declares an AUTOLOAD function, then there may be no explicit definition of the method. See perlsub for more information.

like image 83
a'r Avatar answered Feb 24 '23 16:02

a'r