| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: delegate testing to the cloud | ||||||||||||||||||||||||||||
| 3 | # PODNAME: cpan-tested | ||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use 5.008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use warnings qw(all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use CPAN::DistnameInfo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Carp qw(carp croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use File::Spec::Functions; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use HTTP::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use IO::Uncompress::Gunzip qw(gunzip $GunzipError); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use JSON::PP qw(decode_json); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Pod::Usage qw(pod2usage); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | our $VERSION = '0.003'; # VERSION | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # parse the options file | ||||||||||||||||||||||||||||
| 26 | 1 | my $rcname = catfile($ENV{HOME}, q(.cpan-tested.conf)); | |||||||||||||||||||||||||||
| 27 | 1 | ▶ | if (open(my $rcfile, q(<), $rcname)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | while (<$rcfile>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 0 | s/\#.*$//x; | |||||||||||||||||||||||||||
| 30 | 0 | s/^\s+|\s+$//gx; | |||||||||||||||||||||||||||
| 31 | 0 | ▶ | next unless $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 0 | my @pair = split /\s+/x, $_, 2; | |||||||||||||||||||||||||||
| 33 | 0 | $pair[0] = q(--) . $pair[0]; | |||||||||||||||||||||||||||
| 34 | 0 | unshift @ARGV, @pair; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | 0 | close $rcfile; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | my %match = ( | |||||||||||||||||||||||||||
| 41 | archname => 0, | ||||||||||||||||||||||||||||
| 42 | osname => 1, | ||||||||||||||||||||||||||||
| 43 | osvers => 0, | ||||||||||||||||||||||||||||
| 44 | version => 1, | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | Getopt::Long::GetOptions( | ||||||||||||||||||||||||||||
| 47 | q(h|help) => \my $help, | ||||||||||||||||||||||||||||
| 48 | q(b|blacklist=s)=> \my @blacklist, | ||||||||||||||||||||||||||||
| 49 | q(v|verbose) => \my $verbose, | ||||||||||||||||||||||||||||
| 50 | q(archname!) => \$match{archname}, # "x86_64-linux" | ||||||||||||||||||||||||||||
| 51 | q(osname!) => \$match{osname}, # "linux" | ||||||||||||||||||||||||||||
| 52 | q(osvers!) => \$match{osvers}, # "3.0.0-26-generic" | ||||||||||||||||||||||||||||
| 53 | q(perl!) => \$match{version}, # "5.14.2" | ||||||||||||||||||||||||||||
| 54 | 1 | ▶ | ) or pod2usage(-verbose => 1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 1 | ▶ | pod2usage(-verbose => 2) if $help; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | %match = map { | ||||||||||||||||||||||||||||
| 58 | 1 | $match{$_} | |||||||||||||||||||||||||||
| 59 | 4 | ▶ | ? ($_ => $Config{$_}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | : () | ||||||||||||||||||||||||||||
| 61 | } keys %match; | ||||||||||||||||||||||||||||
| 62 | 1 | $match{status} = q(PASS); # cine qua non | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 1 | ▶ | print STDERR Dumper \%match | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | if $verbose; | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 1 | my $ua = HTTP::Tiny->new( | |||||||||||||||||||||||||||
| 68 | agent => q(cpan-tested/) . $main::VERSION, | ||||||||||||||||||||||||||||
| 69 | default_headers => { q(Accept-Encoding) => q(gzip) }, | ||||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 1 | ▶ | while (my $name = <>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 1 | chomp $name; | |||||||||||||||||||||||||||
| 74 | 1 | my $d = CPAN::DistnameInfo->new($name); | |||||||||||||||||||||||||||
| 75 | 1 | my %prop = $d->properties; | |||||||||||||||||||||||||||
| 76 | 1 | ▶ | next unless defined $prop{dist}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # do not update blacklisted modules | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | next if grep { $prop{dist} =~ /^$_$/x } @blacklist; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 1 | my $json = fetch_results($prop{dist}); | |||||||||||||||||||||||||||
| 82 | 0 | my $versions = $json->{$prop{distvname}}; | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | if (q(ARRAY) ne ref $versions) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | carp qq($prop{distvname} not tested yet); | |||||||||||||||||||||||||||
| 85 | 0 | next; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | for my $test (@{$versions}) { | |||||||||||||||||||||||||||
| 89 | 0 | $test->{version} = delete $test->{perl}; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | my $ok = 0; | |||||||||||||||||||||||||||
| 92 | 0 | ▶ | while (my ($property, $value) = each %match) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | ++$ok | ||||||||||||||||||||||||||||
| 94 | if defined $test->{$property} | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | and $value eq $test->{$property}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $test->{$property} and $value eq $test->{$property}
MC/DC0%0/2
defined $test->{$property} and $value eq $test->{$property}
defined $test->{$property}
$value eq $test->{$property}
Truth table0%0/3
A and B
A= defined $test->{$property}B= $value eq $test->{$property}
| |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ($ok == keys %match) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | print STDERR Dumper $test | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | if defined $verbose; | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | print $name, qq(\n); | |||||||||||||||||||||||||||
| 103 | 0 | last; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 1 | ▶ | sub fetch_results { | ||||||||||||||||||||||||||
|
Subroutine
fetch_results: called CC=8 SCAR=36.7
| |||||||||||||||||||||||||||||
| 109 | 1 | my ($dist) = @_; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 1 | my $url = sprintf | |||||||||||||||||||||||||||
| 112 | q(http://cpantesters.org/static/distro/%s/%s.js), | ||||||||||||||||||||||||||||
| 113 | substr($dist, 0, 1), | ||||||||||||||||||||||||||||
| 114 | $dist; | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 1 | ▶ | print STDERR "$url\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | if defined $verbose; | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 1 | my $res = $ua->get($url); | |||||||||||||||||||||||||||
| 120 | croak qq($url: $res->{reason}) | ||||||||||||||||||||||||||||
| 121 | 1 | ▶ | unless $res->{success}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | my $content; | |||||||||||||||||||||||||||
| 124 | 0 | ▶ | if (defined $res->{headers}->{q(content-encoding)} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $res->{"headers"}{"content-encoding"} and $res->{"headers"}{"content-encoding"} eq "gzip"
MC/DC0%0/2
defined $res->{"headers"}{"content-encoding"} and $res->{"headers"}{"content-encoding"} eq "gzip"
defined $res->{"headers"}{"content-encoding"}
$res->{"headers"}{"content-encoding"} eq "gzip"
Truth table0%0/3
A and B
A= defined $res->{"headers"}{"content-encoding"}B= $res->{"headers"}{"content-encoding"} eq "gzip"
| |||||||||||||||||||||||||||||
| 125 | and $res->{headers}->{q(content-encoding)} eq q(gzip)) { | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | my $tmp; | |||||||||||||||||||||||||||
| 128 | 0 | ▶ | gunzip \$res->{content} => \$tmp | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | or croak qq($url: $GunzipError); | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | $content = $tmp; | |||||||||||||||||||||||||||
| 132 | } else { | ||||||||||||||||||||||||||||
| 133 | 0 | $content = $res->{content}; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ($content) = $content =~ /\bvar\s+results\s*=\s*({.*?});/sx; | |||||||||||||||||||||||||||
| 137 | 0 | $content =~ s/([{,])(\w+):/$1"$2":/gsx; | |||||||||||||||||||||||||||
| 138 | 0 | my $json = eval { decode_json($content) }; | |||||||||||||||||||||||||||
| 139 | 0 | ▶ | croak qq($url: $@) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ or "HASH" ne ref $json
MC/DC0%0/2
$@ or "HASH" ne ref $json
$@
"HASH" ne ref $json
Truth table0%0/3
A or B
A= $@B= "HASH" ne ref $json
| |||||||||||||||||||||||||||||
| 140 | if $@ | ||||||||||||||||||||||||||||
| 141 | or q(HASH) ne ref $json; | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | return $json; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | __END__ | ||||||||||||||||||||||||||||