Perl Advent Calendar 2006-12-23

Happy Holidays You Bastard

by Jerrad Pierce

Last year we looked at Test::Perl::Critic, today we present an alternate and potentially more convenient means of interacting with Perl::Critic to enforce adherence to best practices: criticism. criticism is a pragma with specifiable levels of severity which will invoke Perl::Critic upon each execution of your code, even insisting that strict be enabled. Of course all of these tests exact a performance penalty that would be unacceptable in production. Luckily, the module handles this cleverly, allowing the same code to be used in development and production without modification. If Perl::Critic is not available loading criticism is essentially a no-op.

$ perl mod23.pl
RCS keywords $Id$ not found at a line 1
RCS keywords $Revision$, $HeadURL$, $Date$ not found at a line 1
RCS keywords $Revision$, $Source$, $Date$ not found at a line 1
No "VERSION" variable found at a line 1
Code not contained in explicit package at a line 1
Code not contained in explicit package at a line 2
Code not contained in explicit package at a line 3
Code not contained in explicit package at a line 5
Double-sigil dereference at a line 6
Module does not end with "1;" at a line 6
Code not contained in explicit package at a line 6

Note, however, that there appears to be an undocumented dependency in v.04 In my testing, the brutal criticisms above are not issued if warnings are also not enabled. This does not appear to affect any other levels of severity, each of which emits fewer messages through to 'gentle' which does not balk at the code at all.

mod23.pl


   1 use criticism 'brutal';
   2 use strict;
   3 use warnings;
   4 
   5 $a = sub{ };
   6 &$a;