1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
# vim: ts=4 : sw=4 : et
use warnings;
use strict;
# Check for comments and POD flagged with FIX.
# Are there any modules that already does this?
# Perl::Critic::Policy::Bangs::ProhibitFlagComments doesn't consider
# POD. Make a Perl::Critic::Policy out of this?
use English qw(-no_match_vars);
use File::Find;
use FindBin;
use Test::More;
use Pod::Simple::TextContent;
if ($ENV{TEST_POD}) {
plan tests => 1;
}
else {
plan skip_all => 'set TEST_POD to enable this test'
}
my $count = 0;
find(\&fixes, "$FindBin::Bin/../lib");
is($count, 0, "Should not find any FIX comments");
sub fixes
{
my $file = $File::Find::name;
# skip SVN stuff
if ( -d and m{\.svn}) {
$File::Find::prune = 1;
return;
}
return unless -f $file;
#
# Check comments
#
open my $F, '<', $file
or warn "Couldn't open $file: $!" && return;
while (<$F>) {
if (m{#\s*FIX}) {
printf "Found a FIX comment at %s: %d\n",
$file, $.;
$count++;
}
}
close $F;
#
# Check POD
#
my $pod_parser = Pod::Simple::TextContent->new;
my $pod = "";
$pod_parser->output_string(\$pod);
$pod_parser->parse_file($file);
my $pod_count = scalar(grep {/FIX/} split /\n/, $pod);
printf "Found %d FIX(es) in POD in %s\n",
$pod_count,$file if $pod_count;
$count += $pod_count;
}
|