CPAN Module Review: Test::Perl::Critic

by chromatic

If you really want to make something a habit, find a way to do it without thinking about it. I like to automate the things I value so I never do them incorrectly, incompletely, or infrequently. Thus Test::Perl::Critic allows you to add customizable Perl::Critic tests to your test suites, so you can ensure that you've followed local style.


Andy Lester
2006-09-29 20:42:05
I would also like to point to the many Perl::Critic add-on modules, where dozens of CPAN authors have created their own sets of policies, using the flexible Perl::Critic framework.

Actually, there's only one author that's done it, but they're some fine, fine policies, if I do say so myself. I point you to Perl::Critic::Bangs (, with policies for vague variable names, commented-out code, and use of the dreaded no_plan in tests.

2006-09-30 11:50:57
I looked at the Perl::Critic doco and it shows right there how to put the severity level in the perlcriticrc:

severity = 1
arg1 = value1
arg2 = value2



2006-09-30 11:55:26
Bob, that changes only the severity for that specific policy, not the default severity level of the report. I wanted the latter.
Jeff Thalhammer
2006-09-30 21:32:03
Great article! Note that level 5 is the highest severity, not the lowest. So by default, Perl::Critic only reports the most egregious errors.

use Test::Perl::Critic (-severity => $x);

As you pointed out, this is the intended mechanism for setting the reporing threshold. I can see the virtue of setting this in the .perlcriticrc file. We'll consider that for a future release.

Chris Laco
2006-10-04 08:39:25
I took the 'default-all-on' approach then changed thing I didn't agree with in my rc. That way, when new policies come out, they're automatically run, and I must make decisions on whether I agree or disagree with them. This seemed safer than tweaking the levels of all of the policies in the rc.

-profile => 't/style_perl_critic.rc',
-severity => 1,
-format => "%m at line %l, column %c: %p Severity %s\n\t%r"

Michael R. Wolf
2006-10-08 21:49:10
Did you consider putting a "no critic" and "use critic" comment-directives around the offending lines to indicate a conscious non-compliance? That seems to make perlcritic do what you want, but it seems to be distributing perlcritc pieces when you have decided not to.
2006-10-16 11:02:44
Michael, that's a good suggestion. I considered it, but in this case I prefer to leave that information outside the source code. If there were a competing suite of tools, it could be confusing to have multiple analyzer directives in the code.