Labyrinth/Plugin/CPAN/Builder.pm

filter: Statementstmt 96.9% 64 / 66 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 22 / 22 Podpod n/a totaltotal 97.7% 86 / 88 CC 1 SCAR 0.1
CC
1
Cov
97%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Labyrinth/Plugin/CPAN/Report.pm ↑ Summary CPAN/Testers/WWW/Reports.pm »
1 package Labyrinth::Plugin::CPAN::Builder;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 $VERSION = '3.59';
8  
9 =head1 NAME
10  
11 Labyrinth::Plugin::CPAN::Builder - Plugin to build the static files that drive the dynamic site.
12  
13 =cut
14  
15 #----------------------------------------------------------------------------
16 # Libraries
17  
18 4 ▶use base qw(Labyrinth::Plugin::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 4 ▶use Labyrinth::Audit;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶use Labyrinth::DTUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 ▶use Labyrinth::MLUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 ▶use Labyrinth::Mailer;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 4 ▶use Labyrinth::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 4 ▶use Labyrinth::Support;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 4 ▶use Labyrinth::Variables;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 4 ▶use Labyrinth::Writer;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 4 ▶use Labyrinth::Plugin::CPAN;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 4 ▶use Labyrinth::Plugin::Articles::Site;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 4 ▶use Clone qw(clone);
Subroutine BEGIN: called CC=1 SCAR=0.0
33 4 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 4 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 4 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 4 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 #use Sort::Versions;
38 4 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 4 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 4 ▶use XML::RSS;
Subroutine BEGIN: called CC=1 SCAR=2.6
41 #use YAML::XS;
42 use version;
43  
44 #use Devel::Size qw(total_size);
45  
46 #----------------------------------------------------------------------------
47 # Variables
48  
49 my $RECENT = 200;
50  
51 #----------------------------------------------------------------------------
52 # Public Interface Functions
53  
54 =head1 METHODS
55  
56 =head2 Public Interface Methods
57  
58 =over 4
59  
60 =item BasePages
61  
62 Regenerates all site pages.
63  
64 =item Process
65  
66 Simple control process.
67  
68 =item IndexPages
69  
70 Rebuilds the index pages for each author and distribution letter directory.
71  
72 =item RemovePages
73  
74 Master controller for removing reports from author and distribution pages.
75  
76 =item RemoveAuthorPages
77  
78 Routine for removing reports from author pages.
79  
80 =item RemoveDistroPages
81  
82 Routine for removing reports from distribution pages.
83  
84 =item AuthorPages
85  
86 Rebuilds a named author page.
87  
88 =item DistroPages
89  
90 Rebuilds a named distribution page.
91  
92 =item StatsPages
93  
94 Rebuilds the stats pages for pass matrix.
95  
96 =item RecentPage
97  
98 Regenerates the recent page, and associated files.
99  
100 =back
101  
102 =cut
103  
104 sub BasePages {
105 my $cache = sprintf "%s/static", $settings{webdir};
106 mkpath($cache);
107 $tvars{cache} = $cache;
108 $tvars{static} = 1;
109  
110 $tvars{content} = "content/welcome.html";
111 my $text = Transform( 'cpan/layout-static.html', \%tvars );
112 overwrite_file( $cache . '/index.html', $text );
113  
114 my $site = Labyrinth::Plugin::Articles::Site->new();
115 $tvars{content} = "articles/arts-item.html";
116 for my $page (qw(help about)) {
117 $cgiparams{'name'} = $page;
118 $site->Item();
119 $text = Transform( 'cpan/layout-static.html', \%tvars );
120 overwrite_file( "$cache/page/$page.html", $text );
121 }
122 }
123  
124 sub Process {
125 my ($self,$progress,$type) = @_;
126  
127 # check whether we are running split or combined queries
128 my $types = $type ? "'$type'" : "'author','distro'";
129  
130 my $cpan = Labyrinth::Plugin::CPAN->new();
131 $cpan->Configure();
132  
133 my $olderhit = 0;
134 my $quickhit = 1;
135 while(1) {
136 my $cnt = IndexPages($cpan,$dbi,$progress,$type);
137 $cnt += RemovePages($cpan,$dbi,$progress,$type);
138  
139 # shouldn't really hard code these :)
140 my ($query,$loop,$limit) = ('GetRequests',10,10);
141 ($query,$loop,$limit) = ('GetOlderRequests',1,100) if($quickhit == 1);
142 ($query,$loop,$limit) = ('GetSmallRequests',2,10) if($quickhit == 3);
143 ($query,$loop,$limit) = ('GetLargeRequests',2,25) if($quickhit == 5); # typically these are long running author searches
144  
145 my %names;
146 for(1..$loop) {
147 my @rows = $dbi->GetQuery('hash',$query,{types => $types, limit => $limit});
148 last unless(@rows);
149  
150 for my $row (@rows) {
151 next unless(defined $row->{type});
152 next if($names{$row->{type}} && $names{$row->{type}}{$row->{name}});
153 if(defined $progress) {
154 $progress->( ".. processing $row->{type} $row->{name} => $row->{count} $row->{total}" );
155 }
156 if($row->{type} eq 'author') { AuthorPages($cpan,$dbi,$row->{name},$progress) }
157 else { DistroPages($cpan,$dbi,$row->{name},$progress) }
158  
159 $names{$row->{type}}{$row->{name}} = 1; # prevent repeating the same update too quickly.
160 $cnt++;
161 }
162 }
163  
164 my $req = _request_count($dbi);
165 $progress->( "Processed $cnt pages, $req requests remaining." ) if(defined $progress);
166 #sleep(300) if($cnt == 0 || $req == 0);
167 last if($cnt == 0 || $req == 0);
168  
169 my $age = _request_oldest($dbi);
170 my @row = $dbi->GetQuery('hash','GetLargeRequests',{types => $types, limit => 1});
171 my $sum = $row[0]->{total};
172 my $num = $row[0]->{count};
173  
174 $quickhit =
175 $sum > $settings{buildlevel4} # very high sum of requests for one request type
176 ? 5
177 : $num > $settings{buildlevel5} # very high num of requests for one request type
178 ? 5
179 : $age > $settings{agelimit1} # requests older than x days take priority
180 ? 1
181 : $req < $settings{buildlevel1} # low amount of requests
182 ? 1
183 : $req < $settings{buildlevel2} # medium level of requests
184 ? ++$quickhit % 2
185 : $req < $settings{buildlevel3} # high level of requests
186 ? ++$quickhit % 4
187 : $age > $settings{agelimit2} # older than x days
188 ? 1
189 : ++$quickhit % 6; # very high level of requests
190 }
191 }
192  
193 sub IndexPages {
194 my ($cpan,$dbi,$progress,$type) = @_;
195  
196 # check whether we are running split or combined queries
197 my $types = "'ixauth','ixdist'";
198 $types = "'ixauth'" if($type && $type eq 'author');
199 $types = "'ixdist'" if($type && $type eq 'distro');
200  
201 my @index = $dbi->GetQuery('hash','GetIndexRequests',{types => $types});
202 for my $index (@index) {
203 my ($type,@list);
204  
205 $progress->( ".. processing $index->{type} $index->{name}" ) if(defined $progress);
206  
207 if($index->{type} eq 'ixauth') {
208 my @rows = $dbi->GetQuery('hash','GetAuthors',"$index->{name}%");
209 @list = map {$_->{author}} @rows;
210 $type = 'author';
211 } else {
212 my @rows = $dbi->GetQuery('hash','GetDistros',"$index->{name}%");
213 @list = map {$_->{dist}} @rows;
214 $type = 'distro';
215 }
216  
217 my $cache = sprintf "%s/static/%s/%s", $settings{webdir}, $type, substr($index->{name},0,1);
218 mkpath($cache);
219  
220 $tvars{letter} = $index->{name};
221 $tvars{cache} = $cache;
222 $tvars{content} = "cpan/$type-list.html";
223 $tvars{list} = \@list if(@list);
224 my $text = Transform( 'cpan/layout-static.html', \%tvars );
225 overwrite_file( $cache . '/index.html', $text );
226  
227 if($type eq 'distro') {
228 $cache = sprintf "%s/stats/%s/%s", $settings{webdir}, $type, substr($index->{name},0,1);
229 mkpath($cache);
230  
231 my $destfile = "$cache/index.html";
232 #$progress->( ".. processing $index->{type} $index->{name} - $destfile" ) if(defined $progress);
233 $tvars{content} = 'cpan/stats-distro-index.html';
234 $tvars{cache} = $cache;
235 $text = Transform( 'cpan/layout-stats-static.html', \%tvars );
236 overwrite_file( $cache . '/index.html', $text );
237 }
238  
239 # remove requests
240 $dbi->DoQuery('DeletePageRequests',{ids => '0'},$index->{type},$index->{name});
241 }
242  
243 return scalar(@index);
244 }
245  
246 sub RemovePages {
247 my ($cpan,$dbi,$progress,$type) = @_;
248  
249 # check whether we are running split or combined queries
250 my $types = "'rmauth','rmdist'";
251 $types = "'rmauth'" if($type && $type eq 'author');
252 $types = "'rmdist'" if($type && $type eq 'distro');
253  
254 my @rows = $dbi->GetQuery('hash','GetRequests',{types => $types, limit => 20});
255 return 0 unless(@rows);
256  
257 my @index = $dbi->GetQuery('hash','GetIndexRequests',{types => $types});
258 for my $index (@index) {
259 my ($type,@list);
260  
261 $progress->( ".. processing $index->{type} $index->{name}" ) if(defined $progress);
262  
263 if($index->{type} eq 'rmauth') {
264 # 2016-04-21 = Barbie - temporarily suspended line below to allow author pages to generate
265 # seems to be a bug picking up UUID for PSIXDISTS :(
266 RemoveAuthorPages($cpan,$dbi,$progress,$index->{name});
267 } else {
268 RemoveDistroPages($cpan,$dbi,$progress,$index->{name});
269 }
270 }
271 }
272  
273 # note $name is NOT the author name, but the dist name! need to get the reports to track version and then author
274  
275 sub RemoveAuthorPages {
276 my ($cpan,$dbi,$progress,$name) = @_;
277 my (%remove,%author,@reports);
278 my $fail = 0;
279  
280 # get ids from the page requests
281 my @requests = $dbi->GetQuery('hash','GetRequestIDs',{names => $name},'rmauth');
282 my %requests = map { $_->{id} => 1 } grep { $_->{id} } @requests;
283  
284 return unless(keys %requests);
285 push my @ids, keys %requests;
286  
287 my $next = $dbi->Iterator('hash','GetReportsByIDs',{ids=>join(',',@ids)});
288 while(my $row = $next->()) {
289 my @latest = $dbi->GetQuery('hash','CheckLatest',$row->{dist},$row->{version});
290 next unless(@latest);
291 $author{$latest[0]->{author}}++;
292 $remove{$row->{dist}}{uc $row->{state}}++;
293 }
294  
295 for my $author (keys %author) {
296 my $cache = sprintf "%s/static/author/%s", $settings{webdir}, substr($author,0,1);
297 my $destfile = "$cache/$author.json";
298  
299 try {
300 # load JSON, if we have one
301 if(-f $destfile) {
302 $progress->( ".. processing rmauth $author $name (cleaning JSON file)" ) if(defined $progress);
303 my $data = read_file($destfile);
304 $progress->( ".. processing rmauth $author $name (read JSON file)" ) if(defined $progress);
305 my $store;
306 eval { $store = decode_json($data) };
307 $progress->( ".. processing rmauth $author $name (decoded JSON data)" ) if(defined $progress);
308 if(!$@ && $store) {
309 for my $row (@$store) {
310 next if($requests{$row->{id}}); # filter out requests
311  
312 push @reports, $row;
313 }
314 }
315 overwrite_file( $destfile, _make_json( \@reports ) );
316 }
317  
318 # clean the summary, if we have one
319 my @summary = $dbi->GetQuery('hash','GetAuthorSummary',$author);
320 if(@summary) {
321 $progress->( ".. processing rmauth $author $name (cleaning summary) " . scalar(@summary) . ' ' . ($summary[0] && $summary[0]->{dataset} ? 'true' : 'false') ) if(defined $progress);
322 my $dataset = decode_json($summary[0]->{dataset});
323 $progress->( ".. processing rmauth $author $name (decoded JSON summary)" ) if(defined $progress);
324  
325 for my $data ( @{ $dataset->{distributions} } ) {
326 my $dist = $data->{dist};
327 my $summ = $data->{summary};
328  
329 next unless($remove{$dist});
330  
331 for my $state (keys %{ $remove{$dist} }) {
332 $summ->{ $state } -= $remove{$dist}{$state};
333 $summ->{ 'ALL' } -= $remove{$dist}{$state};
334 }
335 }
336  
337 $dbi->DoQuery('UpdateAuthorSummary',$summary[0]->{lastid},encode_json($dataset),$author);
338 }
339  
340 # push in author queue to rebuild pages
341 $dbi->DoQuery('PushAuthor',$author);
342 } catch {
343 $progress->( ".. failed rmauth $author $name (catch block)" ) if(defined $progress);
344 $fail = 1;
345 };
346 }
347  
348 return 0 if($fail);
349  
350 # remove requests
351 $dbi->DoQuery('DeletePageRequests',{ids => join(',',@ids)},'rmauth',$name);
352  
353 return scalar(@ids);
354 }
355  
356 sub RemoveDistroPages {
357 my ($cpan,$dbi,$progress,$name) = @_;
358  
359 # get ids from the page requests
360 my @requests = $dbi->GetQuery('hash','GetRequestIDs',{names => $name},'rmdist');
361 my %requests = map { $_->{id} => 1 } grep { $_->{id} } @requests;
362  
363 return unless(keys %requests);
364 push my @ids, keys %requests;
365  
366 my $exceptions = $cpan->exceptions;
367 my $symlinks = $cpan->symlinks;
368 my $merged = $cpan->merged;
369 my $ignore = $cpan->ignore;
370  
371 my @delete = ($name);
372 if( ( $name =~ /^[A-Za-z0-9][A-Za-z0-9\-_+.]*$/ && !$ignore->{$name} )
373 || ( $exceptions && $name =~ /$exceptions/ ) ) {
374  
375 # Some distributions are known by multiple names. Rather than create
376 # pages for each one, we try and merge them together into one.
377  
378 my $dist;
379 if($symlinks->{$name}) {
380 $name = $symlinks->{$name};
381 $dist = join("','", @{$merged->{$name}});
382 @delete = @{$merged->{$name}};
383 } elsif($merged->{$name}) {
384 $dist = join("','", @{$merged->{$name}});
385 @delete = @{$merged->{$name}};
386 } else {
387 $dist = $name;
388 @delete = ($name);
389 }
390  
391 my @valid = $dbi->GetQuery('hash','FindDistro',{dist=>$dist});
392 return unless(@valid);
393  
394 my $cache = sprintf "%s/static/distro/%s", $settings{webdir}, substr($name,0,1);
395 my $destfile = "$cache/$name.json";
396  
397 # get reports
398 my (%remove,@reports);
399 my $next = $dbi->Iterator('hash','GetReportsByIDs',{ids=>join(',',@ids)});
400 while(my $row = $next->()) {
401 # hash of dist => summary => PASS, FAIL, NA, UNKNOWN
402 $remove{$row->{dist}}{$row->{version}}{uc $row->{state}}++;
403 }
404  
405 # load JSON, if we have one
406 if(-f $destfile) {
407 my $data = read_file($destfile);
408 my $store;
409 eval { $store = decode_json($data) };
410 if(!$@ && $store) {
411 for my $row (@$store) {
412 next if($requests{$row->{id}}); # filter out requests
413  
414 push @reports, $row;
415 }
416 }
417 overwrite_file( $destfile, _make_json( \@reports ) );
418 }
419 }
420  
421 # remove requests
422 $dbi->DoQuery('DeletePageRequests',{ids => join(',',@ids)},'rmdist',$name);
423  
424 # push in author queue to rebuild pages
425 $dbi->DoQuery('PushDistro',$name);
426  
427 return scalar(@ids);
428 }
429  
430 # - build author pages
431 # - update summary
432 # - remove page request entries
433  
434 sub AuthorPages {
435 my ($cpan,$dbi,$name,$progress) = @_;
436 return unless(defined $name);
437  
438 $name = uc $name;
439  
440 my @ids = (0);
441 my %vars = %{ clone (\%tvars) };
442 #LogDebug("AuthorPages: before tvars=".total_size(\%tvars)." bytes");
443  
444 my @valid = $dbi->GetQuery('hash','FindAuthor',$name);
445 if(@valid) {
446 my @dists = $dbi->GetQuery('hash','GetAuthorDists',$name);
447 if(@dists) {
448 my %dists = map {$_->{dist} => $_->{version}} @dists;
449 my $cache = sprintf "%s/static/author/%s", $settings{webdir}, substr($name,0,1);
450 mkpath($cache);
451  
452 my (@reports,%reports,%summary,$next);
453 my $destfile = "$cache/$name.json";
454 my $fromid = '';
455 my $lastid = 0;
456  
457 # load the summary, if we have one
458 my @summary = $dbi->GetQuery('hash','GetAuthorSummary',$name);
459 $lastid = $summary[0]->{lastid} if(@summary);
460  
461 # load JSON, if we have one
462 if(-f $destfile && $lastid) {
463 my $data = read_file($destfile);
464 my $store;
465 eval { $store = decode_json($data); };
466 if(!$@ && $store) {
467 my %ids;
468 for my $row (@$store) {
469 next if($lastid < $row->{id});
470 next if($dists{$row->{dist}} ne $row->{version}); # ensure this is the latest dist version
471 next if($ids{$row->{id}}); # auto clean duplicates
472  
473 $ids{$row->{id}} = 1;
474  
475 unshift @{$reports{$row->{dist}}}, $row;
476 $summary{$row->{dist}}->{ $row->{status} }++;
477 $summary{$row->{dist}}->{ 'ALL' }++;
478 push @reports, $row;
479 }
480  
481 $fromid = " AND id > $lastid " if($lastid);
482 }
483 }
484  
485 # if we have ids in the page requests, just update these
486 my @requests = $dbi->GetQuery('hash','GetRequestIDs',{names => $name},'author');
487 my %requests = map { $_->{id} => 1 } grep { $_->{id} } @requests;
488 if(keys %requests) {
489 $next = $dbi->Iterator('hash','GetReportsByIDs',{ids=>join(',',keys %requests)});
490 push @ids, keys %requests;
491  
492 } else {
493 # process all the reports from the last ID used
494 if(scalar(@dists) > 300) {
495 # a fairly constant 83-93 seconds regardless of volume
496 $next = $dbi->Iterator('hash','GetAuthorDistReports',{fromid=>$fromid},$name);
497 } else {
498 # 3-73 secs for dists of 1-100
499 my $lookup = 'AND ( ' . join(' OR ',map {"(dist = '$_->{dist}' AND version = '$_->{version}')"} @dists) . ' )';
500 $next = $dbi->Iterator('hash','GetAuthorDistReports3',{lookup=>$lookup,fromid=>$fromid});
501 }
502 }
503  
504 while(my $row = $next->()) {
505 next unless($dists{$row->{dist}} && $row->{version});
506 next if($dists{$row->{dist}} ne $row->{version}); # ensure this is the latest dist version
507  
508 $row->{perl} ||= '';
509 $row->{perl} = "5.004_05" if $row->{perl} eq "5.4.4"; # RT 15162
510 $row->{perl} =~ s/patch.*/patch blead/ if $row->{perl} =~ /patch.*blead/;
511 my ($osname) = $cpan->OSName($row->{osname});
512  
513 $row->{status} = uc $row->{state};
514 $row->{ostext} = $osname;
515 $row->{distribution} = $row->{dist};
516 $row->{distversion} = $row->{dist} . '-' . $row->{version};
517 $row->{csspatch} = $row->{perl} =~ /\b(RC\d+|patch)\b/ ? 'pat' : 'unp';
518 $row->{cssperl} = $row->{perl} =~ /^5.(7|9|[1-9][13579])/ ? 'dev' : 'rel';
519  
520 push @{$reports{$row->{dist}}}, $row;
521 $summary{$row->{dist}}->{ $row->{status} }++;
522 $summary{$row->{dist}}->{ 'ALL' }++;
523 $lastid = $row->{id} if($lastid < $row->{id});
524 unshift @reports, $row;
525 }
526  
527 for my $dist (@dists) {
528 $dist->{letter} = substr($dist->{dist},0,1);
529 $dist->{reports} = 1 if($reports{$dist->{dist}});
530 $dist->{summary} = $summary{$dist->{dist}};
531 $dist->{cssrelease} = $dist->{version} =~ /(_|-TRIAL)/ ? 'rel' : 'off';
532 $dist->{csscurrent} = $dist->{type} eq 'backpan' ? 'back' : 'cpan';
533 }
534  
535 $vars{builder}{author} = $name;
536 $vars{builder}{letter} = substr($name,0,1);
537 $vars{builder}{title} = 'Reports for distributions by ' . $name;
538 $vars{builder}{distributions} = \@dists if(@dists);
539 $vars{builder}{perlvers} = $cpan->mklist_perls;
540 $vars{builder}{osnames} = $cpan->osnames;
541 $vars{builder}{processed} = time;
542  
543 # insert summary details
544 {
545 my $dataset = encode_json($vars{builder});
546 if(@summary) { $dbi->DoQuery('UpdateAuthorSummary',$lastid,$dataset,$name); }
547 else { $dbi->DoQuery('InsertAuthorSummary',$lastid,$dataset,$name); }
548 }
549  
550 # we have to do this here as we don't want all the reports in
551 # the encoded summary, just whether we have reports or not
552 for my $dist (@dists) {
553 $dist->{reports} = $reports{$dist->{dist}};
554 }
555  
556 $vars{cache} = $cache;
557 $vars{content} = 'cpan/author-reports-static.html';
558 $vars{processed} = formatDate(8);
559  
560 # build other static pages
561 my $text = Transform( 'cpan/layout-static.html', \%vars );
562 overwrite_file( "$cache/$name.html", $text );
563  
564 $text = Transform( 'cpan/author.js', \%vars );
565 overwrite_file( "$cache/$name.js", $text );
566  
567 overwrite_file( "$cache/$name.json", _make_json( \@reports ) );
568 }
569 }
570  
571 #LogDebug("AuthorPages: after tvars=".total_size(\%tvars)." bytes");
572  
573 # remove requests
574 $dbi->DoQuery('DeletePageRequests',{ids => join(',',@ids)},'author',$name);
575 }
576  
577 # - build distro pages
578 # - update summary
579 # - remove page request entries
580  
581 sub DistroPages {
582 my ($cpan,$dbi,$name,$progress) = @_;
583 return unless(defined $name);
584  
585 my @ids = (0);
586 my %vars = %{ clone (\%tvars) };
587  
588 #LogDebug("DistroPages: before tvars=".total_size(\%tvars)." bytes");
589 #$progress->( ".. .. starting $name" ) if(defined $progress);
590  
591 my $exceptions = $cpan->exceptions;
592 my $symlinks = $cpan->symlinks;
593 my $merged = $cpan->merged;
594 my $ignore = $cpan->ignore;
595  
596 my @delete = ($name);
597 if( ( $name =~ /^[A-Za-z0-9][A-Za-z0-9\-_+.]*$/ && !$ignore->{$name} )
598 || ( $exceptions && $name =~ /$exceptions/ ) ) {
599  
600 # Some distributions are known by multiple names. Rather than create
601 # pages for each one, we try and merge them together into one.
602  
603 my $dist;
604 if($symlinks->{$name}) {
605 $name = $symlinks->{$name};
606 $dist = join("','", @{$merged->{$name}});
607 @delete = @{$merged->{$name}};
608 } elsif($merged->{$name}) {
609 $dist = join("','", @{$merged->{$name}});
610 @delete = @{$merged->{$name}};
611 } else {
612 $dist = $name;
613 @delete = ($name);
614 }
615  
616 #$progress->( ".. .. getting records for $name" ) if(defined $progress);
617 my @valid = $dbi->GetQuery('hash','FindDistro',{dist=>$dist});
618 #$progress->( ".. .. retrieved records for $name" ) if(defined $progress);
619 if(@valid) {
620 my (@reports,%authors,%version,$summary,$byversion,$next);
621 my $fromid = '';
622 my $lastid = 0;
623  
624 # determine max dist/version for each pause id
625 for(@valid) {
626 $authors{$_->{author}} = $_->{version};
627 $version{$_->{version}} = { author => $_->{author}, new => 0, type => $_->{type}};
628 }
629 my %reports = map {$authors{$_} => []} keys %authors;
630  
631 # if we have a summary, process all reports to the last update from the JSON cache
632  
633 my @summary = $dbi->GetQuery('hash','GetDistroSummary',$name);
634 $lastid = $summary[0]->{lastid} if(@summary);
635  
636 my $cache = sprintf "%s/static/distro/%s", $settings{webdir}, substr($name,0,1);
637 my $destfile = "$cache/$name.json";
638 mkpath($cache);
639  
640 #$progress->( ".. .. loading JSON data for $name" ) if(defined $progress);
641 # load JSON data if available
642 if(-f $destfile && $lastid) {
643 my $json = read_file($destfile);
644 my $data;
645 eval { $data = decode_json($json); };
646 if(!$@ && $data) {
647 my %ids;
648 for my $row (@$data) {
649 next if($lastid < $row->{id});
650 next if($ids{$row->{id}}); # auto clean duplicates
651  
652 $ids{$row->{id}} = 1;
653 push @reports, $row;
654  
655 $summary->{ $row->{version} }->{ $row->{status} }++;
656 $summary->{ $row->{version} }->{ 'ALL' }++;
657 unshift @{ $byversion->{ $row->{version} } }, $row;
658  
659 # record reports from max versions
660 unshift @{ $reports{$row->{version}} }, $row if(defined $reports{$row->{version}});
661 }
662  
663 $fromid = " AND id > $lastid ";
664 }
665 }
666 #$progress->( ".. .. loaded JSON data for $name" ) if(defined $progress);
667  
668 # if we have ids in the page requests, just update these
669 my @requests = $dbi->GetQuery('hash','GetRequestIDs',{names => $dist},'distro');
670 my %requests = map { $_->{id} => 1 } grep { $_->{id} } @requests;
671 if(keys %requests) {
672 $next = $dbi->Iterator('hash','GetReportsByIDs',{ids=>join(',',keys %requests)});
673 push @ids, keys %requests;
674 } else {
675 $next = $dbi->Iterator('hash','GetDistroReports',{fromid => $fromid, dist => $dist});
676 }
677  
678 #$progress->( ".. .. starting data update for $name" ) if(defined $progress);
679 while(my $row = $next->()) {
680 $row->{perl} = "5.004_05" if $row->{perl} eq "5.4.4"; # RT 15162
681 $row->{perl} =~ s/patch.*/patch blead/ if $row->{perl} =~ /patch.*blead/;
682 my ($osname) = $cpan->OSName($row->{osname});
683  
684 $row->{distribution} = $name;
685 $row->{status} = uc $row->{state};
686 $row->{ostext} = $osname;
687 $row->{osvers} = $row->{osvers};
688 $row->{distversion} = $name . '-' . $row->{version};
689 $row->{csspatch} = $row->{perl} =~ /\b(RC\d+|patch)\b/ ? 'pat' : 'unp';
690 $row->{cssperl} = $row->{perl} =~ /^5.(7|9|[1-9][13579])/ ? 'dev' : 'rel';
691 $lastid = $row->{id} if($lastid < $row->{id});
692 unshift @reports, $row;
693  
694 $summary->{ $row->{version} }->{ $row->{status} }++;
695 $summary->{ $row->{version} }->{ 'ALL' }++;
696 push @{ $byversion->{ $row->{version} } }, $row;
697  
698 # record reports from max versions
699 unshift @{ $reports{$row->{version}} }, $row if($reports{$row->{version}});
700 $version{$row->{version}}->{new} = 1;
701 }
702 #$progress->( ".. .. summary data update complete for $name" ) if(defined $progress);
703  
704 for my $version ( keys %$byversion ) {
705 my @list = @{ $byversion->{$version} };
706 $byversion->{$version} = [ sort { $b->{id} <=> $a->{id} } @list ];
707 }
708  
709 # ensure we cover all known versions
710 my @rows = $dbi->GetQuery('array','GetDistVersions',{dist=>$dist});
711 my @versions = map{$_->[0]} @rows;
712 my %versions = map {my $v = $_; $v =~ s/[^\w\.\-]/X/g; $_ => $v} @versions;
713  
714 my %release;
715 for my $version ( keys %versions ) {
716 $release{$version}->{csscurrent} = $version{$version}->{type} eq 'backpan' ? 'back' : 'cpan';
717 $release{$version}->{cssrelease} = $version =~ /(_|-TRIAL)/ ? 'dev' : 'off';
718 $release{$version}->{header} = "<h2>$dist $version ";
719 if($summary->{$version}{ALL}) {
720 $release{$version}->{header} .= "(<b> ";
721 for my $status (sort keys %{$summary->{$version}}) {
722 $release{$version}->{header} .= "<span class='$status'>$summary->{$version}{$status} $status";
723 if($summary->{$version}{$status} > 1) {
724 $release{$version}->{header} .= $status eq 'PASS' ? 'es' : 's';
725 }
726 $release{$version}->{header} .= "</span> ";
727 }
728 $release{$version}->{header} .= "</b>)";
729 } else {
730 $release{$version}->{header} .= "(No reports)";
731 }
732 $release{$version}->{header} .= "</h2>";
733 }
734 #$progress->( ".. .. version data update complete for $name" ) if(defined $progress);
735  
736 # V1 code starts
737 # my ($stats,$oses);
738 # @rows = $dbi->GetQuery('hash','GetDistrosPass',{dist=>$dist});
739 # for(@rows) {
740 # my ($osname,$code) = $cpan->OSName($_->{osname});
741 # $stats->{$_->{perl}}{$code}{count} = $_->{count};
742 # $oses->{$code} = $osname;
743 # }
744 ##$progress->( ".. .. OS data update complete for $name" ) if(defined $progress);
745 #
746 # # distribution PASS stats
747 # my @stats = $dbi->GetQuery('hash','GetStatsPass',{dist=>$dist});
748 # for(@stats) {
749 # my ($osname,$code) = $cpan->OSName($_->{osname});
750 # $stats->{$_->{perl}}{$code}{version} = $_->{version}
751 # if(!$stats->{$_->{perl}}->{$code} || _versioncmp($_->{version},$stats->{$_->{perl}}->{$code}{version}));
752 # }
753 ##$progress->( ".. .. Pass Stats data update complete for $name" ) if(defined $progress);
754 # V1 code end
755  
756 # V2 code starts
757 # # retrieve perl/os stats
758 # my ($stats,$oses);
759 # my @stats = $dbi->GetQuery('hash','GetStatsPass',{dist=>$dist});
760 # for(@stats) {
761 # my ($osname,$code) = $cpan->OSName($_->{osname});
762 # $stats->{$_->{perl}}{$code}{version} = $_->{version}
763 # if(!$stats->{$_->{perl}}->{$code} || _versioncmp($_->{version},$stats->{$_->{perl}}->{$code}{version}));
764 #
765 # $stats->{$_->{perl}}{$code}{count}++;
766 # $oses->{$code} = $osname;
767 # }
768 ##$progress->( ".. .. Perl/OS data update complete for $name" ) if(defined $progress);
769 # V2 code end
770  
771 # V3 code starts
772 # retrieve perl/os stats
773 my ($stats,$oses);
774 my $lastref = 0;
775 @rows = $dbi->GetQuery('hash','GetStatsStore',$name);
776 for(@rows) {
777 $stats->{$_->{perl}}{$_->{osname}}{storeid} = $_->{storeid};
778 $stats->{$_->{perl}}{$_->{osname}}{version} = $_->{version};
779 $stats->{$_->{perl}}{$_->{osname}}{count} = $_->{counter};
780 $stats->{$_->{perl}}{$_->{osname}}{updated} = 0;
781 $oses->{$_->{osname}} = $_->{osname};
782 $lastref = $_->{lastid};
783 }
784  
785 # update perl/os stats
786 my @stats = $dbi->GetQuery('hash','GetStatsPass2',{dist=>$dist},$lastref);
787 for(@stats) {
788 my ($osname,$code) = $cpan->OSName($_->{osname});
789 my $perl = $_->{perl};
790 $perl =~ s/ .*$//; # don't care about the patch/RC number
791  
792 $stats->{$perl}{$code}{updated} = 1;
793  
794 $stats->{$perl}{$code}{version} = $_->{version}
795 if(!$stats->{$perl}->{$code} || _versioncmp($_->{version},$stats->{$perl}->{$code}{version}));
796  
797 $stats->{$perl}{$code}{count}++;
798 $oses->{$code} = $osname;
799 $lastref = $_->{id} if($lastref < $_->{id});
800 }
801  
802 # store perl/os stats
803 for my $perl (keys %$stats) {
804 for my $code (keys %{$stats->{$perl}}) {
805 next unless($stats->{$perl}{$code}{updated});
806 if($stats->{$perl}{$code}{storeid}) {
807 $dbi->DoQuery('UpdStatsStore',$name,$perl,$code,$stats->{$perl}{$code}{version},$stats->{$perl}{$code}{count},$lastref, $stats->{$perl}{$code}{storeid});
808 } else {
809 $dbi->DoQuery('SetStatsStore',$name,$perl,$code,$stats->{$perl}{$code}{version},$stats->{$perl}{$code}{count},$lastref);
810 }
811 }
812 }
813 # $dbi->DoQuery('DelStatsStore',$name);
814 # for my $perl (keys %$stats) {
815 # for my $code (keys %{$stats->{$perl}}) {
816 # $dbi->DoQuery('SetStatsStore',$name,$perl,$code,$stats->{$perl}{$code}{version},$stats->{$perl}{$code}{count},$lastref);
817 # }
818 # }
819 #$progress->( ".. .. Perl/OS data update complete for $name" ) if(defined $progress);
820 # V3 code end
821  
822 my @stats_oses = sort keys %$oses;
823 my @stats_perl = sort {_versioncmp($b,$a)} keys %$stats;
824 my @stats_poff = grep {!/patch/} sort {_versioncmp($b,$a)} keys %$stats;
825  
826 $vars{title} = 'Reports for distribution ' . $name;
827  
828 $vars{builder}{distribution} = $name;
829 $vars{builder}{letter} = substr($name,0,1);
830 $vars{builder}{stats_code} = $oses;
831 $vars{builder}{stats_oses} = \@stats_oses;
832 $vars{builder}{stats_perl} = \@stats_perl;
833 $vars{builder}{stats_poff} = \@stats_poff;
834 $vars{builder}{stats} = $stats;
835 $vars{builder}{title} = $vars{title};
836 $vars{builder}{perlvers} = $cpan->mklist_perls;
837 $vars{builder}{osnames} = $cpan->osnames;
838 $vars{builder}{processed} = time;
839 #$progress->( ".. .. memory data update complete for $name" ) if(defined $progress);
840  
841 # insert summary details
842 {
843 my $dataset = encode_json($vars{builder});
844 if(@summary) { $dbi->DoQuery('UpdateDistroSummary',$lastid,$dataset,$name); }
845 else { $dbi->DoQuery('InsertDistroSummary',$lastid,$dataset,$name); }
846 }
847 #$progress->( ".. .. summary data stored for $name" ) if(defined $progress);
848  
849 $vars{versions} = \@versions;
850 $vars{versions_tag} = \%versions;
851 $vars{summary} = $summary;
852 $vars{release} = \%release;
853 $vars{byversion} = $byversion;
854 $vars{cache} = $cache;
855 $vars{processed} = formatDate(8);
856  
857 #$progress->( ".. .. building static pages for $name" ) if(defined $progress);
858 # build other static pages
859 $vars{content} = 'cpan/distro-reports-static.html';
860 my $text = Transform( 'cpan/layout-static.html', \%vars );
861 overwrite_file( "$cache/$name.html", $text );
862 #$progress->( ".. .. Dynamic HTML page written for $name" ) if(defined $progress);
863  
864 $text = Transform( 'cpan/distro.js', \%vars );
865 overwrite_file( "$cache/$name.js", $text );
866 #$progress->( ".. .. JS page written for $name" ) if(defined $progress);
867  
868 overwrite_file( "$cache/$name.json", _make_json( \@reports ) );
869 #$progress->( ".. .. JSON page written for $name" ) if(defined $progress);
870  
871 $cache = sprintf "%s/stats/distro/%s", $settings{webdir}, substr($name,0,1);
872 mkpath($cache);
873 $vars{cache} = $cache;
874  
875 $vars{content} = 'cpan/stats-distro-static.html';
876 $text = Transform( 'cpan/layout-stats-static.html', \%vars );
877 overwrite_file( "$cache/$name.html", $text );
878 #$progress->( ".. .. Static HTML page written for $name" ) if(defined $progress);
879  
880 # generate symbolic links where necessary
881 if($merged->{$name}) {
882 my $cwd = getcwd;
883 chdir("$settings{webdir}/static/distro");
884 for my $dist (@{$merged->{$name}}) {
885 next if($dist eq $name);
886 for my $ext (qw(html json js)) {
887 my $source = substr($name,0,1) . "/$name.$ext" ;
888 my $target = substr($dist,0,1) . "/$dist.$ext" ;
889 next if(!-f $source || -f $target);
890  
891 eval {symlink($source,$target) ; 1};
892 }
893 }
894 chdir($cwd);
895 #$progress->( ".. .. symbolic links created for $name" ) if(defined $progress);
896 }
897 }
898 }
899  
900 #LogDebug("DistroPages: after tvars=".total_size(\%tvars)." bytes");
901 #LogDebug("DistroPages: ids=@ids, distros=@delete");
902  
903 # remove requests
904 while(@ids) {
905 #$progress->( ".. .. removing page_request entries for $name. ids=".scalar(@ids) ) if(defined $progress);
906 my @remove = splice(@ids,0,100);
907 $dbi->DoQuery('DeletePageRequests',{ids => join(',',@remove)},'distro',$_) for(@delete);
908 };
909 #$progress->( ".. .. removed page_request entries for $name" ) if(defined $progress);
910 }
911  
912 sub StatsPages {
913 my $cpan = Labyrinth::Plugin::CPAN->new();
914 $cpan->Configure();
915  
916 my $cache = sprintf "%s/stats", $settings{webdir};
917 mkpath($cache);
918  
919 #print STDERR "StatsPages: cache=$cache\n";
920  
921 my (%data,%perldata,%perls,%all_osnames,%dists,%perlos,%lookup);
922  
923 no warnings( 'uninitialized', 'numeric' );
924  
925 my $next = $dbi->Iterator('hash','GetStats');
926  
927 # build data structures
928 while ( my $row = $next->() ) {
929 #next if not $row->{perl};
930 #next if $row->{perl} =~ / /;
931 #next if $row->{perl} =~ /^5\.(7|9|[1-9][13579])\b/; # ignore dev versions
932 #next if $row->{version} =~ /[^\d.]/;
933  
934 $row->{perl} = "5.004_05" if $row->{perl} eq "5.4.4"; # RT 15162
935  
936 my ($osname,$oscode) = $cpan->OSName($row->{osname});
937 $row->{osname} = $oscode;
938 $lookup{$oscode} = $osname;
939  
940 $perldata{$row->{perl}}{$row->{dist}} = $row->{version} if $perldata{$row->{perl}}{$row->{dist}} < $row->{version};
941 $data{$row->{dist}}{$row->{perl}}{$row->{osname}} = $row->{version} if $data{$row->{dist}}{$row->{perl}}{$row->{osname}} < $row->{version};
942 $perls{$row->{perl}}{reports}++;
943 $perls{$row->{perl}}{distros}{$row->{dist}}++;
944 $perlos{$row->{perl}}{$row->{osname}}++;
945 $all_osnames{$row->{osname}}++;
946 }
947  
948 my @versions = sort {_versioncmp($b,$a)} keys %perls;
949 my $text;
950  
951 # page perl perl version cross referenced with platforms
952 my %perl_osname_all;
953 for my $perl ( @versions ) {
954 my (@data,%oscounter,%dist_for_perl);
955 for my $dist ( sort keys %{ $perldata{$perl} } ) {
956 my @osversion;
957 for my $oscode ( sort keys %{ $perlos{$perl} } ) {
958 if ( defined $data{$dist}{$perl}{$oscode} ) {
959 push @osversion, { ver => $data{$dist}{$perl}{$oscode} };
960 $oscounter{$oscode}++;
961 $dist_for_perl{$dist}++;
962 } else {
963 push @osversion, { ver => undef };
964 }
965 }
966 push @data, {
967 dist => $dist,
968 osversion => \@osversion,
969 };
970 }
971  
972 my @perl_osnames;
973 for my $code ( sort keys %{ $perlos{$perl} } ) {
974 if ( $oscounter{$code} ) {
975 push @perl_osnames, { oscode => $code, osname => $lookup{$code}, cnt => $oscounter{$code} };
976 $perl_osname_all{$code}{$perl} = $oscounter{$code};
977 }
978 }
979  
980 my $destfile = "perl_${perl}_platforms.html";
981 $tvars{osnames} = \@perl_osnames;
982 $tvars{dists} = \@data;
983 $tvars{perl} = $perl;
984 $tvars{cnt_modules} = scalar keys %dist_for_perl;
985 $tvars{cache} = $cache;
986 $tvars{content} = 'cpan/stats-perl-platform.html';
987 $text = Transform( 'cpan/layout-stats-static.html', \%tvars );
988 overwrite_file( "$cache/$destfile", $text );
989 }
990  
991 my @perl_osnames;
992 for(keys %perl_osname_all) {
993 my ($name,$code) = $cpan->OSName($_);
994 push @perl_osnames, {oscode => $code, osname => $name}
995 }
996  
997 my (@perls,@data_perlplat,$parms,$destfile);
998 for my $perl ( @versions ) {
999 push @perls, {
1000 perl => $perl,
1001 report_count => $perls{$perl}{reports},
1002 distro_count => scalar( keys %{ $perls{$perl}{distros} } ),
1003 };
1004  
1005 my @count;
1006 for my $os (keys %perl_osname_all) {
1007 my ($name,$code) = $cpan->OSName($os);
1008 push @count, { oscode => $code, osname => $name, count => $perl_osname_all{$os}{$perl} };
1009 }
1010 push @data_perlplat, {
1011 perl => $perl,
1012 count => \@count,
1013 };
1014  
1015 my (@data_perl,$cnt);
1016 for my $dist ( sort keys %{ $perldata{$perl} } ) {
1017 $cnt++;
1018 push @data_perl, {
1019 dist => $dist,
1020 version => $perldata{$perl}{$dist},
1021 };
1022 }
1023  
1024 # page per perl version
1025 $destfile = "perl_${perl}.html";
1026 $tvars{data} = \@data_perl;
1027 $tvars{perl} = $perl;
1028 $tvars{cnt_modules} = $cnt;
1029 $tvars{cache} = $cache;
1030 $tvars{content} = 'cpan/stats-perl-version.html';
1031 $text = Transform( 'cpan/layout-stats-static.html', \%tvars );
1032 overwrite_file( "$cache/$destfile", $text );
1033 }
1034  
1035 # how many test reports per platform per perl version?
1036 $destfile = "perl_platforms.html";
1037 $tvars{osnames} = \@perl_osnames;
1038 $tvars{perlv} = \@data_perlplat;
1039 $tvars{cache} = $cache;
1040 $tvars{content} = 'cpan/stats-perl-platform-count.html';
1041 $text = Transform( 'cpan/layout-stats-static.html', \%tvars );
1042 overwrite_file( "$cache/$destfile", $text );
1043  
1044 # generate index.html
1045 $destfile = "index.html";
1046 $tvars{perls} = \@perls;
1047 $tvars{cache} = $cache;
1048 $tvars{content} = 'cpan/stats-index.html';
1049 $text = Transform( 'cpan/layout-stats-static.html', \%tvars );
1050 overwrite_file( "$cache/$destfile", $text );
1051  
1052 # # create symbolic links
1053 # for my $link ('headings', 'background.png', 'style.css', 'cpan-testers.css') {
1054 # my $source = file( $directory, $link );
1055 # my $target = file( $directory, 'stats', $link );
1056 # next if(!-e $source);
1057 # next if( -e $target);
1058 # eval {symlink($source,$target) ; 1};
1059 # }
1060 }
1061  
1062 sub RecentPage {
1063 my $cpan = Labyrinth::Plugin::CPAN->new();
1064 $cpan->Configure();
1065  
1066 # Recent reports
1067 my @recent;
1068 my $count = $settings{rss_limit_recent} || $RECENT;
1069 my $next = $dbi->Iterator('hash','GetRecent',{limit => "LIMIT $count"});
1070  
1071 while ( my $row = $next->() ) {
1072  
1073 next unless $row->{version};
1074 my ($name) = $cpan->OSName($row->{osname});
1075  
1076 my $report = {
1077 guid => $row->{guid},
1078 id => $row->{id},
1079 dist => $row->{dist},
1080 status => uc $row->{state},
1081 version => $row->{version},
1082 perl => $row->{perl},
1083 osname => $name,
1084 osvers => $row->{osvers},
1085 platform => $row->{platform},
1086 };
1087 push @recent, $report;
1088 last if(--$count < 1);
1089 }
1090  
1091 my $cache = sprintf "%s/static", $settings{webdir};
1092 mkpath($cache);
1093  
1094 $tvars{recent} = \@recent;
1095 $tvars{cache} = $cache;
1096 $tvars{content} = 'cpan/recent.html';
1097  
1098 my $text = Transform( 'cpan/layout-static.html', \%tvars );
1099 overwrite_file( $cache . '/recent.html', $text );
1100 $tvars{recent} = undef;
1101  
1102 my $destfile = "$cache/recent.rss";
1103 overwrite_file( $destfile, _make_rss( 'recent', undef, \@recent ) );
1104 }
1105  
1106 #----------------------------------------------------------------------------
1107 # Private Interface Functions
1108  
1109 sub _request_count {
1110 my $dbi = shift;
1111  
1112 my @rows = $dbi->GetQuery('array','CountRequests');
1113 my $cnt = @rows ? $rows[0]->[0] : 0;
1114 return $cnt;
1115 }
1116  
1117 sub _request_oldest {
1118 my $dbi = shift;
1119  
1120 my @rows = $dbi->GetQuery('array','OldestRequest');
1121 my $cnt = @rows ? $rows[0]->[0] : 0;
1122 return $cnt;
1123 }
1124  
1125 sub _make_json {
1126 my ( $data ) = @_;
1127 return encode_json( $data );
1128 }
1129  
1130 sub _make_rss {
1131 my ( $type, $item, $data ) = @_;
1132 my ( $title, $link, $desc );
1133  
1134 if($type eq 'dist') {
1135 $title = "$item CPAN Testers Reports";
1136 $link = "http://www.cpantesters.org/distro/".substr($item,0,1)."/$item.html";
1137 $desc = "Automated test results for the $item distribution";
1138 } elsif($type eq 'recent') {
1139 $title = "Recent CPAN Testers Reports";
1140 $link = "http://www.cpantesters.org/static/recent.html";
1141 $desc = "Recent CPAN Testers reports";
1142 } elsif($type eq 'author') {
1143 $title = "Reports for distributions by $item";
1144 $link = "http://www.cpantesters.org/author/".substr($item,0,1)."/$item.html";
1145 $desc = "Reports for distributions by $item";
1146 } elsif($type eq 'nopass') {
1147 $title = "Failing Reports for distributions by $item";
1148 $link = "http://www.cpantesters.org/author/".substr($item,0,1)."/$item.html";
1149 $desc = "Reports for distributions by $item";
1150 }
1151  
1152 my $rss = XML::RSS->new( version => '1.0' );
1153 $rss->channel(
1154 title => $title,
1155 link => $link,
1156 description => $desc,
1157 syn => {
1158 updatePeriod => "daily",
1159 updateFrequency => "1",
1160 updateBase => "1901-01-01T00:00+00:00",
1161 },
1162 );
1163  
1164 for my $test (@$data) {
1165 $rss->add_item(
1166 title => sprintf(
1167 "%s %s-%s %s on %s %s (%s)",
1168 map {$_||''}
1169 @{$test}{
1170 qw( status dist version perl osname osvers platform )
1171 }
1172 ),
1173 link => "$settings{reportlink2}/" . ($test->{guid} || $test->{id}),
1174 );
1175 }
1176  
1177 return $rss->as_string;
1178 }
1179  
1180 sub _versioncmp {
1181 my ($v1,$v2) = @_;
1182 my ($vn1,$vn2);
1183  
1184 $v1 =~ s/\s.*$// if($v1);
1185 $v2 =~ s/\s.*$// if($v2);
1186  
1187 return -1 if(!$v1 && $v2);
1188 return 0 if(!$v1 && !$v2);
1189 return 1 if( $v1 && !$v2);
1190  
1191 eval { $vn1 = version->parse($v1); };
1192 if($@) { return $v1 cmp $v2 }
1193 eval { $vn2 = version->parse($v2); };
1194 if($@) { return $v1 cmp $v2 }
1195  
1196 return $vn1 cmp $vn2;
1197 }
1198  
1199 1;
1200  
1201 __END__
1202  
1203 =head1 SEE ALSO
1204  
1205 Labyrinth
1206  
1207 =head1 AUTHOR
1208  
1209 Barbie, <barbie@missbarbell.co.uk> for
1210 Miss Barbell Productions, L<http://www.missbarbell.co.uk/>
1211  
1212 =head1 COPYRIGHT & LICENSE
1213  
1214 Copyright (C) 2008-2017 Barbie for Miss Barbell Productions
1215 All Rights Reserved.
1216  
1217 This module is free software; you can redistribute it and/or
1218 modify it under the Artistic License 2.0.
1219  
1220 =cut
« Labyrinth/Plugin/CPAN/Report.pm ↑ Summary CPAN/Testers/WWW/Reports.pm »