blib/lib/CPAN/Testers/Data/Generator.pm

filter: Statementstmt 10.6% 87 / 821 Branchbran 0.4% 2 / 414 Conditioncond 0.9% 2 / 220 MC/DCmcdc 0.8% 1 / 122 Subroutinesub 36.9% 24 / 65 Podpod 100% 26 / 26 totaltotal 8.5% 142 / 1668 CC 321 SCAR 60.9
CC
321
Cov
6%
parse_report
1332.0
store_report
1332.0
reparse_report
756.0
CRAP 442.4
↑ Summary
1 package CPAN::Testers::Data::Generator;
2  
3 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 9 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 $VERSION = '1.21';
8  
9 #----------------------------------------------------------------------------
10 # Library Modules
11  
12 9 ▶use Config::IniFiles;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use CPAN::Testers::Common::Article;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 9 ▶use CPAN::Testers::Common::DBUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 #use Data::Dumper;
16 9 ▶use Data::FlexSerializer;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 9 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 9 ▶use DateTime::Duration;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 9 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 9 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 9 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 9 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 9 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 9 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 9 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 9 ▶use Metabase 0.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 9 ▶use Metabase::Fact;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 9 ▶use Metabase::Resource;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 9 ▶use CPAN::Testers::Fact::LegacyReport;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 9 ▶use CPAN::Testers::Fact::TestSummary;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 9 ▶use CPAN::Testers::Metabase::AWS;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 9 ▶use CPAN::Testers::Report;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 #----------------------------------------------------------------------------
36 # Variables
37  
38 9 my $DIFF = 30; # max difference allowed in seconds
39 9 my $MINS = 15; # split time in minutes
40  
41 9 my %testers;
42  
43 9 my $FROM = 'CPAN Tester Report Server <do_not_reply@cpantesters.org>';
44 9 my $HOW = '/usr/sbin/sendmail -bm';
45 9 my $HEAD = 'To: EMAIL
46 From: FROM
47 Date: DATE
48 Subject: CPAN Testers Generator Error Report
49  
50 ';
51  
52 9 my $BODY = '
53 The following reports failed to parse into the cpanstats database:
54  
55 INVALID
56  
57 Thanks,
58 CPAN Testers Server.
59 ';
60  
61 9 my @admins = (
62 'barbie@missbarbell.co.uk',
63 #'david@dagolden.com'
64 );
65  
66 9 my ($OSNAMES,%MAPPINGS);
67  
68 #----------------------------------------------------------------------------
69 # The Application Programming Interface
70  
71 0 ▶sub new {
Subroutine new: not called CC=26 SCAR=65.5
Pod documented
72 0 my $class = shift;
73 0 my %hash = @_;
74  
75 0 my $self = {
76 meta_count => 0,
77 stat_count => 0,
78 last => '',
79 };
80 0 bless $self, $class;
81  
82 # load configuration
83 0 my $cfg = Config::IniFiles->new( -file => $hash{config} );
84  
85 # configure databases
86 0 for my $db (qw(CPANSTATS METABASE)) {
87 0 ▶ die "No configuration for $db database\n" unless($cfg->SectionExists($db));
Branch: 1 branch
BranchTrueFalseTotal
unless $cfg->SectionExists($db) 0 0 0
88 0 ▶ my %opts = map {$_ => ($cfg->val($db,$_)||undef);} qw(driver database dbfile dbhost dbport dbuser dbpass);
Condition0%0/2
$cfg->val($db, $_) || undef
l!l
00
MC/DC0%0/1
$cfg->val($db, $_) || undef
$cfg->val($db, $_)
Truth table0%0/2
A
A= $cfg->val($db, $_)
Aresult
11
00
89 0 $opts{AutoCommit} = 0;
90 0 $self->{$db} = CPAN::Testers::Common::DBUtils->new(%opts);
91 0 ▶ die "Cannot configure $db database\n" unless($self->{$db});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{$db} 0 0 0
92 0 ▶ $self->{$db}->{'mysql_enable_utf8'} = 1 if($opts{driver} =~ /mysql/i);
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"driver"} =~ /mysql/i 0 0 0
93 0 ▶ $self->{$db}->{'mysql_auto_reconnect'} = 1 if($opts{driver} =~ /mysql/i);
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"driver"} =~ /mysql/i 0 0 0
94 }
95  
96 0 ▶ if($cfg->SectionExists('ADMINISTRATION')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cfg->SectionExists("ADMINISTRATION")) 0 0 0
97 0 my @admins = $cfg->val('ADMINISTRATION','admins');
98 0 $self->{admins} = \@admins;
99 }
100  
101 # command line swtiches override configuration settings
102 0 for my $key (qw(logfile poll_limit stopfile offset aws_bucket aws_namespace)) {
103 0 ▶ $self->{$key} = $hash{$key} || $cfg->val('MAIN',$key);
Condition0%0/3
$hash{$key} || $cfg->val('MAIN', $key)
l!l&&r!l&&!r
000
MC/DC0%0/2
$hash{$key} || $cfg->val('MAIN', $key)
$hash{$key} $cfg->val('MAIN', $key)
Truth table0%0/3
A || B
A= $hash{$key}B= $cfg->val('MAIN', $key)
ABresult
1X1
011
000
104 }
105  
106 0 ▶ $self->{offset} ||= 1;
Condition0%0/2
$self->{"offset"} ||= 1
l!l
00
MC/DC0%0/1
$self->{"offset"} ||= 1
$self->{"offset"}
Truth table0%0/2
A
A= $self->{"offset"}
Aresult
11
00
107 0 ▶ $self->{poll_limit} ||= 1000;
Condition0%0/2
$self->{"poll_limit"} ||= 1000
l!l
00
MC/DC0%0/1
$self->{"poll_limit"} ||= 1000
$self->{"poll_limit"}
Truth table0%0/2
A
A= $self->{"poll_limit"}
Aresult
11
00
108  
109 0 my @rows = $self->{METABASE}->get_query('hash','SELECT * FROM testers_email');
110 0 for my $row (@rows) {
111 0 $testers{$row->{resource}} = $row->{email};
112 }
113  
114 # build OS names map
115 0 @rows = $self->{CPANSTATS}->get_query('array','SELECT osname,ostitle FROM osname');
116 0 for my $row (@rows) {
117 0 ▶ $self->{OSNAMES}{lc $row->[0]} ||= $row->[1];
Condition0%0/3
$self->{"OSNAMES"}{lc $row->[0]} ||= $row->[1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"OSNAMES"}{lc $row->[0]} ||= $row->[1]
$self->{"OSNAMES"}{lc $row->[0]} $row->[1]
Truth table0%0/3
A ||= B
A= $self->{"OSNAMES"}{lc $row->[0]}B= $row->[1]
ABresult
1X1
011
000
118 }
119 0 ▶ $OSNAMES = join('|',keys %{$self->{OSNAMES}}) if(keys %{$self->{OSNAMES}});
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$$self{"OSNAMES"};} 0 0 0
120  
121 0 $self->load_uploads();
122 0 $self->load_authors();
123 0 $self->load_perl_versions();
124  
125 0 ▶ if($cfg->SectionExists('DISABLE')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cfg->SectionExists("DISABLE")) 0 0 0
126 0 my @values = $cfg->val('DISABLE','LIST');
127 0 $self->{DISABLE}{$_} = 1 for(@values);
128 }
129  
130 0 ▶ if($cfg->SectionExists('OSNAMES')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cfg->SectionExists("OSNAMES")) 0 0 0
131 0 for my $param ($cfg->Parameters('OSNAMES')) {
132 0 ▶ $self->{OSNAMES}{lc $param} ||= lc $cfg->val('OSNAMES',$param);
Condition0%0/3
$self->{"OSNAMES"}{lc $param} ||= lc $cfg->val("OSNAMES", $param)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"OSNAMES"}{lc $param} ||= lc $cfg->val("OSNAMES", $param)
$self->{"OSNAMES"}{lc $param} lc $cfg->val("OSNAMES", $param)
Truth table0%0/3
A ||= B
A= $self->{"OSNAMES"}{lc $param}B= lc $cfg->val("OSNAMES", $param)
ABresult
1X1
011
000
133 }
134 }
135  
136 0 ▶ if($cfg->SectionExists('MAPPINGS')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cfg->SectionExists("MAPPINGS")) 0 0 0
137 0 for my $param ($cfg->Parameters('MAPPINGS')) {
138 0 $MAPPINGS{$param} = [ split(',', $cfg->val('MAPPINGS',$param), 2) ];
139 }
140 }
141  
142 0 eval {
143 $self->{metabase} = CPAN::Testers::Metabase::AWS->new(
144 bucket => $self->{aws_bucket},
145 namespace => $self->{aws_namespace},
146 0 );
147 0 $self->{librarian} = $self->{metabase}->public_librarian;
148 };
149  
150 # if we require remote access, we need the librarian
151 0 ▶ unless($hash{localonly}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hash{"localonly"}) 0 0 0
152 0 ▶ return unless($self->{metabase} && $self->{librarian});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"metabase"} and $self->{"librarian"} 0 0 0
Condition0%0/3
$self->{"metabase"} and $self->{"librarian"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"metabase"} and $self->{"librarian"}
$self->{"metabase"} $self->{"librarian"}
Truth table0%0/3
A and B
A= $self->{"metabase"}B= $self->{"librarian"}
ABresult
0X0
100
111
153 }
154  
155 # reports are now stored in a compressed format
156 0 $self->{serializer} = Data::FlexSerializer->new(
157 detect_compression => 1,
158 detect_json => 1,
159 output_format => 'json'
160 );
161 0 $self->{serializer2} = Data::FlexSerializer->new(
162 detect_compression => 1,
163 detect_sereal => 1,
164 output_format => 'sereal'
165 );
166  
167 0 return $self;
168 }
169  
170 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
171 0 my $self = shift;
172  
173 0 $self->save_perl_versions();
174 }
175  
176 #----------------------------------------------------------------------------
177 # Public Methods
178  
179 0 ▶sub generate {
Subroutine generate: not called CC=11 SCAR=48.8
Pod documented
180 0 my $self = shift;
181 0 ▶ my $nonstop = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
182 0 my $maxdate = shift;
183 0 my ($to,@reports);
184  
185 0 $self->{reparse} = 0;
186  
187 0 $self->_log("START GENERATE nonstop=$nonstop\n");
188  
189 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$nonstop and do { do { my $start = localtime time; ($self->{"processed"}, $self->{"stored"}, $self->{"cached"}) = (0, 0, 0); if ($maxdate) { $to = $maxdate; } else { $to = sprintf("%sT%sZ", "DateTime"->now->ymd, "DateTime"->now->hms); } ; $self->_log("DATES maxdate=$maxdate, to=$to \n"); my $data = $self->get_next_dates($to); $self->_consume_reports($to, $data); $nonstop = 0 if $self->{"processed"} == 0; $nonstop = 0 if $self->{"stopfile"} and -f $self->{"stopfile"}; $nonstop = 0 if $maxdate and $maxdate le $to; $self->load_uploads if $nonstop; $self->load_authors if $nonstop; $self->_log("CHECK nonstop=$nonstop\n") } } 0 0 0
190 0 my $start = localtime(time);
191 0 ($self->{processed},$self->{stored},$self->{cached}) = (0,0,0);
192  
193 0 ▶ if($maxdate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($maxdate) { } 0 0 0
194 0 $to = $maxdate;
195 } else {
196 0 $to = sprintf "%sT%sZ", DateTime->now->ymd, DateTime->now->hms;
197 }
198  
199 0 $self->_log("DATES maxdate=$maxdate, to=$to \n");
200  
201 0 my $data = $self->get_next_dates($to);
202
203 0 $self->_consume_reports( $to, $data );
204  
205 0 ▶ $nonstop = 0 if($self->{processed} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"processed"} == 0 0 0 0
206 0 ▶ $nonstop = 0 if($self->{stopfile} && -f $self->{stopfile});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"stopfile"} and -f $self->{"stopfile"} 0 0 0
Condition0%0/3
$self->{"stopfile"} and -f $self->{"stopfile"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"stopfile"} and -f $self->{"stopfile"}
$self->{"stopfile"} -f $self->{"stopfile"}
Truth table0%0/3
A and B
A= $self->{"stopfile"}B= -f $self->{"stopfile"}
ABresult
0X0
100
111
207 0 ▶ $nonstop = 0 if($maxdate && $maxdate le $to);
Branch: 1 branch
BranchTrueFalseTotal
if $maxdate and $maxdate le $to 0 0 0
Condition0%0/3
$maxdate and $maxdate le $to
!ll&&!rl&&r
000
MC/DC0%0/2
$maxdate and $maxdate le $to
$maxdate $maxdate le $to
Truth table0%0/3
A and B
A= $maxdateB= $maxdate le $to
ABresult
0X0
100
111
208  
209 0 ▶ $self->load_uploads() if($nonstop);
Branch: 1 branch
BranchTrueFalseTotal
if $nonstop 0 0 0
210 0 ▶ $self->load_authors() if($nonstop);
Branch: 1 branch
BranchTrueFalseTotal
if $nonstop 0 0 0
211  
212 0 $self->_log("CHECK nonstop=$nonstop\n");
213 } while($nonstop);
214 0 $self->_log("STOP GENERATE nonstop=$nonstop\n");
215 }
216  
217 0 ▶sub regenerate {
Subroutine regenerate: not called CC=8 SCAR=42.8
Pod documented
218 0 my ($self,$hash) = @_;
219  
220 0 $self->{reparse} = 0;
221  
222 0 my $maxdate = sprintf "%sT%sZ", DateTime->now->ymd, DateTime->now->hms;
223  
224 0 $self->_log("START REGENERATE\n");
225  
226 0 my @data;
227 0 ▶ if($hash->{file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash->{'file'}) { } 0 0 0
228 0 ▶ my $fh = IO::File->new($hash->{file},'r') or die "Cannot open file [$hash->{file}]: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new($hash->{"file"}, "r") or die qq[Cannot open file [$hash->{"file"}]: $!\n] 0 0 0
229 0 ▶ while(<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
230 0 s/\s+$//;
231 0 my ($fval,$tval) = split(/,/,$_,2);
232 0 my %data;
233 0 ▶ $data{gstart} = $fval if($fval =~ /^\w+-\w+-\w+-\w+-\w+$/);
Branch: 1 branch
BranchTrueFalseTotal
if $fval =~ /^\w+-\w+-\w+-\w+-\w+$/ 0 0 0
234 0 ▶ $data{dstart} = $fval if($fval =~ /^\d+-\d+-\d+T\d+:\d+:\d+Z$/);
Branch: 1 branch
BranchTrueFalseTotal
if $fval =~ /^\d+-\d+-\d+T\d+:\d+:\d+Z$/ 0 0 0
235 0 ▶ $data{gend} = $tval if($tval =~ /^\w+-\w+-\w+-\w+-\w+$/);
Branch: 1 branch
BranchTrueFalseTotal
if $tval =~ /^\w+-\w+-\w+-\w+-\w+$/ 0 0 0
236 0 ▶ $data{dend} = $tval if($tval =~ /^\d+-\d+-\d+T\d+:\d+:\d+Z$/);
Branch: 1 branch
BranchTrueFalseTotal
if $tval =~ /^\d+-\d+-\d+T\d+:\d+:\d+Z$/ 0 0 0
237 0 push @data, \%data;
238 }
239 0 $fh->close;
240 } else {
241 push @data, { gstart => $hash->{gstart}, gend => $hash->{gend},
242 0 dstart => $hash->{dstart}, dend => $hash->{dend} };
243 }
244  
245 0 $self->_consume_reports( $maxdate, \@data );
246  
247 0 $self->_log("STOP REGENERATE\n");
248 }
249  
250 0 ▶sub rebuild {
Subroutine rebuild: not called CC=12 SCAR=50.5
Pod documented
251 0 my ($self,$hash) = @_;
252 0 $self->_log("START REBUILD\n");
253  
254 0 my $start = localtime(time);
255 0 ($self->{processed},$self->{stored},$self->{cached}) = (0,0,0);
256  
257 0 $self->{reparse} = 1;
258 0 ▶ $self->{localonly} = $hash->{localonly} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$hash->{'localonly'} ? : 0 0 0
259 0 ▶ $self->{check} = $hash->{check} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$hash->{'check'} ? : 0 0 0
260  
261  
262 # selection choices:
263 # 1) from guid [to guid]
264 # 2) from date [to date]
265  
266 0 $hash->{dstart} = $self->_get_createdate( $hash->{gstart}, $hash->{dstart} );
267 0 $hash->{dend} = $self->_get_createdate( $hash->{gend}, $hash->{dend} );
268  
269 0 my @where;
270 0 ▶ push @where, "updated >= '$hash->{dstart}'" if($hash->{dstart});
Branch: 1 branch
BranchTrueFalseTotal
if $hash->{"dstart"} 0 0 0
271 0 ▶ push @where, "updated <= '$hash->{dend}'" if($hash->{dend});
Branch: 1 branch
BranchTrueFalseTotal
if $hash->{"dend"} 0 0 0
272
273 0 ▶ my $sql = 'SELECT * FROM metabase' .
Branch: 1 branch
BranchTrueFalseTotal
@where ? : 0 0 0
274 (@where ? ' WHERE ' . join(' AND ',@where) : '') .
275 ' ORDER BY updated ASC';
276  
277 0 $self->_log("START sql=[$sql]\n");
278  
279 # $self->{CPANSTATS}->do_query("DELETE FROM cpanstats WHERE id >= $start AND id <= $end");
280  
281 0 my $iterator = $self->{METABASE}->iterator('hash',$sql);
282 0 ▶ while(my $row = $iterator->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = &$iterator()) 0 0 0
283 0 $self->_log("GUID [$row->{guid}]");
284 0 $self->{processed}++;
285  
286 0 my $report = $self->load_fact(undef,0,$row);
287  
288 0 ▶ unless($report) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($report) 0 0 0
289 0 $self->_log(" ... no report\n");
290 0 warn "No report returned [$row->{id},$row->{guid}]\n";
291 0 next;
292 }
293  
294 0 $self->{report}{id} = $row->{id};
295 0 $self->{report}{guid} = $row->{guid};
296 0 $self->{report}{metabase} = $self->{facts};
297  
298 # corrupt cached report?
299 0 ▶ if($self->reparse_report()) { # true if invalid report
Branch: 1 branch
BranchTrueFalseTotal
if ($self->reparse_report) 0 0 0
300 0 $self->_log(".. cannot parse metabase cache report\n");
301 0 warn "Cannot parse cached report [$row->{id},$row->{guid}]\n";
302 0 next;
303 }
304  
305 0 ▶ if($self->store_report()) { $self->_log(".. cpanstats stored\n") }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->store_report) { } 0 0 0
306 0 else { $self->_log(".. cpanstats not stored\n") }
307 0 ▶ if($self->cache_update()) { $self->_log(".. metabase stored\n") }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cache_update) { } 0 0 0
308 0 else { $self->_log(".. bad metabase cache data\n") }
309  
310 0 $self->{stored}++;
311 0 $self->{cached}++;
312 }
313  
314 0 ▶ my $invalid = $self->{invalid} ? scalar(@{$self->{invalid}}) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'invalid'} ? : 0 0 0
315 0 my $stop = localtime(time);
316 0 $self->_log("MARKER: processed=$self->{processed}, stored=$self->{stored}, cached=$self->{cached}, invalid=$invalid, start=$start, stop=$stop\n");
317  
318 0 $self->commit();
319 0 $self->_log("STOP REBUILD\n");
320 }
321  
322 0 ▶sub parse {
Subroutine parse: not called CC=11 SCAR=48.8
Pod documented
323 0 my ($self,$hash) = @_;
324 0 $self->_log("START PARSE\n");
325  
326 0 my @guids = $self->_get_guid_list($hash->{guid},$hash->{file});
327 0 ▶ return unless(@guids);
Branch: 1 branch
BranchTrueFalseTotal
unless @guids 0 0 0
328  
329 0 ▶ $self->{force} ||= 0;
Condition0%0/2
$self->{"force"} ||= 0
l!l
00
MC/DC0%0/1
$self->{"force"} ||= 0
$self->{"force"}
Truth table0%0/2
A
A= $self->{"force"}
Aresult
11
00
330  
331 0 for my $guid (@guids) {
332 0 $self->_log("GUID [$guid]");
333  
334 0 my ($report,$stored);
335 0 ▶ unless($hash->{force}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hash->{"force"}) 0 0 0
336 0 $report = $self->load_fact($guid,1);
337 0 $stored = $self->retrieve_report($guid);
338 }
339  
340 0 ▶ if($report && $stored) {
Branch: 1 branch
BranchTrueFalseTotal
if ($report and $stored) 0 0 0
Condition0%0/3
$report and $stored
!ll&&!rl&&r
000
MC/DC0%0/2
$report and $stored
$report $stored
Truth table0%0/3
A and B
A= $reportB= $stored
ABresult
0X0
100
111
341 0 $self->_log(".. report already stored and cached\n");
342 0 next;
343 }
344  
345 0 $report = $self->get_fact($guid);
346  
347 0 ▶ unless($report) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($report) 0 0 0
348 0 $self->_log(".. report not found [$guid]\n");
349 0 next;
350 }
351
352 0 $self->{report}{guid} = $guid;
353 0 $hash->{report} = $report;
354 0 ▶ if($self->parse_report(%$hash)) { # true if invalid report
Branch: 1 branch
BranchTrueFalseTotal
if ($self->parse_report(%$hash)) 0 0 0
355 0 $self->_log(".. cannot parse report [$guid]\n");
356 0 next;
357 }
358  
359 0 ▶ if($self->store_report()) { $self->_log(".. stored"); }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->store_report) { } 0 0 0
360 0 else { $self->_log(".. already stored"); }
361  
362 0 ▶ if($self->cache_report()) { $self->_log(".. cached\n"); }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cache_report) { } 0 0 0
363 0 else { $self->_log(".. FAIL: bad cache data\n"); }
364 }
365  
366 0 $self->commit();
367 0 $self->_log("STOP PARSE\n");
368 0 return 1;
369 }
370  
371 0 ▶sub reparse {
Subroutine reparse: not called CC=17 SCAR=57.2
Pod documented
372 0 my ($self,$hash) = @_;
373 0 $self->_log("START REPARSE\n");
374  
375 0 my @guids = $self->_get_guid_list($hash->{guid},$hash->{file});
376 0 ▶ return unless(@guids);
Branch: 1 branch
BranchTrueFalseTotal
unless @guids 0 0 0
377  
378 0 ▶ $self->{reparse} = $self->{force} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'force'} ? : 0 0 0
379 0 ▶ $self->{localonly} = $hash->{localonly} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$hash->{'localonly'} ? : 0 0 0
380 0 ▶ $self->{check} = $hash->{check} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$hash->{'check'} ? : 0 0 0
381  
382 0 for my $guid (@guids) {
383 0 $self->_log("GUID [$guid]");
384  
385 0 my $report;
386 0 ▶ $report = $self->load_fact($guid) unless($hash->{force});
Branch: 1 branch
BranchTrueFalseTotal
unless $hash->{"force"} 0 0 0
387  
388 0 ▶ if($report) {
Branch: 1 branch
BranchTrueFalseTotal
if ($report) { } 0 0 0
389 0 $self->{report}{metabase} = $report;
390 0 $self->{report}{guid} = $guid;
391 0 $hash->{report} = $report;
392 0 ▶ if($self->reparse_report(%$hash)) { # true if invalid report
Branch: 1 branch
BranchTrueFalseTotal
if ($self->reparse_report(%$hash)) 0 0 0
393 0 $self->_log(".. cannot parse report [$guid]\n");
394 0 return 0;
395 }
396 } else {
397 0 ▶ $report = $self->get_fact($guid) unless($report || $hash->{localonly});
Branch: 1 branch
BranchTrueFalseTotal
unless $report or $hash->{"localonly"} 0 0 0
Condition0%0/3
$report or $hash->{"localonly"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$report or $hash->{"localonly"}
$report $hash->{"localonly"}
Truth table0%0/3
A or B
A= $reportB= $hash->{"localonly"}
ABresult
1X1
011
000
398  
399 0 ▶ unless($report) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($report) 0 0 0
400 0 ▶ if($self->{localonly}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"localonly"}) 0 0 0
401 0 $self->_log(".. report not available locally [$guid]\n");
402 0 return 0;
403 }
404 0 $self->_log(".. report not found [$guid]\n");
405 0 return 0;
406 }
407
408 0 $self->{report}{guid} = $guid;
409 0 $hash->{report} = $report;
410 0 ▶ if($self->parse_report(%$hash)) { # true if invalid report
Branch: 1 branch
BranchTrueFalseTotal
if ($self->parse_report(%$hash)) 0 0 0
411 0 $self->_log(".. cannot parse report [$guid]\n");
412 0 return 0;
413 }
414 }
415  
416 0 ▶ if($self->store_report()) { $self->_log(".. stored"); }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->store_report) { } 0 0 0
417 else {
418 0 ▶ if($self->{time} gt $self->{report}{updated}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"time"} gt $self->{"report"}{"updated"}) 0 0 0
419 0 $self->_log(".. FAIL: older than requested [$self->{time}]\n");
420 0 return 0;
421 }
422
423 0 $self->_log(".. already stored");
424 }
425 0 ▶ if($self->cache_report()) { $self->_log(".. cached\n"); }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cache_report) { } 0 0 0
426 0 else { $self->_log(".. FAIL: bad cache data\n"); }
427 }
428  
429 0 $self->commit();
430 0 $self->_log("STOP REPARSE\n");
431 0 return 1;
432 }
433  
434 0 ▶sub tail {
Subroutine tail: not called CC=4 SCAR=30.0
Pod documented
435 0 my ($self,$hash) = @_;
436 0 ▶ return unless($hash->{file});
Branch: 1 branch
BranchTrueFalseTotal
unless $hash->{"file"} 0 0 0
437  
438 0 $self->_log("START TAIL\n");
439  
440 0 my $guids = $self->get_tail_guids();
441 0 ▶ my $fh = IO::File->new($hash->{file},'a+') or die "Cannot read file [$hash->{file}]: $!";
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new($hash->{"file"}, "a+") or die qq[Cannot read file [$hash->{"file"}]: $!] 0 0 0
442 0 print $fh "$_\n" for(@$guids);
443 0 $fh->close;
444  
445 0 $self->_log("STOP TAIL\n");
446 }
447  
448 #----------------------------------------------------------------------------
449 # Internal Methods
450  
451 0 ▶sub commit {
Subroutine commit: not called CC=3 SCAR=24.8
Pod documented
452 0 my $self = shift;
453 0 for(qw(CPANSTATS)) {
454 0 ▶ next unless($self->{$_});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{$_} 0 0 0
455 0 $self->{$_}->do_commit;
456 }
457 }
458  
459 0 ▶sub get_tail_guids {
Subroutine get_tail_guids: not called CC=3 SCAR=24.8
Pod documented
460 0 my $self = shift;
461 0 my $guids;
462  
463 0 eval {
464 # $guids = $self->{librarian}->search(
465 # 'core.type' => 'CPAN-Testers-Report',
466 # 'core.update_time' => { ">", 0 },
467 # '-desc' => 'core.update_time',
468 # '-limit' => $self->{poll_limit},
469 # );
470 $guids = $self->{librarian}->search(
471 '-where' => [
472 '-and' =>
473 [ '-eq' => 'core.type' => 'CPAN-Testers-Report' ],
474 [ '-ge' => 'core.update_time' => 0 ]
475 ],
476 '-order' => [ '-desc' => 'core.update_time' ],
477 '-limit' => $self->{poll_limit},
478 0 );
479 };
480  
481 0 ▶ $self->_log(" ... Metabase Tail Failed [$@]\n") if($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
482 0 ▶ $self->_log("Retrieved ".($guids ? scalar(@$guids) : 0)." guids\n");
Branch: 1 branch
BranchTrueFalseTotal
$guids ? : 0 0 0
483  
484 0 return $guids;
485 }
486  
487 0 ▶sub get_next_dates {
Subroutine get_next_dates: not called CC=8 SCAR=42.8
Pod documented
488 0 my ($self,$to) = @_;
489 0 my (@data,$from);
490  
491 0 my $time = sprintf "%sT%sZ", DateTime->now->ymd, DateTime->now->hms;
492  
493 0 $self->_log("DATES to=$to, time=$time\n");
494  
495 # note that because Amazon's SimpleDB can return odd entries out of sync, we have to look at previous entries
496 # to ensure we are starting from the right point. Also ignore date/times in the future.
497 0 my @rows = $self->{METABASE}->get_query('array','SELECT updated FROM metabase WHERE updated <= ? ORDER BY updated DESC LIMIT 10',$time);
498 0 for my $row (@rows) {
499 0 ▶ if($from) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from) 0 0 0
500 0 my $diff = abs( _date_diff($from,$row->[0]) ); # just interested in the difference
501 0 $self->_log("get_next_dates from=[$from], updated=[$row->[0]], diff=$diff, DIFF=$DIFF\n");
502 0 ▶ next if($diff < $DIFF);
Branch: 1 branch
BranchTrueFalseTotal
if $diff < $DIFF 0 0 0
503 }
504  
505 0 $from = $row->[0];
506 }
507  
508 0 ▶ $from ||= '1999-01-01T00:00:00Z';
Condition0%0/2
$from ||= "1999-01-01T00:00:00Z"
l!l
00
MC/DC0%0/1
$from ||= "1999-01-01T00:00:00Z"
$from
Truth table0%0/2
A
A= $from
Aresult
11
00
509 0 ▶ if($from gt $to) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from gt $to) 0 0 0
510 0 my $xx = $from;
511 0 $from = $to;
512 0 $to = $xx;
513 }
514  
515 0 $self->_log("NEXT from=[$from], to=[$to]\n");
516  
517 0 ▶ while($from lt $to) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from lt $to) 0 0 0
518 0 my @from = $from =~ /(\d+)\-(\d+)\-(\d+)T(\d+):(\d+):(\d+)/;
519 0 my $dt = DateTime->new(
520 year => $from[0], month => $from[1], day => $from[2],
521 hour => $from[3], minute => $from[4], second => $from[5],
522 );
523 0 $dt->add( DateTime::Duration->new( minutes => $MINS ) );
524 0 my $split = sprintf "%sT%sZ", $dt->ymd, $dt->hms;
525 0 ▶ if($split lt $to) {
Branch: 1 branch
BranchTrueFalseTotal
if ($split lt $to) { } 0 0 0
526 0 push @data, { dstart => $from, dend => $split };
527 } else {
528 0 push @data, { dstart => $from, dend => $to };
529 }
530  
531 0 $from = $split;
532 }
533  
534 0 return \@data;
535 }
536  
537 0 ▶sub get_next_guids {
Subroutine get_next_guids: not called CC=15 SCAR=54.8
Pod documented
538 0 my ($self,$start,$end) = @_;
539 0 my ($guids);
540  
541 0 ▶ $self->{time} ||= 0;
Condition0%0/2
$self->{"time"} ||= 0
l!l
00
MC/DC0%0/1
$self->{"time"} ||= 0
$self->{"time"}
Truth table0%0/2
A
A= $self->{"time"}
Aresult
11
00
542 0 ▶ $self->{last} ||= 0;
Condition0%0/2
$self->{"last"} ||= 0
l!l
00
MC/DC0%0/1
$self->{"last"} ||= 0
$self->{"last"}
Truth table0%0/2
A
A= $self->{"last"}
Aresult
11
00
543 0 ▶ $start ||= 0;
Condition0%0/2
$start ||= 0
l!l
00
MC/DC0%0/1
$start ||= 0
$start
Truth table0%0/2
A
A= $start
Aresult
11
00
544  
545 0 ▶ $self->_log("PRE time=[$self->{time}], last=[$self->{last}], start=[".($start||'')."], end=[".($end||'')."]\n");
Condition0%0/4
$start || ''
l!l
00
$end || ''
l!l
00
MC/DC0%0/1
$start || ''
$start
MC/DC0%0/1
$end || ''
$end
Truth table0%0/2
A
A= $start
Aresult
11
00
Truth table0%0/2
A
A= $end
Aresult
11
00
546  
547 0 ▶ if($start) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start) { } 0 0 0
548 0 $self->{time} = $start;
549 0 ▶ $self->{time_to} = $end || '';
Condition0%0/2
$end || ''
l!l
00
MC/DC0%0/1
$end || ''
$end
Truth table0%0/2
A
A= $end
Aresult
11
00
550 } else {
551 0 my $time = sprintf "%sT%sZ", DateTime->now->ymd, DateTime->now->hms;
552  
553 # note that because Amazon's SimpleDB can return odd entries out of sync, we have to look at previous entries
554 # to ensure we are starting from the right point. Also ignore date/times in the future.
555 0 my @rows = $self->{METABASE}->get_query('array','SELECT updated FROM metabase WHERE updated <= ? ORDER BY updated DESC LIMIT 10',$time);
556 0 for my $row (@rows) {
557 0 ▶ if($self->{time}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"time"}) 0 0 0
558 0 my $diff = abs( _date_diff($self->{time},$row->[0]) ); # just interested in the difference
559 0 ▶ next if($diff < $DIFF);
Branch: 1 branch
BranchTrueFalseTotal
if $diff < $DIFF 0 0 0
560 }
561  
562 0 $self->{time} = $row->[0];
563 }
564  
565 0 ▶ $self->{time} ||= '1999-01-01T00:00:00Z';
Condition0%0/2
$self->{"time"} ||= "1999-01-01T00:00:00Z"
l!l
00
MC/DC0%0/1
$self->{"time"} ||= "1999-01-01T00:00:00Z"
$self->{"time"}
Truth table0%0/2
A
A= $self->{"time"}
Aresult
11
00
566 0 ▶ if($self->{last} ge $self->{time}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"last"} ge $self->{"time"}) 0 0 0
567 0 my @ts = $self->{last} =~ /(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)Z/;
568 0 $ts[1]--;
569 0 my $ts = timelocal(reverse @ts);
570 0 @ts = localtime($ts + $self->{offset}); # increment the offset for next time
571 0 $self->{time} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ", $ts[5]+1900,$ts[4]+1,$ts[3], $ts[2],$ts[1],$ts[0];
572 }
573 }
574  
575 0 $self->_log("START time=[$self->{time}], last=[$self->{last}]\n");
576 0 $self->{last} = $self->{time};
577  
578 0 eval {
579 # if($self->{time_to}) {
580 # $guids = $self->{librarian}->search(
581 # 'core.type' => 'CPAN-Testers-Report',
582 # 'core.update_time' => { -and => { ">=" => $self->{time}, "<=" => $self->{time_to} } },
583 # '-asc' => 'core.update_time',
584 # '-limit' => $self->{poll_limit},
585 # );
586 # } else {
587 $guids = $self->{librarian}->search(
588 '-where' => [
589 '-and' =>
590 [ '-eq' => 'core.type' => 'CPAN-Testers-Report' ],
591 [ '-ge' => 'core.update_time' => $self->{time} ]
592 ],
593 '-order' => [ '-asc' => 'core.update_time' ],
594 '-limit' => $self->{poll_limit},
595 0 );
596 # }
597 };
598  
599 0 ▶ $self->_log(" ... Metabase Search Failed [$@]\n") if($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
600 0 ▶ $self->_log("Retrieved ".($guids ? scalar(@$guids) : 0)." guids\n");
Branch: 1 branch
BranchTrueFalseTotal
$guids ? : 0 0 0
601 0 return $guids;
602 }
603  
604 0 ▶sub retrieve_reports {
Subroutine retrieve_reports: not called CC=10 SCAR=47.0
Pod documented
605 0 my ($self,$guids,$start) = @_;
606  
607 0 ▶ if($guids) {
Branch: 1 branch
BranchTrueFalseTotal
if ($guids) 0 0 0
608 0 for my $guid (@$guids) {
609 0 $self->_log("GUID [$guid]");
610 0 $self->{processed}++;
611 0 $self->{msg} = '';
612  
613 0 ▶ if(my $report = $self->get_fact($guid)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $report = $self->get_fact($guid)) { } 0 0 0
614 0 $self->{report}{guid} = $guid;
615 0 ▶ next if($self->parse_report(report => $report)); # true if invalid report
Branch: 1 branch
BranchTrueFalseTotal
if $self->parse_report("report", $report) 0 0 0
616  
617 0 ▶ if($self->store_report()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->store_report) { } 0 0 0
618 0 $self->{msg} .= ".. stored";
619 0 $self->{stored}++;
620  
621 } else {
622 0 ▶ if($self->{time} gt $self->{report}{updated}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"time"} gt $self->{"report"}{"updated"}) 0 0 0
623 0 $self->_log(".. FAIL: older than requested [$self->{time}]\n");
624 0 next;
625 }
626 0 $self->{msg} .= ".. already stored";
627 }
628 0 ▶ if($self->cache_report()) { $self->_log(".. cached\n"); $self->{cached}++; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cache_report) { } 0 0 0
629 0 else { $self->_log(".. bad cache data\n"); }
630 } else {
631 0 $self->_log(".. FAIL\n");
632 }
633 }
634 }
635  
636 0 $self->commit();
637 0 ▶ my $invalid = $self->{invalid} ? scalar(@{$self->{invalid}}) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'invalid'} ? : 0 0 0
638 0 my $stop = localtime(time);
639 0 $self->_log("MARKER: processed=$self->{processed}, stored=$self->{stored}, cached=$self->{cached}, invalid=$invalid, start=$start, stop=$stop\n");
640  
641 # only email invalid reports during the generate process
642 0 ▶ $self->_send_email() if($self->{invalid});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"invalid"} 0 0 0
643 }
644  
645 0 ▶sub already_saved {
Subroutine already_saved: not called CC=2 SCAR=17.9
Pod documented
646 0 my ($self,$guid) = @_;
647 0 my @rows = $self->{METABASE}->get_query('array','SELECT updated FROM metabase WHERE guid=?',$guid);
648 0 ▶ return $rows[0]->[0] if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
649 0 return 0;
650 }
651  
652 0 ▶sub load_fact {
Subroutine load_fact: not called CC=8 SCAR=42.8
Pod documented
653 0 my ($self,$guid,$check,$row) = @_;
654  
655 0 ▶ if(!$row && $guid) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $row and $guid) 0 0 0
Condition0%0/3
not $row and $guid
!ll&&!rl&&r
000
MC/DC0%0/2
not $row and $guid
not $row $guid
Truth table0%0/3
not(A) and B
A= not $rowB= $guid
ABresult
0X0
100
111
656 0 my @rows = $self->{METABASE}->get_query('hash','SELECT report,fact FROM metabase WHERE guid=?',$guid);
657 0 ▶ $row = $rows[0] if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
658 }
659  
660 0 ▶ if($row) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row) 0 0 0
661 0 ▶ if($row->{fact}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row->{"fact"}) 0 0 0
662 0 $self->{fact} = $self->{serializer2}->deserialize($row->{fact});
663 0 $self->{facts} = $self->dereference_report($self->{fact});
664 0 return $self->{facts};
665 }
666
667 0 ▶ if($row->{report}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row->{"report"}) 0 0 0
668 0 $self->{facts} = $self->{serializer}->deserialize($row->{report});
669 0 return $self->{facts};
670 }
671 }
672  
673 0 ▶ $self->_log(" ... no report [guid=$guid]\n") unless($check);
Branch: 1 branch
BranchTrueFalseTotal
unless $check 0 0 0
674 0 return;
675 }
676  
677 0 ▶sub get_fact {
Subroutine get_fact: not called CC=2 SCAR=17.9
Pod documented
678 0 my ($self,$guid) = @_;
679 0 my $fact;
680 #print STDERR "guid=$guid\n";
681 0 eval { $fact = $self->{librarian}->extract( $guid ) };
682  
683 0 ▶ if($fact) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fact) 0 0 0
684 0 $self->{fact} = $fact;
685 0 return $fact;
686 }
687  
688 0 $self->_log(" ... no report [guid=$guid] [$@]\n");
689 0 return;
690 }
691  
692 0 ▶sub dereference_report {
Subroutine dereference_report: not called CC=2 SCAR=17.9
Pod documented
693 0 my ($self,$report) = @_;
694 0 my %facts;
695  
696 0 my @facts = $report->facts();
697 0 for my $fact (@facts) {
698 0 my $name = ref $fact;
699 0 $facts{$name} = $fact->as_struct;
700 0 $facts{$name}{content} = decode_json($facts{$name}{content});
701 }
702  
703 0 return \%facts;
704 }
705  
706 0 ▶sub parse_report {
Subroutine parse_report: not called CC=36 SCAR=71.9
Pod documented
707 0 my ($self,%hash) = @_;
708 0 my $options = $hash{options};
709 0 my $report = $hash{report};
710 0 my $guid = $self->{report}{guid};
711 0 my $invalid;
712  
713 0 $self->{report}{created} = $report->{metadata}{core}{creation_time};
714 0 $self->{report}{updated} = $report->{metadata}{core}{update_time};
715  
716 0 ▶ unless(ref($report) eq 'CPAN::Testers::Report') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $report eq "CPAN::Testers::Report") 0 0 0
717 0 $self->{msg} .= ".. ref [" . ref($report) . "]";
718 0 return 1;
719 }
720  
721 0 my @facts = $report->facts();
722 0 for my $fact (@facts) {
723 0 ▶ if(ref $fact eq 'CPAN::Testers::Fact::TestSummary') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $fact eq 'CPAN::Testers::Fact::TestSummary') { } 0 0 0
elsif (ref $fact eq 'CPAN::Testers::Fact::LegacyReport') { } 0 0 0
724 0 $self->{report}{metabase}{'CPAN::Testers::Fact::TestSummary'} = $fact->as_struct;
725 0 $self->{report}{metabase}{'CPAN::Testers::Fact::TestSummary'}{content} = decode_json($self->{report}{metabase}{'CPAN::Testers::Fact::TestSummary'}{content});
726  
727 0 $self->{report}{state} = lc $fact->{content}{grade};
728 0 $self->{report}{platform} = $fact->{content}{archname};
729 0 $self->{report}{osname} = $self->_osname($fact->{content}{osname});
730 0 $self->{report}{osvers} = $fact->{content}{osversion};
731 0 $self->{report}{perl} = $fact->{content}{perl_version};
732 #$self->{report}{created} = $fact->{metadata}{core}{creation_time};
733 #$self->{report}{updated} = $fact->{metadata}{core}{update_time};
734  
735 0 my $dist = Metabase::Resource->new( $fact->resource );
736 0 $self->{report}{dist} = $dist->metadata->{dist_name};
737 0 $self->{report}{version} = $dist->metadata->{dist_version};
738 0 $self->{report}{resource} = $dist->metadata->{resource};
739  
740 # some distros are a pain!
741 0 ▶ if($self->{report}{version} eq '' && $MAPPINGS{$self->{report}{dist}}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'report'}{'version'} eq '' and $MAPPINGS{$self->{'report'}{'dist'}}) { } 0 0 0
elsif ($self->{'report'}{'version'} eq '') { } 0 0 0
Condition0%0/3
$self->{"report"}{"version"} eq "" and $MAPPINGS{$self->{"report"}{"dist"}}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"report"}{"version"} eq "" and $MAPPINGS{$self->{"report"}{"dist"}}
$self->{"report"}{"version"} eq "" $MAPPINGS{$self->{"report"}{"dist"}}
Truth table0%0/3
A and B
A= $self->{"report"}{"version"} eq ""B= $MAPPINGS{$self->{"report"}{"dist"}}
ABresult
0X0
100
111
742 0 $self->{report}{version} = $MAPPINGS{$self->{report}{dist}}->[1];
743 0 $self->{report}{dist} = $MAPPINGS{$self->{report}{dist}}->[0];
744 } elsif($self->{report}{version} eq '') {
745 0 $self->{report}{version} = 0;
746 }
747  
748 0 $self->{report}{from} = $self->_get_tester( $fact->creator->resource );
749  
750 # alternative API
751 #my $profile = $fact->creator->user;
752 #$self->{report}{from} = $profile->{email};
753 #$self->{report}{from} =~ s/'/''/g; #'
754 #$self->{report}{dist} = $fact->resource->dist_name;
755 #$self->{report}{version} = $fact->resource->dist_version;
756  
757 } elsif(ref $fact eq 'CPAN::Testers::Fact::LegacyReport') {
758 0 $self->{report}{metabase}{'CPAN::Testers::Fact::LegacyReport'} = $fact->as_struct;
759 0 $self->{report}{metabase}{'CPAN::Testers::Fact::LegacyReport'}{content} = decode_json($self->{report}{metabase}{'CPAN::Testers::Fact::LegacyReport'}{content});
760 0 ▶ $invalid = 'missing textreport' if(length $fact->{content}{textreport} < 10); # what is the smallest report?
Branch: 1 branch
BranchTrueFalseTotal
if length $fact->{"content"}{"textreport"} < 10 0 0 0
761  
762 0 $self->{report}{perl} = $fact->{content}{perl_version};
763 }
764 }
765  
766 0 ▶ if($invalid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($invalid) 0 0 0
767 0 push @{$self->{invalid}}, {msg => $invalid, guid => $guid};
768 0 return 1;
769 }
770  
771 # fixes from metabase formatting
772 0 $self->{report}{perl} =~ s/^v//; # no leading 'v'
773 0 $self->_check_arch_os();
774  
775 0 ▶ if($self->{report}{created}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'report'}{'created'}) { } 0 0 0
776 0 my @created = $self->{report}{created} =~ /(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)Z/; # 2010-02-23T20:33:52Z
777 0 $self->{report}{postdate} = sprintf "%04d%02d", $created[0], $created[1];
778 0 $self->{report}{fulldate} = sprintf "%04d%02d%02d%02d%02d", $created[0], $created[1], $created[2], $created[3], $created[4];
779 } else {
780 0 my @created = localtime(time);
781 0 $self->{report}{postdate} = sprintf "%04d%02d", $created[5]+1900, $created[4]+1;
782 0 $self->{report}{fulldate} = sprintf "%04d%02d%02d%02d%02d", $created[5]+1900, $created[4]+1, $created[3], $created[2], $created[1];
783 }
784  
785 0 $self->{msg} .= ".. time [$self->{report}{created}][$self->{report}{updated}]";
786  
787 0 $self->{report}{type} = 2;
788 0 ▶ if($self->{DISABLE} && $self->{DISABLE}{$self->{report}{from}}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'DISABLE'} and $self->{'DISABLE'}{$self->{'report'}{'from'}}) { } 0 0 0
elsif ($self->{'report'}{'response'} and $self->{'report'}{'response'} =~ m[/perl6/]) { } 0 0 0
Condition0%0/3
$self->{"DISABLE"} and $self->{"DISABLE"}{$self->{"report"}{"from"}}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"DISABLE"} and $self->{"DISABLE"}{$self->{"report"}{"from"}}
$self->{"DISABLE"} $self->{"DISABLE"}{$self->{"report"}{"from"}}
Truth table0%0/3
A and B
A= $self->{"DISABLE"}B= $self->{"DISABLE"}{$self->{"report"}{"from"}}
ABresult
0X0
100
111
789 0 $self->{report}{state} .= ':invalid';
790 0 $self->{report}{type} = 3;
791 ▶ } elsif($self->{report}{response} && $self->{report}{response} =~ m!/perl6/!) {
Condition0%0/3
$self->{"report"}{"response"} and $self->{"report"}{"response"} =~ m[/perl6/]
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"report"}{"response"} and $self->{"report"}{"response"} =~ m[/perl6/]
$self->{"report"}{"response"} $self->{"report"}{"response"} =~ m[/perl6/]
Truth table0%0/3
A and B
A= $self->{"report"}{"response"}B= $self->{"report"}{"response"} =~ m[/perl6/]
ABresult
0X0
100
111
792 # $self->{report}{type} = 6;
793 0 return 1;
794 }
795  
796 #print STDERR "\n====\nreport=".Dumper($self->{report});
797  
798 0 ▶ return 1 unless($self->_valid_field($guid, 'dist' => $self->{report}{dist}) || ($options && $options->{exclude}{dist}));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_valid_field($guid, "dist", $self->{"report"}{"dist"}) or $options and $options->{"exclude"}{"dist"} 0 0 0
Condition0%0/6
$self->_valid_field($guid, "dist", $self->{"report"}{"dist"}) or $options and $options->{"exclude"}{"dist"}
l!l&&r!l&&!r
000
$options and $options->{"exclude"}{"dist"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->_valid_field($guid, "dist", $self->{"report"}{"dist"}) or $options and $options->{"exclude"}{"dist"}
$self->_valid_field($guid, "dist", $self->{"report"}{"dist"}) $options $options->{"exclude"}{"dist"}
Truth table0%0/4
A or B and C
A= $self->_valid_field($guid, "dist", $self->{"report"}{"dist"})B= $optionsC= $options->{"exclude"}{"dist"}
ABCresult
1XX1
0111
00X0
0100
799 0 ▶ return 1 unless($self->_valid_field($guid, 'version' => $self->{report}{version}) || ($options && $options->{exclude}{version}));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_valid_field($guid, "version", $self->{"report"}{"version"}) or $options and $options->{"exclude"}{"version"} 0 0 0
Condition0%0/6
$self->_valid_field($guid, "version", $self->{"report"}{"version"}) or $options and $options->{"exclude"}{"version"}
l!l&&r!l&&!r
000
$options and $options->{"exclude"}{"version"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->_valid_field($guid, "version", $self->{"report"}{"version"}) or $options and $options->{"exclude"}{"version"}
$self->_valid_field($guid, "version", $self->{"report"}{"version"}) $options $options->{"exclude"}{"version"}
Truth table0%0/4
A or B and C
A= $self->_valid_field($guid, "version", $self->{"report"}{"version"})B= $optionsC= $options->{"exclude"}{"version"}
ABCresult
1XX1
0111
00X0
0100
800 0 ▶ return 1 unless($self->_valid_field($guid, 'from' => $self->{report}{from}) || ($options && $options->{exclude}{from}));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_valid_field($guid, "from", $self->{"report"}{"from"}) or $options and $options->{"exclude"}{"from"} 0 0 0
Condition0%0/6
$self->_valid_field($guid, "from", $self->{"report"}{"from"}) or $options and $options->{"exclude"}{"from"}
l!l&&r!l&&!r
000
$options and $options->{"exclude"}{"from"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->_valid_field($guid, "from", $self->{"report"}{"from"}) or $options and $options->{"exclude"}{"from"}
$self->_valid_field($guid, "from", $self->{"report"}{"from"}) $options $options->{"exclude"}{"from"}
Truth table0%0/4
A or B and C
A= $self->_valid_field($guid, "from", $self->{"report"}{"from"})B= $optionsC= $options->{"exclude"}{"from"}
ABCresult
1XX1
0111
00X0
0100
801 0 ▶ return 1 unless($self->_valid_field($guid, 'perl' => $self->{report}{perl}) || ($options && $options->{exclude}{perl}));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_valid_field($guid, "perl", $self->{"report"}{"perl"}) or $options and $options->{"exclude"}{"perl"} 0 0 0
Condition0%0/6
$self->_valid_field($guid, "perl", $self->{"report"}{"perl"}) or $options and $options->{"exclude"}{"perl"}
l!l&&r!l&&!r
000
$options and $options->{"exclude"}{"perl"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->_valid_field($guid, "perl", $self->{"report"}{"perl"}) or $options and $options->{"exclude"}{"perl"}
$self->_valid_field($guid, "perl", $self->{"report"}{"perl"}) $options $options->{"exclude"}{"perl"}
Truth table0%0/4
A or B and C
A= $self->_valid_field($guid, "perl", $self->{"report"}{"perl"})B= $optionsC= $options->{"exclude"}{"perl"}
ABCresult
1XX1
0111
00X0
0100
802 0 ▶ return 1 unless($self->_valid_field($guid, 'platform' => $self->{report}{platform}) || ($options && $options->{exclude}{platform}));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_valid_field($guid, "platform", $self->{"report"}{"platform"}) or $options and $options->{"exclude"}{"platform"} 0 0 0
Condition0%0/6
$self->_valid_field($guid, "platform", $self->{"report"}{"platform"}) or $options and $options->{"exclude"}{"platform"}
l!l&&r!l&&!r
000
$options and $options->{"exclude"}{"platform"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->_valid_field($guid, "platform", $self->{"report"}{"platform"}) or $options and $options->{"exclude"}{"platform"}
$self->_valid_field($guid, "platform", $self->{"report"}{"platform"}) $options $options->{"exclude"}{"platform"}
Truth table0%0/4
A or B and C
A= $self->_valid_field($guid, "platform", $self->{"report"}{"platform"})B= $optionsC= $options->{"exclude"}{"platform"}
ABCresult
1XX1
0111
00X0
0100
803 0 ▶ return 1 unless($self->_valid_field($guid, 'osname' => $self->{report}{osname}) || ($options && $options->{exclude}{osname}));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_valid_field($guid, "osname", $self->{"report"}{"osname"}) or $options and $options->{"exclude"}{"osname"} 0 0 0
Condition0%0/6
$self->_valid_field($guid, "osname", $self->{"report"}{"osname"}) or $options and $options->{"exclude"}{"osname"}
l!l&&r!l&&!r
000
$options and $options->{"exclude"}{"osname"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->_valid_field($guid, "osname", $self->{"report"}{"osname"}) or $options and $options->{"exclude"}{"osname"}
$self->_valid_field($guid, "osname", $self->{"report"}{"osname"}) $options $options->{"exclude"}{"osname"}
Truth table0%0/4
A or B and C
A= $self->_valid_field($guid, "osname", $self->{"report"}{"osname"})B= $optionsC= $options->{"exclude"}{"osname"}
ABCresult
1XX1
0111
00X0
0100
804 0 ▶ return 1 unless($self->_valid_field($guid, 'osvers' => $self->{report}{osvers}) || ($options && $options->{exclude}{osname}));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_valid_field($guid, "osvers", $self->{"report"}{"osvers"}) or $options and $options->{"exclude"}{"osname"} 0 0 0
Condition0%0/6
$self->_valid_field($guid, "osvers", $self->{"report"}{"osvers"}) or $options and $options->{"exclude"}{"osname"}
l!l&&r!l&&!r
000
$options and $options->{"exclude"}{"osname"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->_valid_field($guid, "osvers", $self->{"report"}{"osvers"}) or $options and $options->{"exclude"}{"osname"}
$self->_valid_field($guid, "osvers", $self->{"report"}{"osvers"}) $options $options->{"exclude"}{"osname"}
Truth table0%0/4
A or B and C
A= $self->_valid_field($guid, "osvers", $self->{"report"}{"osvers"})B= $optionsC= $options->{"exclude"}{"osname"}
ABCresult
1XX1
0111
00X0
0100
805  
806 0 return 0
807 }
808  
809 0 ▶sub reparse_report {
Subroutine reparse_report: not called CC=27 SCAR=66.3
Pod documented
810 0 my ($self,%hash) = @_;
811 0 my $fact = 'CPAN::Testers::Fact::TestSummary';
812 0 my $options = $hash{options};
813  
814 0 $self->{report}{metabase}{$fact}{content} = encode_json($self->{report}{metabase}{$fact}{content});
815 0 my $report = CPAN::Testers::Fact::TestSummary->from_struct( $self->{report}{metabase}{$fact} );
816 0 my $guid = $self->{report}{guid};
817  
818 0 $self->{report}{state} = lc $report->{content}{grade};
819 0 $self->{report}{platform} = $report->{content}{archname};
820 0 $self->{report}{osname} = $self->_osname($report->{content}{osname});
821 0 $self->{report}{osvers} = $report->{content}{osversion};
822 0 $self->{report}{perl} = $report->{content}{perl_version};
823 0 $self->{report}{created} = $report->{metadata}{core}{creation_time};
824  
825 0 my $dist = Metabase::Resource->new( $report->{metadata}{core}{resource} );
826 0 $self->{report}{dist} = $dist->metadata->{dist_name};
827 0 $self->{report}{version} = $dist->metadata->{dist_version};
828 0 $self->{report}{resource} = $dist->metadata->{resource};
829  
830 0 $self->{report}{from} = $self->_get_tester( $report->{metadata}{core}{creator}{resource} );
831  
832 0 ▶ if($self->{report}{created}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'report'}{'created'}) { } 0 0 0
833 0 my @created = $self->{report}{created} =~ /(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)Z/; # 2010-02-23T20:33:52Z
834 0 $self->{report}{postdate} = sprintf "%04d%02d", $created[0], $created[1];
835 0 $self->{report}{fulldate} = sprintf "%04d%02d%02d%02d%02d", $created[0], $created[1], $created[2], $created[3], $created[4];
836 } else {
837 0 my @created = localtime(time);
838 0 $self->{report}{postdate} = sprintf "%04d%02d", $created[5]+1900, $created[4]+1;
839 0 $self->{report}{fulldate} = sprintf "%04d%02d%02d%02d%02d", $created[5]+1900, $created[4]+1, $created[3], $created[2], $created[1];
840 }
841  
842 0 $self->{report}{type} = 2;
843 0 ▶ if($self->{DISABLE} && $self->{DISABLE}{$self->{report}{from}}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'DISABLE'} and $self->{'DISABLE'}{$self->{'report'}{'from'}}) { } 0 0 0
elsif ($self->{'report'}{'response'} and $self->{'report'}{'response'} =~ m[/perl6/]) { } 0 0 0
Condition0%0/3
$self->{"DISABLE"} and $self->{"DISABLE"}{$self->{"report"}{"from"}}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"DISABLE"} and $self->{"DISABLE"}{$self->{"report"}{"from"}}
$self->{"DISABLE"} $self->{"DISABLE"}{$self->{"report"}{"from"}}
Truth table0%0/3
A and B
A= $self->{"DISABLE"}B= $self->{"DISABLE"}{$self->{"report"}{"from"}}
ABresult
0X0
100
111
844 0 $self->{report}{state} .= ':invalid';
845 0 $self->{report}{type} = 3;
846 ▶ } elsif($self->{report}{response} && $self->{report}{response} =~ m!/perl6/!) {
Condition0%0/3
$self->{"report"}{"response"} and $self->{"report"}{"response"} =~ m[/perl6/]
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"report"}{"response"} and $self->{"report"}{"response"} =~ m[/perl6/]
$self->{"report"}{"response"} $self->{"report"}{"response"} =~ m[/perl6/]
Truth table0%0/3
A and B
A= $self->{"report"}{"response"}B= $self->{"report"}{"response"} =~ m[/perl6/]
ABresult
0X0
100
111
847 # $self->{report}{type} = 6;
848 0 return 1;
849 }
850  
851 0 ▶ return 1 unless($self->_valid_field($guid, 'dist' => $self->{report}{dist}) || ($options && $options->{exclude}{dist}));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_valid_field($guid, "dist", $self->{"report"}{"dist"}) or $options and $options->{"exclude"}{"dist"} 0 0 0
Condition0%0/6
$self->_valid_field($guid, "dist", $self->{"report"}{"dist"}) or $options and $options->{"exclude"}{"dist"}
l!l&&r!l&&!r
000
$options and $options->{"exclude"}{"dist"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->_valid_field($guid, "dist", $self->{"report"}{"dist"}) or $options and $options->{"exclude"}{"dist"}
$self->_valid_field($guid, "dist", $self->{"report"}{"dist"}) $options $options->{"exclude"}{"dist"}
Truth table0%0/4
A or B and C
A= $self->_valid_field($guid, "dist", $self->{"report"}{"dist"})B= $optionsC= $options->{"exclude"}{"dist"}
ABCresult
1XX1
0111
00X0
0100
852 0 ▶ return 1 unless($self->_valid_field($guid, 'version' => $self->{report}{version}) || ($options && $options->{exclude}{version}));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_valid_field($guid, "version", $self->{"report"}{"version"}) or $options and $options->{"exclude"}{"version"} 0 0 0
Condition0%0/6
$self->_valid_field($guid, "version", $self->{"report"}{"version"}) or $options and $options->{"exclude"}{"version"}
l!l&&r!l&&!r
000
$options and $options->{"exclude"}{"version"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->_valid_field($guid, "version", $self->{"report"}{"version"}) or $options and $options->{"exclude"}{"version"}
$self->_valid_field($guid, "version", $self->{"report"}{"version"}) $options $options->{"exclude"}{"version"}
Truth table0%0/4
A or B and C
A= $self->_valid_field($guid, "version", $self->{"report"}{"version"})B= $optionsC= $options->{"exclude"}{"version"}
ABCresult
1XX1
0111
00X0
0100
853 0 ▶ return 1 unless($self->_valid_field($guid, 'from' => $self->{report}{from}) || ($options && $options->{exclude}{from}));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_valid_field($guid, "from", $self->{"report"}{"from"}) or $options and $options->{"exclude"}{"from"} 0 0 0
Condition0%0/6
$self->_valid_field($guid, "from", $self->{"report"}{"from"}) or $options and $options->{"exclude"}{"from"}
l!l&&r!l&&!r
000
$options and $options->{"exclude"}{"from"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->_valid_field($guid, "from", $self->{"report"}{"from"}) or $options and $options->{"exclude"}{"from"}
$self->_valid_field($guid, "from", $self->{"report"}{"from"}) $options $options->{"exclude"}{"from"}
Truth table0%0/4
A or B and C
A= $self->_valid_field($guid, "from", $self->{"report"}{"from"})B= $optionsC= $options->{"exclude"}{"from"}
ABCresult
1XX1
0111
00X0
0100
854 0 ▶ return 1 unless($self->_valid_field($guid, 'perl' => $self->{report}{perl}) || ($options && $options->{exclude}{perl}));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_valid_field($guid, "perl", $self->{"report"}{"perl"}) or $options and $options->{"exclude"}{"perl"} 0 0 0
Condition0%0/6
$self->_valid_field($guid, "perl", $self->{"report"}{"perl"}) or $options and $options->{"exclude"}{"perl"}
l!l&&r!l&&!r
000
$options and $options->{"exclude"}{"perl"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->_valid_field($guid, "perl", $self->{"report"}{"perl"}) or $options and $options->{"exclude"}{"perl"}
$self->_valid_field($guid, "perl", $self->{"report"}{"perl"}) $options $options->{"exclude"}{"perl"}
Truth table0%0/4
A or B and C
A= $self->_valid_field($guid, "perl", $self->{"report"}{"perl"})B= $optionsC= $options->{"exclude"}{"perl"}
ABCresult
1XX1
0111
00X0
0100
855 0 ▶ return 1 unless($self->_valid_field($guid, 'platform' => $self->{report}{platform}) || ($options && $options->{exclude}{platform}));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_valid_field($guid, "platform", $self->{"report"}{"platform"}) or $options and $options->{"exclude"}{"platform"} 0 0 0
Condition0%0/6
$self->_valid_field($guid, "platform", $self->{"report"}{"platform"}) or $options and $options->{"exclude"}{"platform"}
l!l&&r!l&&!r
000
$options and $options->{"exclude"}{"platform"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->_valid_field($guid, "platform", $self->{"report"}{"platform"}) or $options and $options->{"exclude"}{"platform"}
$self->_valid_field($guid, "platform", $self->{"report"}{"platform"}) $options $options->{"exclude"}{"platform"}
Truth table0%0/4
A or B and C
A= $self->_valid_field($guid, "platform", $self->{"report"}{"platform"})B= $optionsC= $options->{"exclude"}{"platform"}
ABCresult
1XX1
0111
00X0
0100
856 0 ▶ return 1 unless($self->_valid_field($guid, 'osname' => $self->{report}{osname}) || ($options && $options->{exclude}{osname}));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_valid_field($guid, "osname", $self->{"report"}{"osname"}) or $options and $options->{"exclude"}{"osname"} 0 0 0
Condition0%0/6
$self->_valid_field($guid, "osname", $self->{"report"}{"osname"}) or $options and $options->{"exclude"}{"osname"}
l!l&&r!l&&!r
000
$options and $options->{"exclude"}{"osname"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->_valid_field($guid, "osname", $self->{"report"}{"osname"}) or $options and $options->{"exclude"}{"osname"}
$self->_valid_field($guid, "osname", $self->{"report"}{"osname"}) $options $options->{"exclude"}{"osname"}
Truth table0%0/4
A or B and C
A= $self->_valid_field($guid, "osname", $self->{"report"}{"osname"})B= $optionsC= $options->{"exclude"}{"osname"}
ABCresult
1XX1
0111
00X0
0100
857 0 ▶ return 1 unless($self->_valid_field($guid, 'osvers' => $self->{report}{osvers}) || ($options && $options->{exclude}{osname}));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_valid_field($guid, "osvers", $self->{"report"}{"osvers"}) or $options and $options->{"exclude"}{"osname"} 0 0 0
Condition0%0/6
$self->_valid_field($guid, "osvers", $self->{"report"}{"osvers"}) or $options and $options->{"exclude"}{"osname"}
l!l&&r!l&&!r
000
$options and $options->{"exclude"}{"osname"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->_valid_field($guid, "osvers", $self->{"report"}{"osvers"}) or $options and $options->{"exclude"}{"osname"}
$self->_valid_field($guid, "osvers", $self->{"report"}{"osvers"}) $options $options->{"exclude"}{"osname"}
Truth table0%0/4
A or B and C
A= $self->_valid_field($guid, "osvers", $self->{"report"}{"osvers"})B= $optionsC= $options->{"exclude"}{"osname"}
ABCresult
1XX1
0111
00X0
0100
858  
859 0 return 0;
860 }
861  
862 0 ▶sub retrieve_report {
Subroutine retrieve_report: not called CC=3 SCAR=24.8
Pod documented
863 0 my $self = shift;
864 0 ▶ my $guid = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $guid = shift() or return 0 0 0
865  
866 0 my @rows = $self->{CPANSTATS}->get_query('hash','SELECT * FROM cpanstats WHERE guid=?',$guid);
867 0 ▶ return $rows[0] if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
868 0 return;
869 }
870  
871 0 ▶sub store_report {
Subroutine store_report: not called CC=36 SCAR=71.9
Pod documented
872 0 my $self = shift;
873 0 my @fields = qw(guid state postdate from dist version platform perl osname osvers fulldate type uploadid);
874  
875 0 my %fields = map {$_ => $self->{report}{$_}} @fields;
876 0 ▶ $fields{$_} ||= 0 for(qw(type uploadid));
Condition0%0/2
$fields{$_} ||= 0
l!l
00
MC/DC0%0/1
$fields{$_} ||= 0
$fields{$_}
Truth table0%0/2
A
A= $fields{$_}
Aresult
11
00
877 0 ▶ $fields{$_} ||= '0' for(qw(perl));
Condition0%0/2
$fields{$_} ||= 0
l!l
00
MC/DC0%0/1
$fields{$_} ||= 0
$fields{$_}
Truth table0%0/2
A
A= $fields{$_}
Aresult
11
00
878 0 ▶ $fields{$_} ||= '' for(@fields);
Condition0%0/2
$fields{$_} ||= ""
l!l
00
MC/DC0%0/1
$fields{$_} ||= ""
$fields{$_}
Truth table0%0/2
A
A= $fields{$_}
Aresult
11
00
879 0 ▶ $fields{uploadid} ||= $self->{upload}{$fields{dist}}{$fields{version}};
Condition0%0/3
$fields{"uploadid"} ||= $self->{"upload"}{$fields{"dist"}}{$fields{"version"}}
l!l&&r!l&&!r
000
MC/DC0%0/2
$fields{"uploadid"} ||= $self->{"upload"}{$fields{"dist"}}{$fields{"version"}}
$fields{"uploadid"} $self->{"upload"}{$fields{"dist"}}{$fields{"version"}}
Truth table0%0/3
A ||= B
A= $fields{"uploadid"}B= $self->{"upload"}{$fields{"dist"}}{$fields{"version"}}
ABresult
1X1
011
000
880  
881 0 my @values = map {$fields{$_}} @fields;
882  
883 0 my %SQL = (
884 'SELECT' => {
885 CPANSTATS => 'SELECT id FROM cpanstats WHERE guid=?',
886 RELEASE => 'SELECT id FROM release_data WHERE guid=?',
887 },
888 'INSERT' => {
889 CPANSTATS => 'INSERT INTO cpanstats (guid,state,postdate,tester,dist,version,platform,perl,osname,osvers,fulldate,type,uploadid) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)',
890 RELEASE => 'INSERT INTO release_data (id,guid,dist,version,oncpan,distmat,perlmat,patched,pass,fail,na,unknown,uploadid) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)',
891 PASSES => 'INSERT IGNORE passreports SET platform=?, osname=?, perl=?, dist=?, postdate=?',
892 },
893 'UPDATE' => {
894 CPANSTATS => 'UPDATE cpanstats SET state=?,postdate=?,tester=?,dist=?,version=?,platform=?,perl=?,osname=?,osvers=?,fulldate=?,type=?,uploadid=? WHERE guid=?',
895 RELEASE => 'UPDATE release_data SET id=?,dist=?,version=?,oncpan=?,distmat=?,perlmat=?,patched=?,pass=?,fail=?,na=?,unknown=?,uploadid=? WHERE guid=?',
896 },
897 );
898  
899 # update the mysql database
900 0 my @rows = $self->{CPANSTATS}->get_query('array',$SQL{SELECT}{CPANSTATS},$values[0]);
901 0 ▶ if(@rows) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rows) { } 0 0 0
902 0 ▶ if($self->{reparse}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'reparse'}) { } 0 0 0
903 0 my ($guid,@update) = @values;
904 0 ▶ if($self->{check}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'check'}) { } 0 0 0
905 0 $self->_log( "CHECK: $SQL{UPDATE}{CPANSTATS},[" . join(',',@update,$guid) . "]\n" );
906 } else {
907 0 $self->{CPANSTATS}->do_query($SQL{UPDATE}{CPANSTATS},@update,$guid);
908 }
909 } else {
910 0 $self->{report}{id} = $rows[0]->[0];
911 0 return 0;
912 }
913 } else {
914 0 ▶ if($self->{check}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'check'}) { } 0 0 0
915 0 $self->_log( "CHECK: $SQL{INSERT}{CPANSTATS},[" . join(',',@values) . "]\n" );
916 } else {
917 0 $self->{report}{id} = $self->{CPANSTATS}->id_query($SQL{INSERT}{CPANSTATS},@values);
918 }
919 }
920  
921 # in check mode, assume the rest happens
922 0 ▶ return 1 if($self->{check});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"check"} 0 0 0
923  
924 # perl version components
925 0 my ($perl,$patch,$devel) = $self->_get_perl_version($fields{perl});
926  
927 # only valid perl5 reports
928 0 ▶ if($self->{report}{type} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"report"}{"type"} == 2) 0 0 0
929 0 $fields{id} = $self->{report}{id};
930  
931 # push page requests
932 # - note we only update the author if this is the *latest* version of the distribution
933 0 ▶ my $author = $self->{report}{pauseid} || $self->_get_author($fields{uploadid},$fields{dist},$fields{version});
Condition0%0/3
$self->{'report'}{'pauseid'} || $self->_get_author($fields{'uploadid'}, $fields{'dist'}, $fields{'version'})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'report'}{'pauseid'} || $self->_get_author($fields{'uploadid'}, $fields{'dist'}, $fields{'version'})
$self->{'report'}{'pauseid'} $self->_get_author($fields{'uploadid'}, $fields{'dist'}, $fields{'version'})
Truth table0%0/3
A || B
A= $self->{'report'}{'pauseid'}B= $self->_get_author($fields{'uploadid'}, $fields{'dist'}, $fields{'version'})
ABresult
1X1
011
000
934 0 ▶ $self->{CPANSTATS}->do_query("INSERT INTO page_requests (type,name,weight,id) VALUES ('author',?,1,?)",$author,$fields{id}) if($author);
Branch: 1 branch
BranchTrueFalseTotal
if $author 0 0 0
935 0 $self->{CPANSTATS}->do_query("INSERT INTO page_requests (type,name,weight,id) VALUES ('distro',?,1,?)",$fields{dist},$fields{id});
936  
937 0 my @rows = $self->{CPANSTATS}->get_query('array',$SQL{SELECT}{RELEASE},$fields{guid});
938 #print STDERR "# select release $SQL{SELECT}{RELEASE},$fields{guid}\n";
939 0 ▶ if(@rows) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rows) { } 0 0 0
940 0 ▶ if($self->{reparse}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"reparse"}) 0 0 0
941 $self->{CPANSTATS}->do_query($SQL{UPDATE}{RELEASE},
942 $fields{id}, # id,
943 $fields{dist},$fields{version}, # dist, version
944  
945 $self->_oncpan($fields{uploadid},$fields{dist},$fields{version}) ? 1 : 2,
946  
947 $fields{version} =~ /_/ ? 2 : 1,
948 $devel ? 2 : 1,
949 $patch ? 2 : 1,
950  
951 $fields{state} eq 'pass' ? 1 : 0,
952 $fields{state} eq 'fail' ? 1 : 0,
953 $fields{state} eq 'na' ? 1 : 0,
954 $fields{state} eq 'unknown' ? 1 : 0,
955  
956 $fields{uploadid},
957  
958 0 ▶ $fields{guid}); # guid
Branch: 8 branches
BranchTrueFalseTotal
$self->_oncpan($fields{'uploadid'}, $fields{'dist'}, $fields{'version'}) ? : 0 0 0
$fields{'version'} =~ /_/ ? : 0 0 0
$devel ? : 0 0 0
$patch ? : 0 0 0
$fields{'state'} eq 'pass' ? : 0 0 0
$fields{'state'} eq 'fail' ? : 0 0 0
$fields{'state'} eq 'na' ? : 0 0 0
$fields{'state'} eq 'unknown' ? : 0 0 0
959 }
960 } else {
961 #print STDERR "# insert release $SQL{INSERT}{RELEASE},$fields[0],$fields[1]\n";
962 $self->{CPANSTATS}->do_query($SQL{INSERT}{RELEASE},
963 $fields{id},$fields{guid}, # id, guid
964 $fields{dist},$fields{version}, # dist, version
965  
966 $self->_oncpan($fields{uploadid},$fields{dist},$fields{version}) ? 1 : 2,
967  
968 $fields{version} =~ /_/ ? 2 : 1,
969 $devel ? 2 : 1,
970 $patch ? 2 : 1,
971  
972 $fields{state} eq 'pass' ? 1 : 0,
973 $fields{state} eq 'fail' ? 1 : 0,
974 $fields{state} eq 'na' ? 1 : 0,
975 $fields{state} eq 'unknown' ? 1 : 0,
976  
977 0 ▶ $fields{uploadid});
Branch: 8 branches
BranchTrueFalseTotal
$self->_oncpan($fields{'uploadid'}, $fields{'dist'}, $fields{'version'}) ? : 0 0 0
$fields{'version'} =~ /_/ ? : 0 0 0
$devel ? : 0 0 0
$patch ? : 0 0 0
$fields{'state'} eq 'pass' ? : 0 0 0
$fields{'state'} eq 'fail' ? : 0 0 0
$fields{'state'} eq 'na' ? : 0 0 0
$fields{'state'} eq 'unknown' ? : 0 0 0
978 }
979 }
980  
981 0 ▶ if($fields{state} eq 'pass') {
Branch: 1 branch
BranchTrueFalseTotal
if ($fields{"state"} eq "pass") 0 0 0
982 0 $fields{perl} =~ s/\s.*//; # only need to know the main release
983 $self->{CPANSTATS}->do_query($SQL{INSERT}{PASSES},
984 $fields{platform},
985 $fields{osname},
986 $fields{perl},
987 $fields{dist},
988 0 $fields{postdate});
989 }
990  
991 0 ▶ if((++$self->{stat_count} % 500) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$self->{"stat_count"} % 500 == 0) 0 0 0
992 0 $self->commit;
993 }
994  
995 0 return 1;
996 }
997  
998 0 ▶sub cache_report {
Subroutine cache_report: not called CC=9 SCAR=45.0
Pod documented
999 0 my $self = shift;
1000 0 ▶ return 0 unless($self->{report}{guid} && $self->{report}{metabase});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"report"}{"guid"} and $self->{"report"}{"metabase"} 0 0 0
Condition0%0/3
$self->{"report"}{"guid"} and $self->{"report"}{"metabase"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"report"}{"guid"} and $self->{"report"}{"metabase"}
$self->{"report"}{"guid"} $self->{"report"}{"metabase"}
Truth table0%0/3
A and B
A= $self->{"report"}{"guid"}B= $self->{"report"}{"metabase"}
ABresult
0X0
100
111
1001  
1002 # in check mode, assume the rest happens
1003 0 ▶ return 1 if($self->{check});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"check"} 0 0 0
1004 0 ▶ return 1 if($self->{localonly});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"localonly"} 0 0 0
1005  
1006 0 my ($json,$data,$fact);
1007  
1008 0 eval { $json = encode_json($self->{report}{metabase}); };
1009 0 eval { $data = $self->{serializer}->serialize("$json"); };
1010 0 ▶ eval { $data = $self->{serializer}->serialize( $self->{report}{metabase} ); } if($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1011 0 eval { $fact = $self->{serializer2}->serialize($self->{fact}); };
1012  
1013 0 ▶ $data ||= '';
Condition0%0/2
$data ||= ""
l!l
00
MC/DC0%0/1
$data ||= ""
$data
Truth table0%0/2
A
A= $data
Aresult
11
00
1014 0 ▶ $fact ||= '';
Condition0%0/2
$fact ||= ""
l!l
00
MC/DC0%0/1
$fact ||= ""
$fact
Truth table0%0/2
A
A= $fact
Aresult
11
00
1015  
1016 $self->{METABASE}->do_query('INSERT IGNORE INTO metabase (guid,id,updated,report,fact) VALUES (?,?,?,?,?)',
1017 0 $self->{report}{guid},$self->{report}{id},$self->{report}{updated},$data,$fact);
1018  
1019 0 ▶ if((++$self->{meta_count} % 500) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$self->{"meta_count"} % 500 == 0) 0 0 0
1020 0 $self->{METABASE}->do_commit;
1021 }
1022  
1023 0 return 1;
1024 }
1025  
1026 0 ▶sub cache_update {
Subroutine cache_update: not called CC=6 SCAR=37.4
Pod documented
1027 0 my $self = shift;
1028 0 ▶ return 0 unless($self->{report}{guid} && $self->{report}{id});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"report"}{"guid"} and $self->{"report"}{"id"} 0 0 0
Condition0%0/3
$self->{"report"}{"guid"} and $self->{"report"}{"id"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"report"}{"guid"} and $self->{"report"}{"id"}
$self->{"report"}{"guid"} $self->{"report"}{"id"}
Truth table0%0/3
A and B
A= $self->{"report"}{"guid"}B= $self->{"report"}{"id"}
ABresult
0X0
100
111
1029  
1030 # in check mode, assume the rest happens
1031 0 ▶ return 1 if($self->{check});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"check"} 0 0 0
1032 0 ▶ return 1 if($self->{localonly});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"localonly"} 0 0 0
1033  
1034 0 $self->{METABASE}->do_query('UPDATE metabase SET id=? WHERE guid=?',$self->{report}{id},$self->{report}{guid});
1035  
1036 0 ▶ if((++$self->{meta_count} % 500) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$self->{"meta_count"} % 500 == 0) 0 0 0
1037 0 $self->{METABASE}->do_commit;
1038 }
1039  
1040 0 return 1;
1041 }
1042  
1043 #----------------------------------------------------------------------------
1044 # Internal Cache Methods
1045  
1046 0 ▶sub load_uploads {
Subroutine load_uploads: not called CC=2 SCAR=17.9
Pod documented
1047 0 my $self = shift;
1048  
1049 0 my @rows = $self->{CPANSTATS}->get_query('hash','SELECT uploadid,dist,version,type FROM uploads');
1050 0 for my $row (@rows) {
1051 0 $self->{oncpan}{$row->{uploadid}} = $row->{type};
1052 0 $self->{upload}{$row->{dist}}{$row->{version}} = $row->{uploadid};
1053 }
1054 }
1055  
1056 0 ▶sub load_authors {
Subroutine load_authors: not called CC=2 SCAR=17.9
Pod documented
1057 0 my $self = shift;
1058  
1059 0 my @rows = $self->{CPANSTATS}->get_query('hash','SELECT author,dist,version,uploadid FROM ixlatest');
1060 0 for my $row (@rows) {
1061 0 $self->{author}{$row->{dist}}{$row->{version}} = $row->{author};
1062 0 $self->{author2}{$row->{uploadid}} = $row->{author};
1063 }
1064 }
1065  
1066 0 ▶sub load_perl_versions {
Subroutine load_perl_versions: not called CC=2 SCAR=17.9
Pod documented
1067 0 my $self = shift;
1068  
1069 0 my @rows = $self->{CPANSTATS}->get_query('hash','SELECT * FROM perl_version');
1070 0 for my $row (@rows) {
1071 $self->{perls}{$row->{version}} = {
1072 perl => $row->{perl},
1073 patch => $row->{patch},
1074 devel => $row->{devel},
1075 0 saved => 1
1076 };
1077 }
1078 }
1079  
1080 0 ▶sub save_perl_versions {
Subroutine save_perl_versions: not called CC=3 SCAR=24.8
Pod documented
1081 0 my $self = shift;
1082  
1083 0 for my $vers (keys %{ $self->{perls} }) {
1084 0 ▶ next if($self->{perls}{$vers}{saved});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"perls"}{$vers}{"saved"} 0 0 0
1085 $self->{CPANSTATS}->do_query("INSERT INTO perl_version (version,perl,patch,devel) VALUES (?,?,?,?)",
1086 0 $vers, $self->{perls}{$vers}{perl}, $self->{perls}{$vers}{patch}, $self->{perls}{$vers}{devel});
1087 }
1088 }
1089  
1090 #----------------------------------------------------------------------------
1091 # Private Methods
1092  
1093 0 ▶sub _consume_reports {
Subroutine _consume_reports: not called CC=24 SCAR=64.0
1094 0 my ($self,$maxdate,$dataset) = @_;
1095  
1096 0 for my $data (@$dataset) {
1097 0 my $start = $self->_get_createdate( $data->{gstart}, $data->{dstart} );
1098 0 my $end = $self->_get_createdate( $data->{gend}, $data->{dend} );
1099  
1100 0 ▶ unless($start && $end) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($start and $end) 0 0 0
Condition0%0/3
$start and $end
!ll&&!rl&&r
000
MC/DC0%0/2
$start and $end
$start $end
Truth table0%0/3
A and B
A= $startB= $end
ABresult
0X0
100
111
1101 0 ▶ $start ||= '';
Condition0%0/2
$start ||= ""
l!l
00
MC/DC0%0/1
$start ||= ""
$start
Truth table0%0/2
A
A= $start
Aresult
11
00
1102 0 ▶ $end ||= '';
Condition0%0/2
$end ||= ""
l!l
00
MC/DC0%0/1
$end ||= ""
$end
Truth table0%0/2
A
A= $end
Aresult
11
00
1103 0 $self->_log("BAD DATES: start=$start, end=$end [missing dates]\n");
1104 0 next;
1105 }
1106 0 ▶ if($start ge $end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start ge $end) 0 0 0
1107 0 $self->_log("BAD DATES: start=$start, end=$end [end before start]\n");
1108 0 next;
1109 }
1110 # if($end gt $maxdate) {
1111 # $self->_log("BAD DATES: start=$start, end=$end [exceeds $maxdate]\n");
1112 # next;
1113 # }
1114  
1115 0 $self->_log("LOOP: start=$start, end=$end\n");
1116  
1117 0 ($self->{processed},$self->{stored},$self->{cached}) = (0,0,0);
1118  
1119 # what guids do we already have?
1120 0 my $sql = 'SELECT guid FROM metabase WHERE updated >= ? AND updated <= ? ORDER BY updated asc';
1121 0 my @guids = $self->{METABASE}->get_query('hash',$sql,$data->{dstart},$data->{dend});
1122 0 my %guids = map {$_->{guid} => 1} @guids;
1123  
1124 # note that because Amazon's SimpleDB can return odd entries out of
1125 # sync, we have to look at previous entries to ensure we are starting
1126 # from the right point
1127 0 my ($update,$prev,$last) = ($start,$start,$start);
1128 0 my @times = ();
1129  
1130 0 my $prior = [ 0, 0 ];
1131 0 my $saved = 0;
1132 0 ▶ while($update lt $end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($update lt $end) 0 0 0
1133 0 $self->_log("UPDATE: update=$update, end=$end, saved=$saved, guids=".(scalar(@guids))."\n");
1134  
1135 # get list of guids from last update date
1136 0 my $guids = $self->get_next_guids($update,$end);
1137 0 ▶ last unless($guids);
Branch: 1 branch
BranchTrueFalseTotal
unless $guids 0 0 0
1138  
1139 0 @guids = grep { !$guids{$_} } @$guids;
1140 0 ▶ last unless(@guids);
Branch: 1 branch
BranchTrueFalseTotal
unless @guids 0 0 0
1141 0 ▶ last if($prior->[0] eq $guids[0] && $prior->[1] eq $guids[-1]); # prevent an endless loop
Branch: 1 branch
BranchTrueFalseTotal
if $prior->[0] eq $guids[0] and $prior->[1] eq $guids[-1] 0 0 0
Condition0%0/3
$prior->[0] eq $guids[0] and $prior->[1] eq $guids[-1]
!ll&&!rl&&r
000
MC/DC0%0/2
$prior->[0] eq $guids[0] and $prior->[1] eq $guids[-1]
$prior->[0] eq $guids[0] $prior->[1] eq $guids[-1]
Truth table0%0/3
A and B
A= $prior->[0] eq $guids[0]B= $prior->[1] eq $guids[-1]
ABresult
0X0
100
111
1142 0 $prior = [ $guids[0], $guids[-1] ];
1143  
1144 0 $self->_log("UPDATE: todo guids=".(scalar(@guids))."\n");
1145  
1146 0 my $current = $update;
1147 0 for my $guid (@guids) {
1148 # don't process too far
1149 0 ▶ shift @times if(@times > 9); # one off
Branch: 1 branch
BranchTrueFalseTotal
if @times > 9 0 0 0
1150 0 ▶ push @times, [ $current, (_date_diff($end,$current) <= 0 ? 0 : 1) ]; # one on ... max 10
Branch: 1 branch
BranchTrueFalseTotal
_date_diff($end, $current) <= 0 ? : 0 0 0
1151  
1152 0 my $times = 0;
1153 0 $times += $_->[1] for(@times);
1154 0 ▶ last if($times == 10); # stop if all greater than end
Branch: 1 branch
BranchTrueFalseTotal
if $times == 10 0 0 0
1155  
1156 # okay process
1157 0 $self->_log("GUID [$guid]");
1158  
1159 0 $self->{processed}++;
1160  
1161 0 ▶ if(my $time = $self->already_saved($guid)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $time = $self->already_saved($guid)) 0 0 0
1162 0 $self->_log(".. already saved [$time]\n");
1163 0 $current = $time;
1164 0 $saved++;
1165 0 next;
1166 }
1167  
1168 0 ▶ if(my $report = $self->get_fact($guid)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $report = $self->get_fact($guid)) { } 0 0 0
1169 0 $current = $report->{metadata}{core}{update_time};
1170 0 $self->{report}{guid} = $guid;
1171 0 ▶ next if($self->parse_report(report => $report)); # true if invalid report
Branch: 1 branch
BranchTrueFalseTotal
if $self->parse_report("report", $report) 0 0 0
1172  
1173 0 ▶ if($self->store_report()) { $self->_log(".. stored"); $self->{stored}++; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->store_report) { } 0 0 0
1174 0 else { $self->_log(".. already stored"); }
1175 0 ▶ if($self->cache_report()) { $self->_log(".. cached\n"); $self->{cached}++; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cache_report) { } 0 0 0
1176 0 else { $self->_log(".. bad cache data\n"); }
1177 } else {
1178 0 $self->_log(".. FAIL\n");
1179 }
1180 }
1181  
1182 0 $update = $times[0]->[0];
1183  
1184 0 $self->commit();
1185 }
1186  
1187 0 $self->commit();
1188 0 ▶ my $invalid = $self->{invalid} ? scalar(@{$self->{invalid}}) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'invalid'} ? : 0 0 0
1189 0 my $stop = localtime(time);
1190 0 $self->_log("MARKER: processed=$self->{processed}, stored=$self->{stored}, cached=$self->{cached}, invalid=$invalid, start=$start, stop=$stop\n");
1191 }
1192  
1193 # only email invalid reports during the generate process
1194 0 ▶ $self->_send_email() if($self->{invalid});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"invalid"} 0 0 0
1195 }
1196  
1197 0 ▶sub _get_perl_version {
Subroutine _get_perl_version: not called CC=4 SCAR=30.0
1198 0 my $self = shift;
1199 0 my $vers = shift;
1200  
1201 0 ▶ unless($self->{perls}{$vers}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"perls"}{$vers}) 0 0 0
1202 0 ▶ my $patch = $vers =~ /^5.(7|9|[1-9][13579])/ ? 1 : 0, # odd numbers now mark development releases
Branch: 2 branches
BranchTrueFalseTotal
$vers =~ /^5.(7|9|[1-9][13579])/ ? : 0 0 0
$vers =~ /(RC\d+|patch)/ ? : 0 0 0
1203 my $devel = $vers =~ /(RC\d+|patch)/ ? 1 : 0,
1204 my ($perl) = $vers =~ /(5\.\d+(?:\.\d+)?)/;
1205  
1206 0 $self->{perls}{$vers} = {
1207 perl => $perl,
1208 patch => $patch,
1209 devel => $devel,
1210 saved => 0
1211 };
1212 }
1213  
1214 0 return $self->{perls}{$vers}{perl}, $self->{perls}{$vers}{patch}, $self->{perls}{$vers}{devel};
1215 }
1216  
1217 0 ▶sub _get_guid_list {
Subroutine _get_guid_list: not called CC=9 SCAR=45.0
1218 0 my ($self,$guid,$file) = @_;
1219 0 my (@ids,@guids);
1220  
1221 # we're only parsing one id
1222 0 ▶ if($guid) {
Branch: 2 branches
BranchTrueFalseTotal
if ($guid) { } 0 0 0
elsif ($file) { } 0 0 0
1223 0 ▶ if($guid =~ /^\d+$/) { push @ids, $guid }
Branch: 1 branch
BranchTrueFalseTotal
if ($guid =~ /^\d+$/) { } 0 0 0
1224 0 else { push @guids, $guid }
1225 } elsif($file) {
1226 0 ▶ my $fh = IO::File->new($file,'r') or die "Cannot read file [$file]: $!";
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new($file, "r") or die "Cannot read file [$file]: $!" 0 0 0
1227 0 ▶ while(<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
1228 0 chomp;
1229 0 my ($num) = (m/^([\da-z-]+)/i);
1230 0 ▶ if($num =~ /^\d+$/) { push @ids, $num }
Branch: 1 branch
BranchTrueFalseTotal
if ($num =~ /^\d+$/) { } 0 0 0
1231 0 else { push @guids, $num }
1232 }
1233 0 $fh->close;
1234 } else {
1235 0 return;
1236 }
1237  
1238 # turn ids into guids
1239 0 ▶ if(@ids) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ids) 0 0 0
1240 0 my @rows = $self->{CPANSTATS}->get_query('array','SELECT guid FROM cpanstats WHERE id IN ('.join(',',@ids).')');
1241 0 push @guids, $_->[0] for(@rows);
1242 }
1243  
1244 0 my %guids = map {$_ => 1} @guids;
1245 0 my @list = keys %guids;
1246 0 return @list;
1247 }
1248  
1249 0 ▶sub _get_createdate {
Subroutine _get_createdate: not called CC=7 SCAR=40.3
1250 0 my ($self,$guid,$date) = @_;
1251  
1252 0 ▶ return unless($guid || $date);
Branch: 1 branch
BranchTrueFalseTotal
unless $guid or $date 0 0 0
Condition0%0/3
$guid or $date
l!l&&r!l&&!r
000
MC/DC0%0/2
$guid or $date
$guid $date
Truth table0%0/3
A or B
A= $guidB= $date
ABresult
1X1
011
000
1253 0 ▶ if($guid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($guid) 0 0 0
1254 0 my @rows = $self->{METABASE}->get_query('hash','SELECT updated FROM metabase WHERE guid=?',$guid);
1255 0 ▶ $date = $rows[0]->{updated} if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
1256 }
1257  
1258 0 ▶ return unless($date && $date =~ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $date and $date =~ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/ 0 0 0
Condition0%0/3
$date and $date =~ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/
!ll&&!rl&&r
000
MC/DC0%0/2
$date and $date =~ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/
$date $date =~ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/
Truth table0%0/3
A and B
A= $dateB= $date =~ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/
ABresult
0X0
100
111
1259 0 return $date;
1260 }
1261  
1262 0 ▶sub _get_tester {
Subroutine _get_tester: not called CC=11 SCAR=48.8
1263 0 my ($self,$creator) = @_;
1264 0 ▶ return $testers{$creator} if($testers{$creator});
Branch: 1 branch
BranchTrueFalseTotal
if $testers{$creator} 0 0 0
1265  
1266 0 my $profile = Metabase::Resource->new( $creator );
1267 0 ▶ return $creator unless($profile);
Branch: 1 branch
BranchTrueFalseTotal
unless $profile 0 0 0
1268  
1269 0 my $user;
1270 0 eval { $user = $self->{librarian}->extract( $profile->guid ) };
1271 0 ▶ return $creator unless($user);
Branch: 1 branch
BranchTrueFalseTotal
unless $user 0 0 0
1272  
1273 0 my ($name,@emails);
1274 0 for my $fact ($user->facts()) {
1275 0 ▶ if(ref $fact eq 'Metabase::User::EmailAddress') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $fact eq 'Metabase::User::EmailAddress') { } 0 0 0
elsif (ref $fact eq 'Metabase::User::FullName') { } 0 0 0
1276 0 push @emails, $fact->{content};
1277 } elsif(ref $fact eq 'Metabase::User::FullName') {
1278 0 $name = encode_entities($fact->{content});
1279 }
1280 }
1281  
1282 0 ▶ $name ||= 'NONAME'; # shouldn't happen, but allows for checks later
Condition0%0/2
$name ||= "NONAME"
l!l
00
MC/DC0%0/1
$name ||= "NONAME"
$name
Truth table0%0/2
A
A= $name
Aresult
11
00
1283  
1284 0 for my $em (@emails) {
1285 0 $self->{METABASE}->do_query('INSERT INTO testers_email (resource,fullname,email) VALUES (?,?,?)',$creator,$name,$em);
1286 }
1287  
1288 0 ▶ $testers{$creator} = @emails ? $emails[0] : $creator;
Branch: 1 branch
BranchTrueFalseTotal
@emails ? : 0 0 0
1289 0 ▶ $testers{$creator} =~ s/\'/''/g if($testers{$creator});
Branch: 1 branch
BranchTrueFalseTotal
if $testers{$creator} 0 0 0
1290 0 return $testers{$creator};
1291 }
1292  
1293 0 ▶sub _get_author {
Subroutine _get_author: not called CC=4 SCAR=30.0
1294 0 my ($self,$upid,$dist,$vers) = @_;
1295  
1296 0 ▶ my $author = $self->{author2}{$upid} || '';
Condition0%0/2
$self->{'author2'}{$upid} || ''
l!l
00
MC/DC0%0/1
$self->{'author2'}{$upid} || ''
$self->{'author2'}{$upid}
Truth table0%0/2
A
A= $self->{'author2'}{$upid}
Aresult
11
00
1297 0 ▶ $author ||= $self->{author}{$dist}{$vers} || '';
Condition0%0/5
$author ||= $self->{"author"}{$dist}{$vers} || ""
l!l&&r!l&&!r
000
$self->{'author'}{$dist}{$vers} || ''
l!l
00
MC/DC0%0/2
$author ||= $self->{"author"}{$dist}{$vers} || ""
$author $self->{'author'}{$dist}{$vers}
Truth table0%0/3
A ||= B
A= $authorB= $self->{'author'}{$dist}{$vers}
ABresult
1X1
011
000
1298  
1299 0 return $author;
1300 }
1301  
1302 0 ▶sub _valid_field {
Subroutine _valid_field: not called CC=2 SCAR=17.9
1303 0 my ($self,$id,$name,$value) = @_;
1304 0 ▶ return 1 if(defined $value);
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 0 0 0
1305 0 $self->_log(" . [$id] ... missing field: $name\n");
1306 0 return 0;
1307 }
1308  
1309 0 ▶sub _get_lastid {
Subroutine _get_lastid: not called CC=3 SCAR=24.8
1310 0 my $self = shift;
1311  
1312 0 my @rows = $self->{METABASE}->get_query('array',"SELECT MAX(id) FROM metabase");
1313 0 ▶ return 0 unless(@rows);
Branch: 1 branch
BranchTrueFalseTotal
unless @rows 0 0 0
1314 0 ▶ return $rows[0]->[0] || 0;
Condition0%0/2
$rows[0][0] || 0
l!l
00
MC/DC0%0/1
$rows[0][0] || 0
$rows[0][0]
Truth table0%0/2
A
A= $rows[0][0]
Aresult
11
00
1315 }
1316  
1317 0 ▶sub _oncpan {
Subroutine _oncpan: not called CC=4 SCAR=30.0
1318 0 my ($self,$upid,$dist,$vers) = @_;
1319
1320 0 ▶ $upid ||= $self->{upload}{$dist}{$vers};
Condition0%0/3
$upid ||= $self->{"upload"}{$dist}{$vers}
l!l&&r!l&&!r
000
MC/DC0%0/2
$upid ||= $self->{"upload"}{$dist}{$vers}
$upid $self->{"upload"}{$dist}{$vers}
Truth table0%0/3
A ||= B
A= $upidB= $self->{"upload"}{$dist}{$vers}
ABresult
1X1
011
000
1321 0 my $type = $self->{oncpan}{$upid};
1322  
1323 0 ▶ return 1 unless($type); # assume it's a new release
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 0 0
1324 0 ▶ return 0 if($type eq 'backpan'); # on backpan only
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "backpan" 0 0 0
1325 0 return 1; # on cpan or new upload
1326 }
1327  
1328 0 ▶sub _osname {
Subroutine _osname: not called CC=3 SCAR=24.8
1329 0 my $self = shift;
1330 0 ▶ my $name = shift || return '';
Condition0%0/2
shift() || (return '')
l!l
00
MC/DC0%0/1
shift() || (return '')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1331  
1332 0 my $lname = lc $name;
1333 0 my $uname = uc $name;
1334 0 ▶ $self->{OSNAMES}{$lname} ||= do {
Condition0%0/3
$self->{"OSNAMES"}{$lname} ||= do { $self->{"CPANSTATS"}->do_query("INSERT INTO osname (osname,ostitle) VALUES ('${name}','${uname}')"); $uname }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"OSNAMES"}{$lname} ||= do { $self->{"CPANSTATS"}->do_query("INSERT INTO osname (osname,ostitle) VALUES ('${name}','${uname}')"); $uname }
$self->{"OSNAMES"}{$lname} do { $self->{"CPANSTATS"}->do_query("INSERT INTO osname (osname,ostitle) VALUES ('${name}','${uname}')"); $uname }
Truth table0%0/3
A ||= B
A= $self->{"OSNAMES"}{$lname}B= do { $self->{"CPANSTATS"}->do_query("INSERT INTO osname (osname,ostitle) VALUES ('${name}','${uname}')"); $uname }
ABresult
1X1
011
000
1335 0 $self->{CPANSTATS}->do_query(qq{INSERT INTO osname (osname,ostitle) VALUES ('$name','$uname')});
1336 0 $uname;
1337 };
1338  
1339 0 return $self->{OSNAMES}{$lname};
1340 }
1341  
1342 0 ▶sub _check_arch_os {
Subroutine _check_arch_os: not called CC=5 SCAR=34.0
1343 0 my $self = shift;
1344  
1345 0 my $text = $self->_platform_to_osname($self->{report}{platform});
1346 #print STDERR "_check: text=$text\n";
1347 #print STDERR "_check: platform=$self->{report}{platform}\n";
1348 #print STDERR "_check: osname=$self->{report}{osname}\n";
1349 0 ▶ return if($text && $self->{report}{osname} && lc $text eq lc $self->{report}{osname});
Branch: 1 branch
BranchTrueFalseTotal
if $text and $self->{"report"}{"osname"} and lc $text eq lc $self->{"report"}{"osname"} 0 0 0
Condition0%0/6
$text and $self->{"report"}{"osname"} and lc $text eq lc $self->{"report"}{"osname"}
!ll&&!rl&&r
000
$text and $self->{"report"}{"osname"}
!ll&&!rl&&r
000
MC/DC0%0/3
$text and $self->{"report"}{"osname"} and lc $text eq lc $self->{"report"}{"osname"}
$text $self->{"report"}{"osname"} lc $text eq lc $self->{"report"}{"osname"}
Truth table0%0/4
A and B and C
A= $textB= $self->{"report"}{"osname"}C= lc $text eq lc $self->{"report"}{"osname"}
ABCresult
0XX0
10X0
1100
1111
1350  
1351 #print STDERR "_check: metabase=".Dumper($self->{report}{metabase})."\n";
1352 0 my $textreport = $self->{report}{metabase}{'CPAN::Testers::Fact::LegacyReport'}{content}{textreport};
1353 0 $textreport =~ s/\\n/\n/g; # newlines may be escaped
1354  
1355 # create a fake mail, as CTC::Article parses a mail like text block
1356 0 my $mail = <<EMAIL;
1357 From: fake\@example.com
1358 To: fake\@example.com
1359 Subject: PASS Fake-0.01
1360 Date: 01-01-2010 01:01:01 Z
1361  
1362 $textreport
1363 EMAIL
1364 0 ▶ my $object = CPAN::Testers::Common::Article->new( $mail ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $object = "CPAN::Testers::Common::Article"->new($mail) or return 0 0 0
1365 0 $object->parse_report();
1366  
1367 0 $self->{report}{osname} = $object->osname;
1368 0 $self->{report}{platform} = $object->archname;
1369 }
1370  
1371 0 ▶sub _platform_to_osname {
Subroutine _platform_to_osname: not called CC=6 SCAR=37.4
1372 0 my $self = shift;
1373 0 ▶ my $arch = shift || return '';
Condition0%0/2
shift() || (return '')
l!l
00
MC/DC0%0/1
shift() || (return '')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1374  
1375 0 ▶ $OSNAMES = join('|',keys %{$self->{OSNAMES}}) if(keys %{$self->{OSNAMES}});
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$$self{"OSNAMES"};} 0 0 0
1376  
1377 0 ▶ return $1 if($arch =~ /($OSNAMES)/i);
Branch: 1 branch
BranchTrueFalseTotal
if $arch =~ /($OSNAMES)/i 0 0 0
1378  
1379 0 for my $rx (keys %{ $self->{OSNAMES} }) {
1380 0 ▶ return $self->{OSNAMES}{$rx} if($arch =~ /$rx/i);
Branch: 1 branch
BranchTrueFalseTotal
if $arch =~ /$rx/i 0 0 0
1381 }
1382  
1383 0 return '';
1384 }
1385  
1386 0 ▶sub _send_email {
Subroutine _send_email: not called CC=3 SCAR=24.8
1387 0 my $self = shift;
1388 0 my $t = localtime;
1389 0 my $DATE = $t->strftime("%a, %d %b %Y %H:%M:%S +0000");
1390 0 $DATE =~ s/\s+$//;
1391 0 my $INVALID = join("\n",@{$self->{invalid}});
1392 0 $self->_log("INVALID:\n$INVALID\n");
1393  
1394 0 for my $admin (@{$self->{admins}}) {
1395 0 my $cmd = qq!| $HOW $admin!;
1396  
1397 0 my $body = $HEAD . $BODY;
1398 0 $body =~ s/FROM/$FROM/g;
1399 0 $body =~ s/EMAIL/$admin/g;
1400 0 $body =~ s/DATE/$DATE/g;
1401 0 $body =~ s/INVALID/$INVALID/g;
1402  
1403 0 ▶ if(my $fh = IO::File->new($cmd)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fh = 'IO::File'->new($cmd)) { } 0 0 0
1404 0 print $fh $body;
1405 0 $fh->close;
1406 0 $self->_log(".. MAIL SEND - SUCCESS - $admin\n");
1407 } else {
1408 0 $self->_log(".. MAIL SEND - FAILED - $admin\n");
1409 }
1410 }
1411 }
1412  
1413 4 ▶sub _date_diff {
Subroutine _date_diff: called CC=3 SCAR=11.0
1414 4 my ($date1,$date2) = @_;
1415  
1416 4 my (@dt1) = $date1 =~ /(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)Z/;
1417 4 my (@dt2) = $date2 =~ /(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)Z/;
1418  
1419 4 ▶ return -1 unless(@dt1 && @dt2);
Branch: 1 branch
BranchTrueFalseTotal
unless @dt1 and @dt2 1 3 4
Condition66%2/3
@dt1 and @dt2
!ll&&!rl&&r
013
MC/DC50%1/2
@dt1 and @dt2
@dt1 @dt2
Truth table66%2/3
A and B
A= @dt1B= @dt2
ABresult
0X0
100
111
1420  
1421 3 my $dt1 = DateTime->new( year => $dt1[0], month => $dt1[1], day => $dt1[2], hour => $dt1[3], minute => $dt1[4], second => $dt1[5], time_zone => 'UTC' )->epoch;
1422 3 my $dt2 = DateTime->new( year => $dt2[0], month => $dt2[1], day => $dt2[2], hour => $dt2[3], minute => $dt2[4], second => $dt2[5], time_zone => 'UTC' )->epoch;
1423  
1424 3 return $dt2 - $dt1;
1425 }
1426  
1427 0 ▶sub _log {
Subroutine _log: not called CC=5 SCAR=34.0
1428 0 my $self = shift;
1429 0 ▶ my $log = $self->{logfile} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $log = $self->{"logfile"} or return 0 0 0
1430 0 ▶ mkpath(dirname($log)) unless(-f $log);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $log 0 0 0
1431 0 ▶ my $fh = IO::File->new($log,'a+') or die "Cannot append to log file [$log]: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new($log, "a+") or die "Cannot append to log file [$log]: $!\n" 0 0 0
1432 0 ▶ print $fh $self->{msg} if($self->{msg});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"msg"} 0 0 0
1433 0 print $fh @_;
1434 0 $fh->close;
1435 0 $self->{msg} = '';
1436 }
1437  
1438 9 1;
1439  
1440 __END__
↑ Summary