Perl::Critic is a lint-like tool for Perl. It uses static analysis (it does not run your code) and provides a list of places where the code violates one of the policy rules. Originally based on the book Perl Best Practices written by Damian Conway, the module is extendable and customizable. You, or your team can set up your own standard, and use Perl::Critic to enforce it.

The Perl::Critic module comes with a command line tool called perlcritic, but you can also integrate the use of Perl::Critic in your unit-tests via the Test::Perl::Critic wrapper.

As an example, let's see the results of the default, the most gentle level of criticism of a script I saw recently. Let's also add some commentary.

Code before strictures are enabled

$ perlcritic example.pl Bareword file handle opened at line 1, column 1. See pages 202,204 of PBP. (Severity: 5) Two-argument "open" used at line 1, column 1. See page 207 of PBP. (Severity: 5) Code before strictures are enabled at line 1, column 1. See page 429 of PBP. (Severity: 5)

This report was given for the following code:

open FH, $filename or die;

Let's start with the third entry. It complains about that fact that there is no use strict;. As I recommend, one should always use strict!