How can I smoke out undefined subroutines?

后端 未结 3 1350
情深已故
情深已故 2021-01-04 00:58

I want to scan a code base to identify all instances of undefined subroutines that are not presently reachable.

As an example:

use strict;
use warnin         


        
3条回答
  •  梦谈多话
    2021-01-04 01:46

    Perhaps Subroutines::ProhibitCallsToUndeclaredSubs policy from Perl::Critic can help

    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.

    This "policy" is a part of Perl::Critic::StricterSubs, which needs to be installed. There are a few more policies there. This is considered a severity 4 violation, so you can do

    perlcritic -4 script.pl
    

    and parse the output for neither declared nor explicitly imported, or use

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

    Some legitimate uses are still flagged, since it requires all subs to be imported explicitly.

    This is a static analyzer, which I think should fit your purpose.

提交回复
热议问题