Subject: | Perl-Metrics command-line program |
This module should include a simple command-line program to conveniently report metrics on .pm files. Here's a preliminary version that lacks proper @ARGV parsing, error checking and POD. If this is interesting to you, I would be happy to finish this and resubmit.
#!/usr/bin/perl -w
use strict;
use PPI;
use Perl::Metric::Basic;
use Data::Dumper;
for my $filename (@ARGV) {
my $document = PPI::Document->new($filename);
my $metric = Perl::Metric::Basic->new->measure($document);
my %totals;
for my $pkg (values %$metric) {
for my $fn (values %$pkg) {
for my $metricname (keys %$fn) {
$totals{$metricname} ||= 0;
$totals{$metricname} += $fn->{$metricname};
}
}
}
print "$filename\n" if (@ARGV > 1);
for my $metricname (sort keys %totals) {
printf " %-16s %4d\n", $metricname, $totals{$metricname};
}
}