Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

CPAN Testers command-line viewer

by tobyink (Abbot)
on Jun 27, 2012 at 09:54 UTC ( #978606=CUFP: print w/ replies, xml ) Need Help??

This script acts as a handy interface to the CPAN testers service, allowing you to quickly check pass/fail rates for a particular release.

It fetches YAMLJSON and performs HTTP caching, so probably puts less stress on the CPAN testers servers than a hit from a browser.

Usage:
	cpan-testers Example-Distribution
	cpan-testers -v0.001 Example-Distribution
	cpan-testers -ov0.001 Example-Distribution
	cpan-testers -s Example-Distribution

Options:
	--version=V, -vV   Show results for particular release version.
	--os, -o           Break down by operating system.
	--summary, -s      Show summary for all versions
	                   (excludes "--version" and "--os" options).
	--stable, -S       Hide dev versions (excludes "--version").

Requires:

#!/usr/bin/env perl use 5.010; use strict; use utf8; { package App::CpanTesters; use Any::Moose 0; use File::Path 0 qw< make_path >; use File::Spec 0 qw< >; use Getopt::Long 0 qw< GetOptionsFromArray :config permute bundling no_ignore_case no_auto_abbrev >; use JSON 0 qw< from_json >; use LWP::Simple 0 qw< mirror is_success >; use List::Util 0 qw< maxstr >; use PerlX::Maybe 0 qw< maybe >; sub show_help { my $exit_status = shift || 0; print <<"HELP"; Usage: $0 Example-Distribution $0 -v0.001 Example-Distribution $0 -ov0.001 Example-Distribution $0 -s Example-Distribution Options: --version=V, -vV Show results for particular release version. --os, -o Break down by operating system. --summary, -s Show summary for all versions (excludes "--version" and "--os" options). --stable, -S Hide dev versions (excludes "--version"). HELP exit($exit_status); } use namespace::clean; has cache_dir => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build_cache_dir', ); has distro => ( is => 'ro', isa => 'Str', required => 1, ); has results => ( is => 'ro', isa => 'ArrayRef', lazy => 1, builder => '_build_results', ); has version => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_build_version', ); has os_data => ( is => 'ro', isa => 'Bool', default => 0, ); has stable => ( is => 'ro', isa => 'Bool', default => 0, ); sub run { my ($class, @argv) = @_; my ($version, $summary, $os_data, $stable) = (undef, 0, 0, 0); GetOptionsFromArray( \@argv, 'version|v=s' => \$version, 'summary|s' => \$summary, 'os|o' => \$os_data, 'stable|S' => \$stable, 'help|usage|h' => \&show_help, ); show_help(1) if $summary && ($os_data or length $version); show_help(1) if $stable && length $version; my $distro = shift @argv or show_help(1); $distro =~ s{::}{-}g; my $self = $class->new( distro => $distro, os_data => !!$os_data, stable => !!$stable, maybe version => $version, ); if ($summary) { exit ! print $self->summary_report; } exit ! print $self->version_report; } sub version_data { my ($self) = @_; my %data; foreach (@{$self->results}) { next unless $_->{version} eq $self->version; my ($pv) = ($_->{perl} =~ /^5\.(\d+)/) or next; next if $pv ~~ [9, 11, 13, 15]; my $key = $self->os_data ? sprintf("Perl 5.%03d, %s", $pv, $_->{ostext}) : sprintf("Perl 5.%03d", $pv); my $num = { PASS => 0, FAIL => 1 }->{$_->{status}} // 2; $data{$key}[$num]++; } return \%data; } sub summary_data { my ($self) = @_; my %data; foreach (@{$self->results}) { my $key = $_->{version}; my $num = { PASS => 0, FAIL => 1 }->{$_->{status}} // 2; $data{$key}[$num]++; } return \%data; } sub format_report { my ($self, $title, $data) = @_; no warnings; join "\n" => ( $title, q(), sprintf("%-32s%6s%6s%6s", q(), qw(PASS FAIL ETC)), ( map { sprintf "%-32s% 6d% 6d% 6d", $_, @{$data->{$_}} +} sort keys %$data ), q(), ); } sub version_report { my ($self) = @_; $self->format_report( sprintf("CPAN Testers results for %s version %s", $self->d +istro, $self->version), $self->version_data, ); } sub summary_report { my ($self, $os_data) = @_; $self->format_report( sprintf("CPAN Testers results for %s", $self->distro), $self->summary_data, ); } sub _build_version { maxstr map { $_->{version} } @{ shift->results } } sub _build_results { my $self = shift; my $results_uri = sprintf( 'http://www.cpantesters.org/distro/%s/%s.json', substr($self->distro, 0, 1), $self->distro, ); my $results_file = File::Spec->catfile( $self->cache_dir, sprintf('%s.json', $self->distro), ); is_success mirror($results_uri => $results_file) or do { unlink $results_file; die "Failed to retrieve URI $results_uri\n"; }; my $results = from_json do { open my $fh, '<', $results_file or die "Could not open $results_file: $!"; local $/ = <$fh>; }; die "Unexpected non-ARRAY content from $results_uri\n" unless ref $results eq 'ARRAY'; $self->stable ? [ grep { $_->{version} !~ /_/ } @$results ] : $results; } sub _build_cache_dir { my $dir = File::Spec->catdir( File::Spec->tmpdir, 'CpanTesters', ); make_path $dir unless -d $dir; return $dir; } } App::CpanTesters->run(@ARGV) unless scalar caller(0);

Update: switched from retrieving YAML to retrieving JSON. The YAML files seem a bit smaller, but JSON parsing seems more reliable, and the JSON files served by the CPAN Testers site seem to have more cache-friendly headers.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Comment on CPAN Testers command-line viewer
Download Code
Re: CPAN Testers command-line viewer
by toolic (Chancellor) on Jun 27, 2012 at 12:43 UTC
    I can't get this to work for me:
    $ cpan-testers List-MoreUtils Undefined subroutine &YAML::XS::LoadFile called at /home/toolic/perl/l +ib/YAML/Any.pm line 93. $ cpan-testers List-MoreUtils-0.33 Undefined subroutine &YAML::XS::LoadFile called at /home/toolic/perl/l +ib/YAML/Any.pm line 93. $ cpan-testers List::MoreUtils Undefined subroutine &YAML::XS::LoadFile called at /home/toolic/perl/l +ib/YAML/Any.pm line 93.
    Am I using it incorrectly?
    $ perl -v This is perl 5, version 12, subversion 2 (v5.12.2) built for x86_64-li +nux

      Me neither:

      $ perl cpan_testers.pl DBI YAML Error: Stream does not end with newline character Code: YAML_PARSE_ERR_NO_FINAL_NEWLINE Line: 0 Document: 0 at /usr/local/share/perl/5.12.4/YAML/Loader.pm line 38

      using system Perl on Ubuntu which here is

      This is perl 5, version 12, subversion 4 (v5.12.4) built for i686-linu +x-gnu-thread-multi-64int (with 45 registered patches, see perl -V for more detail)

      Are you perhaps using a fairly ancient version of YAML::XS?

      What's the output of this?

      perl -MYAML::Any -E'say YAML::Any->implementation, q( ), YAML::Any->im +plementation->VERSION'

      Mine is YAML::XS 0.38.

      I suppose this is the downside of YAML::Any. :-(

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
        Mine is older than yours:
        perl -MYAML::Any -E'say YAML::Any->implementation, q( ), YAML::Any->im +plementation->VERSION' YAML::XS 0.34

        Does that qualify as ancient?

        The first thing I did when I saw my error message was to check the version of YAML::Any which was installed. Since it was older than CPAN (0.72 vs. 0.81), I updated it:

        cpan YAML::Any

        This apparently only updates the pure Perl code in the distribution (unless I answered prompts wrong, if there were any... I don't remember). This is what I get:

        perl -MYAML::Any -E'say YAML::Any->VERSION' 0.81

        So, how do I get the latest YAML::XS?

Re: CPAN Testers command-line viewer
by davido (Archbishop) on Jun 28, 2012 at 02:22 UTC

    This should be on CPAN as an applicaton. I think you know how to do it. :)

    Update (an aside): Before discovering http://analysis.cpantesters.org I wrote a little script that processed the tester's JSON dump, pulled in the text of the actual individual reports, and filled in a bunch of fields in an SQLite database, one row per report. Then I could SELECT ..... WHERE and find similarities across multiple failures. But it was really a one-off script: I was working on one particular module at the time, and soon discovered the analysis report that was more thorough and more useful. ...can't seem to find it now.


    Dave

      "This should be on CPAN as an applicaton."

      I have a bunch of similar little utilities knocking around in various states of usability. I'm tempted to wrap them all up into a single App::Cmd-based box of tricks.

      Update: I've put together a small demonstration at https://bitbucket.org/tobyink/p5-p5u. You can get a copy like this:

      hg clone https://bitbucket.org/tobyink/p5-p5u

      ... and assuming your libraries etc are set up correctly, you can run it like:

      p5u testers JSON
      p5u debian-release JSON
      
      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://978606]
Approved by kcott
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2014-07-26 20:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (179 votes), past polls