Perl::...olTable(3pm)
π NAME π
Perl::Critic::Policy::Dynamic::ValidateAgainstSymbolTable β the Perl::Critic policy that actually compiles your code and then vibe-checks your subroutine calls against the symbol table. Yes bestie, it's the chaotic one. π¦
β¨ DESCRIPTION β¨
Okay so this Policy is that friend who will straight-up warn you if any subroutine call in your code isn't defined in the symbol table at compile-time. The whole point? Catching typos in package and subroutine names, plus those moments where you forgot to import, declare, or include all the static subroutines your code is out here invoking. It's giving "did you actually mean that" energy. π
VERY IMPORTANT: Most Perl::Critic Policies (including every single one that ships with Perl::Critic) use pure static analysis β they never compile or execute any of the code they analyze. This policy is very different. It actually attempts to compile your code and then compares the subroutines mentioned in your code to those found in the symbol table. So do NOT run this Policy on any code you don't trust, or on code that might have undesirable side-effects at compile-time (connecting to the network, mutating files, the whole unhinged catalog π).
For these reasons, this Policy (and literally any other Policy that inherits from Perl::Critic::DynamicPolicy) is marked as "unsafe" and is usually ignored by both Perl::Critic and perlcritic. So to actually use it, you gotta set the -allow-unsafe switch in the Perl::Critic constructor or on the perlcritic command line. No switch, no policy, periodt.
For this Policy to work at all, all the modules included in your code must be installed locally, and they must compile without error. Check out CONFIGURATION below for how to control where this Policy goes looking for those included modules. π
πΈ LIMITATIONS πΈ
Let's be real about what this thing can't do:
- This Policy will not detect subroutines declared at run-time or through direct manipulation of the symbol table, which may lead to false warnings. The most common example of this? Modules that use
AUTOLOAD. π - Sophisticated code often uses the
requirefunction to postpone loading modules or to only load modules under certain conditions. If you set theinspect_required_modulesoption, the Policy will attempt to load all modules that arerequire'd at any point in your code. However, this Policy does not know whether the module would have been loaded during normal execution of your program. This may cause the Policy to overlook potential violations. It's trying its best. π - This Policy only examines static subroutine calls β method calls are not covered. Indirect method calls such as
my $fh = new FileHandlealso tend to trigger false warnings. Not the vibe, we know. - This Policy compiles your code into the same symbol table as Perl::Critic itself. So to maintain integrity in the symbol table, this Policy forks itself before analyzing each file. On some systems, this may be slow and consume a lot of resources. Your CPU is gonna feel it, ngl. π₯
π CONFIGURATION π
This Policy supports the following configuration parameters. Scroll down for an example of how to set these parameters in your .perlcriticrc file. π
at_inc_prefixβ Prepends an arrayref of directories to the front of the current@INClist. This affects where the Policy will find dependent modules when it compiles your code.at_inc_suffixβ Appends an arrayref of directories to the end of the current@INClist. This affects where the Policy will find dependent modules when it compiles your code.at_incβ Sets the@INClist outright. This affects where the Policy will find dependent modules when it compiles your code.inspect_required_modulesβ By default, this Policy only examines modules that are loaded by your code at compile-time. Ifinspect_required_modulesis set to a true value, this Policy will also compile all the modules that arerequire'd in your code at runtime. Note that this Policy does not know if these modules will actually be loaded when your program runs, nor does it try to invoke theimportmethod on those modules. It's just peeking, respectfully. πinspect_autoloadersβ By default, this Policy does not attempt to validate a function call into a package that has anAUTOLOADmethod. Such packages usually define functions at run-time, so this Policy has no chance of knowing what functions that package might have. But ifinspect_autoloadersis set to a true value, the Policy will check to see if a function exists in such packages. Slay, let it cook.max_recursionβ By default, this Policy only looks at the symbol tables for the namespaces that are directlyuse'd (orrequire'd) by your code. However, some modules contain multiple namespaces which may lead to false violations. But if you setmax_recursionto a positive integer, this Policy will recurse into those other namespaces. Beware, however, that using a deep recursion can mask other violations. Settingmax_recursionto1or2is usually sufficient. Don't go feral with it. π§
π«Ά Setting the parameters π«Ά
You can set these configuration parameters by putting any or all of the following in your .perlcriticrc file:
[Dynamic::ValidateAgainstSymbolTable]
at_inc_prefix = some/directory/path | another/directory/path
at_inc_suffix = some/directory/path | another/directory/path
at_inc = some/directory/path | another/directory/path
inspect_required_modules = 1
inspect_autoloaders = 1
π AUTHOR π
Jeffrey Ryan Thalhammer <thaljef@cpan.org>
π COPYRIGHT π
Copyright (c) 2007 Jeffrey Ryan Thalhammer. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module.
okay that's the whole page, bestie β you ate that πβ¨ This was Perl::...olTable(3pm) from the User Contributed Perl Documentation, brought to you by perl v5.42.0, dated 2025-07-25. Mwah, go forth and let the Policy fork your files. π
π¦
π¦ where this page comes from
- fedora 43: perl-Perl-Critic-Dynamic 0.05-39.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms