Parser.pm

filter: Statementstmt 98.6% 142 / 144 Branchbran 86.1% 31 / 36 Conditioncond 55.5% 5 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 97.3% 36 / 37 Podpod 100% 25 / 25 totaltotal 93.0% 239 / 257 CC 28 SCAR 14.8
CC
28
Cov
94%
new
9.2
report
9.0
reports
8.0
CRAP 4.4
« Parser/YAML.pm ↑ Summary Report.pm »
1 package CPAN::Testers::WWW::Reports::Parser;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 $VERSION = '0.05';
8  
9 #----------------------------------------------------------------------------
10 # Library Modules
11  
12 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 #----------------------------------------------------------------------------
15 # Variables
16  
17 6 my $WEB = 'http://www.cpantesters.org/cpan/report/';
18 6 my @valid_fields = qw( id distribution dist distname version distversion perl
19 state status grade action osname ostext osvers platform
20 archname url csspatch cssperl guid );
21 6 my %valid_fields = map {$_ => 1} @valid_fields;
22  
23 #----------------------------------------------------------------------------
24 # The Application Programming Interface
25  
26 sub new {
27 4 ▶ my $class = shift;
Subroutine new: called CC=9 SCAR=22.2
Pod documented
28 4 my %hash = @_;
29  
30 4 ▶ croak "No data format specified\n" unless($hash{format});
Branch: 1 branch
BranchTrueFalseTotal
unless $hash{"format"} 0 4 4
31 4 ▶ croak "Unknown data format specified\n" unless($hash{format} =~ /^(yaml|json)$/i);
Branch: 1 branch
BranchTrueFalseTotal
unless $hash{"format"} =~ /^(yaml|json)$/i 0 4 4
32 4 ▶ croak "Must specify a file or data block to parse\n" unless($hash{data} || $hash{file});
Branch: 1 branch
BranchTrueFalseTotal
unless $hash{"data"} or $hash{"file"} 0 4 4
Condition66%2/3
$hash{"data"} or $hash{"file"}
l!l&&r!l&&!r
130
MC/DC0%0/2
$hash{"data"} or $hash{"file"}
$hash{"data"} $hash{"file"}
Truth table66%2/3
A or B
A= $hash{"data"}B= $hash{"file"}
ABresult
1X1
011
000
33 4 ▶ croak "Cannot access file [$hash{file}]\n" if(defined $hash{file} && ! -f $hash{file});
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash{"file"} and not -f $hash{"file"} 0 4 4
Condition66%2/3
defined $hash{"file"} and not -f $hash{"file"}
!ll&&!rl&&r
130
MC/DC0%0/2
defined $hash{"file"} and not -f $hash{"file"}
defined $hash{"file"} not -f $hash{"file"}
Truth table66%2/3
A and not(B)
A= defined $hash{"file"}B= not -f $hash{"file"}
ABresult
0X0
100
111
34  
35 my $self = {
36 'format' => uc $hash{'format'},
37 'data' => $hash{'data'},
38 'file' => $hash{'file'},
39 4 'objects' => $hash{'objects'},
40 };
41 4 bless $self, $class;
42  
43 4 ▶ if($self->{objects}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"objects"}) 1 3 4
44 1 ▶ eval "use CPAN::Testers::WWW::Reports::Report";
Subroutine BEGIN: called CC=1 SCAR=0.0
45 }
46  
47 4 my $parser = 'CPAN::Testers::WWW::Reports::Parser::' . $self->{'format'};
48 4 ▶ eval "use $parser";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
49 4 ▶ croak "Cannot access $self->{'format'} parser, have you installed the necessary support modules?\n"
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 4 4
50 if($@);
51  
52 4 $self->{parser} = $parser->new();
53 4 $self->{parser}->register( file => $self->{file}, data => $self->{data} );
54 4 $self->{current} = {};
55  
56 4 return $self;
57 }
58  
59 sub DESTROY {
60 4 ▶ my $self = shift;
Subroutine DESTROY: called CC=1 SCAR=0.0
61 }
62  
63 sub filter {
64 13 ▶ my $self = shift;
Subroutine filter: called CC=4 SCAR=13.9
Pod documented
65  
66 13 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 9 4 13
67 9 ▶ $self->{all} = $_[0] =~ /^ALL$/i ? shift : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^ALL$/i ? : 4 5 9
68 9 $self->{fields}{$_} = 1 for(grep {$valid_fields{$_}} @_);
69  
70 # if no arguments, reset to default
71 } else {
72 4 $self->{all} = 1;
73 4 $self->{fields} = {};
74 }
75 }
76  
77 # full data set methods
78  
79 sub reports {
80 9 ▶ my $self = shift;
Subroutine reports: called CC=8 SCAR=20.8
Pod documented
81  
82 9 ▶ $self->filter(@_) if(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 6 3 9
83  
84 #use Data::Dumper;
85 #print STDERR (Dumper($self->{fields}));
86  
87 9 my $data = $self->{parser}->raw_data();
88 9 ▶ return $data unless(defined $self->{fields});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"fields"} 3 6 9
89  
90 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
91  
92 6 for my $report (@$data) {
93 3222 $self->{current} = $report;
94 3222 for my $field (keys %{ $self->{fields} }) {
95 #print STDERR "field=$field\n";
96 12888 eval { $report->{$field} = $self->$field(); };
97 }
98  
99 3222 ▶ next if($self->{all});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"all"} 1611 1611 3222
100  
101 1611 for my $key (keys %$report) {
102 28998 ▶ delete $report->{$key} unless($self->{fields}{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"fields"}{$key} 22554 6444 28998
103 }
104 }
105  
106 6 return $data;
107 }
108  
109  
110 # iterate through data set
111  
112 sub report {
113 545 ▶ my $self = shift;
Subroutine report: called CC=9 SCAR=22.0
Pod documented
114
115 545 ▶ unless($self->{loaded}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"loaded"}) 8 537 545
116 8 $self->{reports} = $self->{parser}->raw_data();
117 8 $self->{loaded} = 1;
118 }
119  
120 545 ▶ return unless(scalar(@{ $self->{reports} }));
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$self->{"reports"};} 1 544 545
121  
122 544 $self->{current} = shift @{ $self->{reports} };
123 544 my %report = map {$_ => $self->{current}{$_}} keys %{$self->{current}};
124  
125 544 ▶ if(scalar(keys %{ $self->{fields} })) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{$$self{"fields"};}) 3 541 544
126 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
127  
128 3 for my $field (keys %{ $self->{fields} }) {
129 27 eval { $report{$field} = $self->$field(); };
130 }
131  
132 3 ▶ unless($self->{all}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"all"}) 2 1 3
133 2 for my $key (keys %report) {
134 38 ▶ delete $report{$key} unless($self->{fields}{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"fields"}{$key} 15 23 38
135 }
136 }
137 }
138  
139 544 ▶ if($self->{objects}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"objects"}) 1 543 544
140 1 my $rep = CPAN::Testers::WWW::Reports::Report->new(\%report);
141 1 return $rep;
142 }
143  
144 543 return \%report;
145 }
146  
147 sub reload {
148 4 ▶ my $self = shift;
Subroutine reload: called CC=1 SCAR=0.0
Pod documented
149 4 $self->{loaded} = 0;
150 }
151  
152  
153 # transpose legacy field names to current field names
154  
155 0 ▶sub guid { my $self = shift; return $self->{current}->{guid} }
Subroutine guid: not called CC=1 SCAR=6.9
Pod documented
156 2 ▶sub id { my $self = shift; return $self->{current}->{id} }
Subroutine id: called CC=1 SCAR=0.0
Pod documented
157 2 ▶sub distribution { my $self = shift; return $self->{current}->{distribution} }
Subroutine distribution: called CC=1 SCAR=0.0
Pod documented
158 2 ▶sub dist { my $self = shift; return $self->{current}->{distribution} }
Subroutine dist: called CC=1 SCAR=0.0
Pod documented
159 3226 ▶sub distname { my $self = shift; return $self->{current}->{distribution} }
Subroutine distname: called CC=1 SCAR=0.0
Pod documented
160 3226 ▶sub version { my $self = shift; return $self->{current}->{version} }
Subroutine version: called CC=1 SCAR=0.0
Pod documented
161 2 ▶sub distversion { my $self = shift; return $self->{current}->{distversion} }
Subroutine distversion: called CC=1 SCAR=0.0
Pod documented
162 2 ▶sub perl { my $self = shift; return $self->{current}->{perl} }
Subroutine perl: called CC=1 SCAR=0.0
Pod documented
163  
164 2 ▶sub state { my $self = shift; return $self->{current}->{state} }
Subroutine state: called CC=1 SCAR=0.0
Pod documented
165 2 ▶sub status { my $self = shift; return $self->{current}->{status} }
Subroutine status: called CC=1 SCAR=0.0
Pod documented
166 3226 ▶sub grade { my $self = shift; return $self->{current}->{status} }
Subroutine grade: called CC=1 SCAR=0.0
Pod documented
167 2 ▶sub action { my $self = shift; return $self->{current}->{status} }
Subroutine action: called CC=1 SCAR=0.0
Pod documented
168  
169 2 ▶sub osname { my $self = shift; return $self->{current}->{osname} }
Subroutine osname: called CC=1 SCAR=0.0
Pod documented
170 2 ▶sub ostext { my $self = shift; return $self->{current}->{ostext} }
Subroutine ostext: called CC=1 SCAR=0.0
Pod documented
171 2 ▶sub osvers { my $self = shift; return $self->{current}->{osvers} }
Subroutine osvers: called CC=1 SCAR=0.0
Pod documented
172 2 ▶sub platform { my $self = shift; return $self->{current}->{platform} }
Subroutine platform: called CC=1 SCAR=0.0
Pod documented
173 2 ▶sub archname { my $self = shift; return $self->{current}->{platform} }
Subroutine archname: called CC=1 SCAR=0.0
Pod documented
174  
175 3226 ▶sub url { my $self = shift; return $WEB . ($self->{current}->{guid} || $self->{current}->{id}) }
Subroutine url: called CC=2 SCAR=8.1
Pod documented
Condition33%1/3
$self->{'current'}{'guid'} || $self->{'current'}{'id'}
l!l&&r!l&&!r
322600
MC/DC0%0/2
$self->{'current'}{'guid'} || $self->{'current'}{'id'}
$self->{'current'}{'guid'} $self->{'current'}{'id'}
Truth table33%1/3
A || B
A= $self->{'current'}{'guid'}B= $self->{'current'}{'id'}
ABresult
1X1
011
000
176  
177 2 ▶sub csspatch { my $self = shift; return $self->{current}->{csspatch} }
Subroutine csspatch: called CC=1 SCAR=0.0
Pod documented
178 2 ▶sub cssperl { my $self = shift; return $self->{current}->{cssperl} }
Subroutine cssperl: called CC=1 SCAR=0.0
Pod documented
179  
180  
181 6 q{ another hope, another dream, another truth ... installed by the machine };
182  
183 __END__
« Parser/YAML.pm ↑ Summary Report.pm »