Skip to content

Instantly share code, notes, and snippets.

@kimmel
Created June 18, 2011 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimmel/1033008 to your computer and use it in GitHub Desktop.
Save kimmel/1033008 to your computer and use it in GitHub Desktop.
A wrapper to run multiple common perlcritic code tests on a single source file. This is licensed under the "3-clause BSD license" to be as free as possible.
#!/usr/bin/perl
#-----------------------------------------------------------------------------#
# Copyright (c) 2011 Kirk Kimmel. All rights reserved.
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
# 3. The name of the AUTHOR may not be used to endorse or promote products derived from this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#-----------------------------------------------------------------------------#
use warnings;
use strict;
use diagnostics;
use Getopt::Std;
die "Usage: perltest.pl <filename>\n" if !( exists $ARGV[0] );
my %opts;
getopts( 'b', \%opts );
my $pc = 'perlcritic --verbose 8 --color ';
my $pct = 'perlcritic --verbose 8 --color --theme ';
print 'perlcritic --theme bugs ', qx{$pct bugs $ARGV[0]};
print 'perlcritic --theme complexity ', qx{$pct complexity $ARGV[0]};
print 'perlcritic --theme performance ', qx{$pct performance $ARGV[0]};
print 'perlcritic --theme portability ', qx{$pct portability $ARGV[0]};
print 'perlcritic --theme security ', qx{$pct security $ARGV[0]};
print 'perlcritic --theme tests ', qx{$pct tests $ARGV[0]};
print 'perlcritic --theme unicode ', qx{$pct unicode $ARGV[0]};
print "\nperlcritic --harsh ", qx{$pc --harsh $ARGV[0]};
print "\nperlcritic --theme pbp\n",
qx{$pct pbp --color-severity-2 MAGENTA --color-severity-1 YELLOW $ARGV[0]};
if ( defined $opts{b} ) {
print "\n\nperlcritic --brutal\n",
qx{$pc --brutal --color-severity-2 YELLOW --color-severity-1 CYAN $ARGV[0]};
}
print "\n---Report complete---\n";
exit 0;
@kimmel
Copy link
Author

kimmel commented Jun 19, 2011

This version has more perlcritic theme tests and slight clarifications made to the license.

@kimmel
Copy link
Author

kimmel commented Jul 1, 2011

I added --verbose 8 to change the perlcritic output. Before it would output page numbers of PBP. Now it outputs the Chapter title and the rule in question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment