bin/cpan-tested

filter: Statementstmt 65.0% 65 / 100 Branchbran 27.5% 11 / 40 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 15 / 15 Podpod n/a totaltotal 53.5% 91 / 170 CC 8 SCAR 27.0
CC
8
Cov
51%
fetch_results
39.3
BEGIN
1.0
BEGIN
1.0
CRAP 14.9
↑ Summary blib/lib/App/cpantested.pm »
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
BranchTrueFalseTotal
if (open my $rcfile, "<", $rcname) 0 1 1
28 0 ▶ while (<$rcfile>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $rcfile)) 0 0 0
29 0 s/\#.*$//x;
30 0 s/^\s+|\s+$//gx;
31 0 ▶ next unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 0 0
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
BranchTrueFalseTotal
&Getopt::Long::GetOptions("h|help", \my $help, "b|blacklist=s", \my @blacklist, "v|verbose", \my $verbose, "archname!", \$match{"archname"}, "osname!", \$match{"osname"}, "osvers!", \$match{"osvers"}, "perl!", \$match{"version"}) or pod2usage("-verbose", 1) 1 0 1
55 1 ▶pod2usage(-verbose => 2) if $help;
Branch: 1 branch
BranchTrueFalseTotal
if $help 0 1 1
56  
57 %match = map {
58 1 $match{$_}
59 4 ▶ ? ($_ => $Config{$_})
Branch: 1 branch
BranchTrueFalseTotal
$match{$_} ? : 1 3 4
60 : ()
61 } keys %match;
62 1 $match{status} = q(PASS); # cine qua non
63  
64 1 ▶print STDERR Dumper \%match
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 1 0 1
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
BranchTrueFalseTotal
if (defined(my $name = readline ARGV)) 1 0 1
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
BranchTrueFalseTotal
unless defined $prop{"dist"} 0 1 1
77  
78 # do not update blacklisted modules
79 0 ▶ next if grep { $prop{dist} =~ /^$_$/x } @blacklist;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$prop{"dist"} =~ /^$_$/x;} @blacklist 0 1 1
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
BranchTrueFalseTotal
if ("ARRAY" ne ref $versions) 0 0 0
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
BranchTrueFalseTotal
if (() = each %match) 0 0 0
93 ++$ok
94 if defined $test->{$property}
95 0 ▶ and $value eq $test->{$property};
Branch: 1 branch
BranchTrueFalseTotal
if defined $test->{$property} and $value eq $test->{$property} 0 0 0
Condition0%0/3
defined $test->{$property} and $value eq $test->{$property}
!ll&&!rl&&r
000
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}
ABresult
0X0
100
111
96 }
97  
98 0 ▶ if ($ok == keys %match) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok == keys %match) 0 0 0
99 0 ▶ print STDERR Dumper $test
Branch: 1 branch
BranchTrueFalseTotal
if defined $verbose 0 0 0
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
BranchTrueFalseTotal
if defined $verbose 1 0 1
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
BranchTrueFalseTotal
unless $res->{"success"} 1 0 1
122  
123 0 my $content;
124 0 ▶ if (defined $res->{headers}->{q(content-encoding)}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $res->{'headers'}{'content-encoding'} and $res->{'headers'}{'content-encoding'} eq 'gzip') { } 0 0 0
Condition0%0/3
defined $res->{"headers"}{"content-encoding"} and $res->{"headers"}{"content-encoding"} eq "gzip"
!ll&&!rl&&r
000
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"
ABresult
0X0
100
111
125 and $res->{headers}->{q(content-encoding)} eq q(gzip)) {
126  
127 0 my $tmp;
128 0 ▶ gunzip \$res->{content} => \$tmp
Branch: 1 branch
BranchTrueFalseTotal
gunzip(\$res->{"content"}, \$tmp) or croak("${url}: $main::GunzipError") 0 0 0
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
BranchTrueFalseTotal
if $@ or "HASH" ne ref $json 0 0 0
Condition0%0/3
$@ or "HASH" ne ref $json
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
140 if $@
141 or q(HASH) ne ref $json;
142  
143 0 return $json;
144 }
145  
146 __END__
↑ Summary blib/lib/App/cpantested.pm »