加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl – 如何抽出未定义的子程序?

发布时间:2020-12-15 21:14:50 所属栏目:大数据 来源:网络整理
导读:我想扫描一个代码库来识别当前不可达的未定义子例程的所有实例. 举个例子: use strict;use warnings;my $flag = 0;if ( $flag ) { undefined_sub();} 意见 当$flag评估为true时,将发出以下警告: Undefined subroutine main::undefined_sub called at - lin
我想扫描一个代码库来识别当前不可达的未定义子例程的所有实例.

举个例子:

use strict;
use warnings;

my $flag = 0;
if ( $flag ) {
  undefined_sub();
}

意见

>当$flag评估为true时,将发出以下警告:

Undefined subroutine &main::undefined_sub called at - line 6

我不想依赖在运行时发出的警告来识别未定义的子例程
>严格的和警告的pragmas在这里没有帮助.使用严格的’subs’没有任何效果.
>即使以下代码片断也是沉默的

$perl -Mstrict -we 'exit 0; undefined_sub()'

解决方法

也许从 Perl::Critic Subroutines::ProhibitCallsToUndeclaredSubs政策可以帮助

This Policy checks that every unqualified subroutine call has a matching subroutine declaration in the current file,or that it explicitly appears in the import list for one of the included modules.

这个“政策”是Perl::Critic::StricterSubs的一部分,需要安装.那里还有一些政策.这被认为是严重性4违反,所以你可以做

perlcritic -4 script.pl

并解析既不声明也不明确导入或使用的输出

perlcritic -4 --single-policy ProhibitCallsToUndeclaredSubs script.pl

一些合法用途仍然被标记,因为它需要明确导入所有的子.

这是一个静态分析仪,我认为应该符合您的目的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读