App-cpanreports
view release on metacpan or search on metacpan
lib/App/cpanreports.pm view on Meta::CPAN
man => 0,
help => 0,
VERSION => 0,
);
sub run {
my ($self) = @_;
Getopt::Long::Configure('bundling');
GetOptions(
\%option,
'version|v=s',
'distiname|d=s',
'dir|D=s',
'state|s=s',
'verbose|V+',
'man',
'help',
'VERSION!',
) or pod2usage(2);
if ( $option{'VERSION'} ) {
print "$name Version = $VERSION\n";
exit 1;
}
elsif ( $option{'man'} ) {
pod2usage( -verbose => 2 );
}
elsif ( $option{'help'} ) {
pod2usage( -verbose => 1 );
}
elsif ( !$option{version} || !$option{distname} ) {
warn <<'HELP';
The arguments --version and --distname must be specified if you are not
running from this script from the distribution's directory.
HELP
pod2usage( -verbose => 1 );
}
# do stuff here
my $mech = WWW::Mechanize->new;
my $dir = "$option{dir}/$option{version}";
my $test_reports = $self->get_report_summary($mech, $dir, $option{distname}, $option{version});
for my $report (@$test_reports) {
next if $report->{version} ne $option{version};
next if $option{state} && $report->{state} eq $option{state};
my $guid = $report->{guid};
next if glob "$dir/*.$guid";
my $file_name = "$dir/log.test-$report->{osname}.$report->{osvers}-$report->{perl}";
$mech->get("http://www.cpantesters.org/cpan/report/$guid");
my $text = $mech->content;
if ($text =~ /ccflags[^\n]+ -DDEBUGGING.+?\n/sm) {
$file_name .= 'd';
}
if ($report->{platform} !~ /thread/) {
$file_name .= "-nt";
}
# add the GUID to the file to make determining if the report has been
# previously downloaded easy.
$file_name .= ".$guid";
$text =~ s/^.*<pre>\nFrom:/From/sm;
$text =~ s{<hr class="clear-contentunit" />.*$}{}s;
decode_entities($text);
path($file_name)->spew_utf8($text);
}
return;
}
my $meta;
sub meta {
return $meta if $meta;
my $file
= -f 'MYMETA.yml' ? path('MYMETA.yml')
: -f '.build/latest/MYMETA.yml' ? path('.build/latest/MYMETA.yml')
: path('META.yml');
$meta = eval { LoadFile $file } || {};
return $meta;
}
sub get_report_summary {
my ($self, $mech, $dir, $distname, $version) = @_;
my $cache = path("$dir/$distname.yml");
$cache->parent->mkpath;
if (-f $cache) {
return Load scalar $cache->slurp_utf8;
}
my $initial = substr $distname, 0, 1;
my $url = "http://www.cpantesters.org/distro/$initial/$distname.yml";
$mech->get($url);
$cache->spew_utf8($mech->content);
my $yaml = Load $mech->content;
return $yaml;
}
1;
__END__
=head1 NAME
App::cpanreports - Download test reports for a CPAN distribution from CPAN Testers
=head1 VERSION
This documentation refers to App::cpanreports version 0.004
=head1 SYNOPSIS
( run in 0.857 second using v1.01-cache-2.11-cpan-39bf76dae61 )