YA Perl Advent Calendar 2005-12-19

I apologize, today's module is a little late out the door. It's also a little light on details because well, it'd take forever and a day to test it thoroughly. And while it might have a dozen or so dependencies–I heartily recommend you use CPAN or CPANPLUS–you probably either have a lot of them already or will need them in the future including: Storable, Test::More, and Scalar-List-Util. The module in question is Test::Perl::Critic.

If you're (un)lucky enough to have a a sadistic project manager who insists on strict coding practices, or you're just a masochist^uMr. Conway recently wrote a little book you may have heard of about writing cleaner line-noise. About the same time two other guys released a book about testing your code for everything up to and including halting. Now you too can say "Hey! You got your trout in my peanut butter!" Yes indeed, you can now automate checking your compliance with established best practices. Test::Perl::Critic lets you add a set of tests for various things from the innocuous ProhibitBuiltinHomonyms (no subs with the same name as CORE functions) to the obnoxious ProhibitUnlessBlocks. Of course it's infinitely configurable, extensible yadda yadda yadda. And yes, the author does in a bout of circular dependency, eat his hown dog food; the engine Perl::Critic contains and passes a Test::Perl::Critic test.

Just for fun, here's the output with the default policies against a very simple and very incomplete module I started last Thanksgiving. A link to the code follows. . o O ( I wonder if "Jeffrey Ryan Thalhammer" is a pseudonym for "Damian Conway", he sure pimps the book like an author ;-)

not ok 1 - blib/lib/Acme/English.pm
#     Failed test (/usr/lib/perl5/site_perl/5.8.0/Test/Perl/Critic.pm at line 83)
# 
# Perl::Critic found these violations in 'blib/lib/Acme/English.pm':
#       Code before warnings are enabled at line 6, column 1. See page 431 of PBP
#       Package variable declared or used at line 4, column 1. See pages 73,75 of PBP
#       List declaration without trailing comma at line 32, column 12. See page 17 of PBP
#       Quotes used with a noisy string at line 12, column 5. See page 53 of PBP
#       Quotes used with a noisy string at line 13, column 5. See page 53 of PBP
#       Quotes used with a noisy string at line 14, column 5. See page 53 of PBP
#       Useless interpolation of literal string at line 14, column 5. See page 51 of PBP
#       Quotes used with a noisy string at line 15, column 5. See page 53 of PBP
#       Quotes used with a noisy string at line 16, column 5. See page 53 of PBP
#       String *may* require interpolation at line 16, column 5. See page 51 of PBP
#       Quotes used with a noisy string at line 17, column 5. See page 53 of PBP
#       Quotes used with a noisy string at line 18, column 5. See page 53 of PBP
#       Quotes used with a noisy string at line 19, column 5. See page 53 of PBP
#       String *may* require interpolation at line 19, column 5. See page 51 of PBP
#       Quotes used with a noisy string at line 20, column 5. See page 53 of PBP
#       Quotes used with a noisy string at line 22, column 5. See page 53 of PBP
#       Quotes used with a noisy string at line 23, column 5. See page 53 of PBP
#       Quotes used with a noisy string at line 26, column 5. See page 53 of PBP
#       Quotes used with a noisy string at line 27, column 5. See page 53 of PBP
#       Quotes used with a noisy string at line 28, column 5. See page 53 of PBP
#       Useless interpolation of literal string at line 28, column 5. See page 51 of PBP
#       Quotes used with a noisy string at line 31, column 5. See page 53 of PBP
#       Quotes used with a noisy string at line 32, column 5. See page 53 of PBP
#       Builtin function called with parens at line 35, column 10. See page 13 of PBP
#       Builtin function called with parens at line 37, column 10. See page 13 of PBP
#       Quotes used with an empty string at line 37, column 16. See page 53 of PBP
#       Builtin function called with parens at line 38, column 11. See page 13 of PBP
#       Useless interpolation of literal string at line 38, column 45. See page 51 of PBP
#       Quotes used with an empty string at line 38, column 45. See page 53 of PBP
# Looks like you failed 1 tests of 1.
make: *** [test_dynamic] Error 1

mod19.pl




NAME

Acme::English - remove unsightly punctuation


SYNOPSIS

  use Acme::English;


DESCRIPTION

Inspired by this lovely poem:

  A poem:
  <>!*''#              waka waka bang splat tick tick hash
  ^@`$$-               carat at back-tick dollar dollar dash
  *!'$_                splat bang tick dollar underscore
  %*<>#4               percent splat waka waka number four
  &)../                ampersand right-paren dot dot slash
  {~|**SYSTEM HALTED   curly bracket tilde pipe splat splat crash

by Fred Bremmer and Steve Kroese

:pretentious Octothorpe

:jargon star hat bar twiddle


BUGS

I cheated in the default definitions of some of the characters. Waka = < and Wakka = > (more k's, get it? ;-) CurLyBracket (I call them CurlyBraces) is the { and CuRlyBracket is }.


AUTHOR

Jerrad Pierce <jpierce@cpan>


SEE ALSO

Acme::English, the ASCII jargon entry


   1 package Acme::English;
   2 
   3 use strict;
   4 use vars qw($VERSION);
   5 
   6 $VERSION = '1.00';
   7 
   8 #Sesquipedalian / oglethorpe
   9 my %chr = (
  10 	   '<' => 'Waka',
  11 	   '>' => 'Wakka',
  12 	   '!' => 'Bang',
  13 	   '*' => 'Splat',
  14 	   "'" => 'Tick',
  15 	   '^' => 'Carat',
  16 	   '@' => 'At',
  17 	   '`' => 'BackTick',
  18 	   '#' => 'Hash', #XXX Number!
  19 	   '$' => 'Dollar',
  20 	   '-' => 'Dash',
  21 	   '_' => 'Underscore',
  22 	   '%' => 'Percent',
  23 	   '&' => 'Ampersand',
  24 	   ')' => 'RightParen',
  25 	   '(' => 'LeftParen',
  26 	   '.' => 'Dot',
  27 	   '/' => 'Slash',
  28 	   "\\"=> 'BackSlash',
  29 	   '{' => 'CurLyBracket', #Right?!! Brace?!
  30 	   '}' => 'CuRlyBracket', #Right?!! Brace?!
  31 	   '~' => 'Tilde',
  32 	   '|' => 'Pipe'
  33 );
  34 #print <DATA>;
  35 my $in = join("\n", (<DATA>));
  36 
  37 foreach (split('', $in) ){
  38     print exists($chr{$_}) ? $chr{$_} : $_, " ";
  39 }
  40 
  41 # Preloaded methods go here.
  42 
  43 # Autoload methods go after =cut, and are processed by the autosplit program.
  44 
  45 1;
  46 __DATA__
  47 
  48 __END__
  49 # Below is the stub of documentation for your module. You better edit it!
  50