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

前端 未结 5 2268
一个人的身影
一个人的身影 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 14:50

    There are two problems with this:

    1. How to not fail -c if the required modules are missing?

      There are two solutions:

      A. Add a fake/stub module in production

      B. In all your modules, use a special catch-all @INC subroutine entry (using subs in @INC is explained here). This obviously has a problem of having the module NOT fail in real production runtime if the libraries are missing - DoublePlusNotGood in my book.

    2. Even if you could somehow skip failing on missing modules, you would STILL fail on any use of the identifiers imported from the missing module or used explicitly from that module's namespace.

      The only realistic solution to this is to go back to #1a and use a fake stub module, but this time one that has a declared and (as needed) exported identifier for every public interface. E.g. do-nothing subs or dummy variables.

      However, even that will fail for some advanced modules that dynamically determine what to create in their own namespace and what to export in runtime (and the caller code could dynamically determine which subs to call - heck, sometimes which modules to import).

      But this approach would work just fine for normal "Java/C-like" OO or procedural code that only calls statically named predefined public subs, methods and accesses exported variables.

提交回复
热议问题