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
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.