blib/lib/App/cpanreports.pm

filter: Statementstmt 52.2% 46 / 88 Branchbran 10.7% 3 / 28 Conditioncond 12.5% 1 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 86.6% 13 / 15 Podpod 100% 3 / 3 totaltotal 44.9% 66 / 147 CC 19 SCAR 45.1
CC
19
Cov
40%
run
210.0
get_report_summary
6.0
meta
5.7
CRAP 90.7
↑ Summary
1 package App::cpanreports;
2  
3 # Created on: 2015-03-01 11:33:26
4 # Create by: Ivan Wills
5 # $Id$
6 # $Revision$, $HeadURL$, $Date$
7 # $Revision$, $Source$, $Date$
8  
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Data::Dumper qw/Dumper/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use English qw/ -no_match_vars /;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use base qw/Exporter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use FindBin qw/$Bin/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use YAML::XS qw/Load LoadFile/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use WWW::Mechanize;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 our $VERSION = 0.004;
23 1 my ($name) = $PROGRAM_NAME =~ m{^.*/(.*?)$}mxs;
24  
25 my %option = (
26 version => meta()->{version},
27 distname => meta()->{name},
28 1 dir => 't/report',
29 verbose => 0,
30 man => 0,
31 help => 0,
32 VERSION => 0,
33 );
34  
35  
36 0 ▶sub run {
Subroutine run: not called CC=14 SCAR=53.5
Pod documented
37 0 my ($self) = @_;
38  
39 0 Getopt::Long::Configure('bundling');
40 0 ▶ GetOptions(
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions(\%option, "version|v=s", "distiname|d=s", "dir|D=s", "state|s=s", "verbose|V+", "man", "help", "VERSION!") or pod2usage(2) 0 0 0
41 \%option,
42 'version|v=s',
43 'distiname|d=s',
44 'dir|D=s',
45 'state|s=s',
46 'verbose|V+',
47 'man',
48 'help',
49 'VERSION!',
50 ) or pod2usage(2);
51  
52 0 ▶ if ( $option{'VERSION'} ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($option{'VERSION'}) { } 0 0 0
elsif ($option{'man'}) { } 0 0 0
elsif ($option{'help'}) { } 0 0 0
elsif (not $option{'version'} && $option{'distname'}) { } 0 0 0
53 0 print "$name Version = $VERSION\n";
54 0 exit 1;
55 }
56 elsif ( $option{'man'} ) {
57 0 pod2usage( -verbose => 2 );
58 }
59 elsif ( $option{'help'} ) {
60 0 pod2usage( -verbose => 1 );
61 }
62 ▶ elsif ( !$option{version} || !$option{distname} ) {
Condition0%0/3
$option{'version'} && $option{'distname'}
!ll&&!rl&&r
000
MC/DC0%0/2
$option{'version'} && $option{'distname'}
$option{'version'} $option{'distname'}
Truth table0%0/3
A && B
A= $option{'version'}B= $option{'distname'}
ABresult
0X0
100
111
63 0 warn <<'HELP';
64 The arguments --version and --distname must be specified if you are not
65 running from this script from the distribution's directory.
66  
67 HELP
68 0 pod2usage( -verbose => 1 );
69 }
70  
71 # do stuff here
72 0 my $mech = WWW::Mechanize->new;
73 0 my $dir = "$option{dir}/$option{version}";
74 0 my $test_reports = $self->get_report_summary($mech, $dir, $option{distname}, $option{version});
75  
76 0 for my $report (@$test_reports) {
77 0 ▶ next if $report->{version} ne $option{version};
Branch: 1 branch
BranchTrueFalseTotal
if $report->{"version"} ne $option{"version"} 0 0 0
78 0 ▶ next if $option{state} && $report->{state} eq $option{state};
Branch: 1 branch
BranchTrueFalseTotal
if $option{"state"} and $report->{"state"} eq $option{"state"} 0 0 0
Condition0%0/3
$option{"state"} and $report->{"state"} eq $option{"state"}
!ll&&!rl&&r
000
MC/DC0%0/2
$option{"state"} and $report->{"state"} eq $option{"state"}
$option{"state"} $report->{"state"} eq $option{"state"}
Truth table0%0/3
A and B
A= $option{"state"}B= $report->{"state"} eq $option{"state"}
ABresult
0X0
100
111
79  
80 0 my $guid = $report->{guid};
81 0 ▶ next if glob "$dir/*.$guid";
Branch: 1 branch
BranchTrueFalseTotal
if glob "$dir/*.$guid" 0 0 0
82  
83 0 my $file_name = "$dir/log.test-$report->{osname}.$report->{osvers}-$report->{perl}";
84 0 $mech->get("http://www.cpantesters.org/cpan/report/$guid");
85 0 my $text = $mech->content;
86  
87 0 ▶ if ($text =~ /ccflags[^\n]+ -DDEBUGGING.+?\n/sm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /ccflags[^\n]+ -DDEBUGGING.+?\n/ms) 0 0 0
88 0 $file_name .= 'd';
89 }
90 0 ▶ if ($report->{platform} !~ /thread/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($report->{"platform"} =~ /thread/) 0 0 0
91 0 $file_name .= "-nt";
92 }
93  
94 # add the GUID to the file to make determining if the report has been
95 # previously downloaded easy.
96 0 $file_name .= ".$guid";
97  
98 0 $text =~ s/^.*<pre>\nFrom:/From/sm;
99 0 $text =~ s{<hr class="clear-contentunit" />.*$}{}s;
100 0 decode_entities($text);
101  
102 0 path($file_name)->spew_utf8($text);
103 }
104  
105 0 return;
106 }
107  
108 1 my $meta;
109 2 ▶sub meta {
Subroutine meta: called CC=5 SCAR=17.5
Pod documented
110 2 ▶ return $meta if $meta;
Branch: 1 branch
BranchTrueFalseTotal
if $meta 1 1 2
111 1 ▶ my $file
Branch: 2 branches
BranchTrueFalseTotal
-f 'MYMETA.yml' ? : 1 0 1
-f '.build/latest/MYMETA.yml' ? : 0 0 0
112 = -f 'MYMETA.yml' ? path('MYMETA.yml')
113 : -f '.build/latest/MYMETA.yml' ? path('.build/latest/MYMETA.yml')
114 : path('META.yml');
115  
116 1 ▶ $meta = eval { LoadFile $file } || {};
Condition50%1/2
eval { do { LoadFile($file) } } || {}
l!l
10
MC/DC0%0/1
eval { do { LoadFile($file) } } || {}
eval { do { LoadFile($file) } }
Truth table50%1/2
A
A= eval { do { LoadFile($file) } }
Aresult
11
00
117 1 return $meta;
118 }
119  
120 0 ▶sub get_report_summary {
Subroutine get_report_summary: not called CC=2 SCAR=17.9
Pod documented
121 0 my ($self, $mech, $dir, $distname, $version) = @_;
122 0 my $cache = path("$dir/$distname.yml");
123 0 $cache->parent->mkpath;
124 0 ▶ if (-f $cache) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $cache) 0 0 0
125 0 return Load scalar $cache->slurp_utf8;
126 }
127  
128 0 my $initial = substr $distname, 0, 1;
129 0 my $url = "http://www.cpantesters.org/distro/$initial/$distname.yml";
130 0 $mech->get($url);
131 0 $cache->spew_utf8($mech->content);
132  
133 0 my $yaml = Load $mech->content;
134 0 return $yaml;
135 }
136  
137  
138 1 1;
139  
140 __END__
↑ Summary