Opps, missed that. I got too anxious trying out the code. Anyways, I created my own version that includes POD counts. Thanks for your contribution, psychotic.
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
MAIN:
{
# Top directory to look through
my $dir = (@ARGV) ? shift : '.';
# Find Perl files in directory
my @files;
find sub {
my $fname = $_;
if (-f $fname) {
foreach my $type (qw(pl pm)) {
my (undef, $ext) = split (/\./, $fname);
if (defined($ext) && $ext eq $type) {
push(@files, $File::Find::name);
}
}
}
}, $dir;
if (! @files) {
print("No Perl files found in '$dir'\n");
exit(1);
}
# Header
print(" Code Cmts POD Total File\n");
print("=" x 60, "\n");
# Process files and generate totals
my ($tloc, $tcom, $ttot, $tpod) = (0,0,0,0);
foreach my $file (@files) {
my ($loc, $com, $pod) = (0,0,0);
# Slurp file
my $contents = do { local (*ARGV, $/) = [$file] and <> };
my @lines = split(/$\//, $contents);
# Process lines
while (@lines) {
my $line = shift(@lines);
# Ignore blank lines
if ($line =~ /^\s*$/) {
next;
}
# Count POD
if ($line =~ /^=[a-z]/) {
$pod++;
while (@lines) {
my $pline = shift(@lines);
if ($pline =~ /^\s*$/) {
next; # Ignore blank lines
}
$pod++;
if ($pline =~ /^=cut/) {
last; # Done with POD block
}
}
}
# Comments and code
elsif ($line =~ /^\s*\#/) {
$com++;
} else {
$loc++;
}
}
# File results
my $tot = $loc + $com + $pod;
printf("% 5d % 5d % 5d % 5d %s\n", $loc, $com, $pod, $tot, $fi
+le);
# Totals
$tloc += $loc;
$tcom += $com;
$tpod += $pod;
$ttot += $tot;
}
# Print grand totals
print("=" x 60, "\n");
printf("% 5d % 5d % 5d % 5d %s\n", $tloc, $tcom, $tpod, $ttot, '--
+ Summary of all files');
}
exit(0);
# EOF
UPDATE: Added correction suggested by psychotic.
Remember: There's always one more bug.
|