So, I am giving some thought to this,... but in the meantime I thought it would be interesting to see just some very basic raw download counts. In particular to see raw download counts on my own modules. (After all, CPAN doesn't automatically give this type of info and its not everyday you get access to nicely cleaned up logs like this) So I whipped this up, just grep the raw log for a PAUSE id and pipe the output into this script (passing in 'module' or 'distro' or nothing for both).
#!/usr/bin/perl
use strict;
use warnings;
my ($by_module, $by_distro);
($by_module, $by_distro) = (1, 1) unless @ARGV;
while (my $arg = shift(@ARGV)) {
$by_module = 1 if lc($arg) =~ 'module';
$by_distro = 1 if lc($arg) =~ 'distro';
}
my %total_downloads_by_module;
my %total_downloads_by_distro;
while (<>) {
my ($url) = /\d{5}\s(.*)/;
my @path = split /\// => $url;
my $module_distro = pop @path;
$total_downloads_by_distro{$module_distro}++ if $by_distro;
if ($by_module) {
my ($module) = ($module_distro =~ /(.*?)\-\d\..*?.tar\.gz/);
$total_downloads_by_module{$module}++;
}
}
format_report("Total Downloads by Module", %total_downloads_by_module)
+ if $by_module;
format_report("Total Downloads by Distro", %total_downloads_by_distro)
+ if $by_distro;
sub format_report {
my ($header, %hash) = @_;
print "+---------------------------------------\n";
print "| $header\n";
print "+------+--------------------------------\n";
print join "\n" =>
map { "| " . sprintf("%4d", $hash{$_}) . " | " . $_ }
sort { $hash{$a} <=> $hash{$b} }
keys %hash;
print "\n+------+--------------------------------\n";
}
BTW - The reg-exp for extracting the module name is horrible and could use a lot of help (*hint* *hint*).