无法在 perl 代码库中找到函数定义 [英] unable to find the function definition in a perl codebase

查看:57
本文介绍了无法在 perl 代码库中找到函数定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在翻阅 7900 多行 perl 代码.我需要改变一些东西,即使我只学习了 36 个小时的 perl,事情也进展得很顺利.我学习了该语言的基本结构,并且能够完成一些小事.但是突然间我发现了一个在任何地方都没有任何定义的函数调用.我多次使用 grep 来检查所有子".我找不到函数定义.我错过了什么?这个函数的定义在哪里.我很确定这是一个用户定义的函数而不是一个库函数(从它的名字我猜到了这个).请帮我找到这个函数的定义.

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);

答案如下:

(我不能发布这个答案,因为我没有足够的声誉)

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

我发现在 perl 中查找导入函数定义的最快方法是以下命令:

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

接下来按c"跳转到提到的函数/子程序.

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): 

推荐答案

在 Perl 中有多种声明方法的方法.这是一个几乎可以肯定不完整的列表:

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

  1. 标准方式,例如.sub NAME { ... }
  2. 使用 MooseX::Method::Signatures, method NAME (...) {...}
  3. 赋值给一个 typeglob,例如.*NAME = sub {...};

另外,如果包声明了一个AUTOLOAD函数,那么可能没有对该方法的显式定义.有关详细信息,请参阅 perlsub.

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

这篇关于无法在 perl 代码库中找到函数定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆