find-undeclared-subs.pl - find places in perl code where undeclared symbols



NAME

find-undeclared-subs.pl - find places in perl code where undeclared symbols are used


SYNOPSIS

find-undeclared-subs.pl-t types-of-symbols-to-check ]
-P perl-backend-command ] file ...


DESCRIPTION

This script lists all undeclared subs used in the perl source files passed on commandline. The use of this script gives more than plain placing of 'use strict' in your source since in case of 'use strict' the use of undeclared subroutines is detected only at runtime when perl has to execute them (i.e. if execution path reached the invokation of the undeclared sub). In contrast this script examines all execution paths and reports all locations the undeclared subroutines are used.

It does not check the modules that the analyzed file requires if the modules are located not in the subdirectories of the directory where the analyzed file is located.


OPTIONS

-t types-of-symbols-to-check
Specify use of what types of undeclared symbols you wish to list. The types-of-symbols-to-check is a string of symbol prefixes you wish to list, listed in any order without any space between them. Here is a correspondence between symbol prefixes and types of symbols:
&
Subroutine

$
Scalar variable

@
List variable

%
Hash variable

  • Symbol table entry

  • The default value of this argument is & - i.e. the locations of the use of undeclared subroutines is listed.

    -P perl-backend-command
    Specify the invokaction string for the backend. It does not need to specify the full path of the perl program. This option is intended for passing any additional options mostly used for specifying the location of modules your program requires. The passed string is prepended to the necessary options used for functionality of this script. The default value of this option is perl.


    NOTES

    It can list give false alarms for symbols that are not subroutines (this is a feature of the B::Xref module used as a backend). So it is only practical to check only the places with the use of undeclared subroutines (that's the default mode if you don't pass any -t options). Use the 'use strict' in your source for detecting use of undeclared objects of types other than subroutines.


    EXAMPLES

    The following commandline should list all locations where undeclared hashes and subroutines are used in files file1.pl and file2.pl, instructing to search for modules in the parent directory:

     find-undeclared-subs.pl -t '%&' -P 'perl -I..' file1.pl file2.pl