Skip navigation

Tag Archives: using Perl::Critic

Downloading the Perl::Critic from work which I uploaded at home this morning. It’s a different feeling than downloading from private ‘net storage; it’s just a transfer mechanism in that case. But using the CPAN to get your own open-source code is just… interesting feeling.

I added the metadata functionality to Perl::Critic that allows this sort of thing a while back and now some one is finally using it. Woohoo!

I’m quite chuffed.

Perl::Critic 1.094 is on its way to a CPAN mirror near you. There are a number of changes in it, but there’s one in particular that I want to point out. A new policy called Miscellanea::ProhibitUselessNoCritic.

Adam Kennedy wrote a journal entry where he mentioned “the expense of having to maintain [## no critic] entries permanently”. This inspired the creation of the new policy.

One of the problems with Perl::Critic is that you may, over time, end up with policy disabling comments scattered across your code that no longer apply, making the code harder to understand. This policy will complain about any ## no critic that doesn’t actually disable any policies. You then know that you can remove those comments, making your code cleaner and congratulating yourself for solving whatever issue that caused you to put it there in the first place.

This post originally appeared at

I was planning on coming into the office early this morning, but just before I was going to leave, I read Spolsky’s post and in under a minute found a Perl::Critic related question I felt needed a good answer.

Dang, writing good answers takes time.

For me, it’s --single-policy.

Generally, Perl::Critic is being used indirectly via a test using Test::P::C or Test::P::C::Progressive, with a perlcriticrc file that is in the distribution’s t/ directory.

The most common reason I have for running perlcritic is when there’s a Test::P::C::Progressive failure. In that case, I’m looking for violations of an individual policy to fix to get the violation count down.

--single-policy overrides all other selection criteria for policies. Its value, like the ones for the --include and --exclude options, is used as a regex applied against policy names with the /i, /m, and /x options applied to it. So, for example, if I want to scan for violations of Modules::RequireNoMatchVarsWithUseEnglish in the current directory, I can simply say

perlcritic --single-policy english .

When cleaning up a body of code, I find it easier to fix one kind of problem at a time in a bunch of files, rather than fixing all kinds of problems a single file at a time.

This post originally appeared at