" /> Status for Andrew DeFaria: April 2012 Archives

« February 2012 | Main | May 2012 »

April 11, 2012

Perl::Critic

OK, I'm a nerd and I'm pretty passionate about Perl. But in my defense this is my business and my chosen career - it is what I went to school for way back in the day. So I listen to podcasts about many topics including technology. One podcast I listen to regularly is FLOSS Weekly with Randal Schwartz. Randal wrote Learning Perl among other Perl books and he had on Jeffery Thalhammer who talked about his creation Perl::Critic. For those who may be interested the Perl::Critic episode is here.

The easiest way you can try out Perl::Critic by going to http://www.perlcritic.org/. You can even evaluate your own Perl scripts by using the Choose File and set your severity level. You can start with gentle but I usually do harsh as that's in the middle.

Perl::Critic is a static analyzer that finds inconsistencies and possible errors in your Perl code as well as tries to enforce best practices as written about in Perl Best Practices by Damian Conway. Perl::Critic is implemented as a CPAN module. There is also a command line (/usr/bin/perlcritic) that allows you to run perlcritic on your code from the command line. But the web page is better because it provides links to explanations of why Perl::Critic thinks what it complains about is a problem as well as tells you how to fix it.

Now, of course, critiquing your code is highly subjective and you may not agree with the rational for why Perl::Critic flags this as a problem. Perl::Critic is very tunable - you can set settings in ~/.perlcriticrc to say "We don't want you, Perl::Critic, to flag this as a problem".

If you use Eclipse as your IDE and have EPIC, the Eclipse Perl Integration plugin, and have Cygwin installed with perlcritic installed too, you can configure Eclipse to use Perl::Critic directly in the editor and flag errors as you code which you can then fix.

For example, you can see the little triangle with "!" in it relates to the line in the Problems tab at the bottom which says that I've defined $value but never used it.