Perl浅层语法检查? IE.不检查导入的语法 [英] Perl shallow syntax check? ie. do not check syntax of imports
问题描述
如何对perl文件执行浅"语法检查.标准perl -c
是有用的,但是它检查导入的语法.当您在代码存储库中工作并推送到运行的环境并且您在存储库中定义了一个函数但尚未推送到运行的环境时,这有时很好,但不是很好.由于导入会引用系统路径(例如,使用Custom :: Project :: Lib qw(foo bar baz)),因此无法检查功能.
How can I perform a "shallow" syntax check on perl files. The standard perl -c
is useful but it checks the syntax of imports. This is sometimes nice but not great when you work in a code repository and push to a running environment and you have a function defined in the repository but not yet pushed to the running environment. It fails checking a function because the imports reference system paths (ie. use Custom::Project::Lib qw(foo bar baz)).
推荐答案
实际上无法完成,因为导入具有影响后续代码解析的能力.例如,use strict
使其不会将裸词解析为字符串(并更改了如何使用变量名的规则),use constant
导致定义了常量子,而use Try::Tiny
更改了涉及以下内容的表达式的解析try
,catch
或finally
(通过为它们提供&
原型).更一般而言,任何将任何内容导出到调用者名称空间的模块都可能影响解析,因为当名称引用现有子例程时,与未引用现有子例程时,perl解析器以不同的方式解决歧义.
It can't practically be done, because imports have the ability to influence the parsing of the code that follows. For example use strict
makes it so that barewords aren't parsed as strings (and changes the rules for how variable names can be used), use constant
causes constant subs to be defined, and use Try::Tiny
changes the parse of expressions involving try
, catch
, or finally
(by giving them &
prototypes). More generally, any module that exports anything into the caller's namespace can influence parsing because the perl parser resolves ambiguity in different ways when a name refers to an existing subroutine than when it doesn't.
这篇关于Perl浅层语法检查? IE.不检查导入的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!