Perl shallow syntax check? ie. do not check syntax of imports

前端 未结 5 2262
一个人的身影
一个人的身影 2021-02-15 14:38

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

5条回答
  •  悲&欢浪女
    2021-02-15 15:14

    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.

提交回复
热议问题