blib/lib/CPAN/Testers/WWW/Reports/Mailer.pm

filter: Statementstmt 20.3% 118 / 580 Branchbran 2.9% 8 / 274 Conditioncond 0.7% 1 / 138 MC/DCmcdc 0.0% 0 / 81 Subroutinesub 60.3% 32 / 53 Podpod 100% 4 / 4 totaltotal 14.4% 163 / 1130 SCAR 102.1
CC
202
Cov
13%
check_reports
8190.0
_get_earliest
240.0
new
204.8
CRAP 27255.0
↑ Summary
1 package CPAN::Testers::WWW::Reports::Mailer;
2  
3 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 22 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 22 $VERSION = '0.36';
8  
9 =head1 NAME
10  
11 CPAN::Testers::WWW::Reports::Mailer - CPAN Testers Reports Mailer
12  
13 =head1 SYNOPSIS
14  
15 use CPAN::Testers::WWW::Reports::Mailer;
16  
17 my $mailer = CPAN::Testers::WWW::Reports::Mailer->new(
18 config => 'myconfig.ini'
19 );
20  
21 $mailer->check_reports();
22 $mailer->check_counts();
23  
24 =head1 DESCRIPTION
25  
26 The CPAN Testers Reports Mailer takes the preferences set within the CPANPREFS
27 database, and uses them to filter out reports that the author does or does not
28 wish to be made aware of.
29  
30 New authors are added to the system as a report for their first reported
31 distribution is submitted by a tester. Default settings are applied in the
32 first instance, with the author able to update these via the preferences
33 website.
34  
35 Initially only a Daily Summary Report is available, in time a Weekly Summary
36 Report and the individual reports will also be available.
37  
38 =head1 CONFIGURATION
39  
40 Configuration for this application can occur via the command line, the API and
41 the configuration file. Of them all, only the configuration file is required.
42  
43 The configuration file should be in the INI style, with the section CPANPREFS
44 describing the associated database access required. The general settings
45 section, SETTINGS, is optional, and can be overridden by the command line and
46 the API arguments.
47  
48 =head2 Database Configuration
49  
50 The CPANPREFS section is required, and should contain the following key/value
51 pairs to describe access to the specific database.
52  
53 =over 4
54  
55 =item * driver
56  
57 =item * database
58  
59 =item * dbhost
60  
61 =item * dbport
62  
63 =item * dbuser
64  
65 =item * dbpass
66  
67 =back
68  
69 Only 'driver' and 'database' are required for an SQLite database, while the
70 other key/values may need to be completed for other databases.
71  
72 It is now assumed that only one database connection is require, with other
73 databases held within the same database application. The primary connection
74 must be to the CPAN Preferences databases. The other databases, CPAN Statistics, Articles and Metabase
75  
76 =head2 General Configuration
77  
78 The following options are available, in the configuration file, on the command
79 line and via the API call to new() as a hash.
80  
81 =over 4
82  
83 =item * mode
84  
85 Processing mode required. This can be one of three values, 'daily', 'weekly' or
86 'reports'. 'daily' and 'weekly' create the mails for the Daily Summary and
87 Weekly Summary reports respectively. 'reports' creates individual report mails
88 for authors.
89  
90 =item * verbose
91  
92 If set to a true value, will print additional log messages.
93  
94 =item * nomail
95  
96 By default this is set to 1, to avoid accidentally running and sending lots of
97 mails :) Set to 0 to allow normal processing.
98  
99 =item * test
100  
101 If used, must be set to a single NNTPID, which will then be tested in isolation
102 for the currently set mode. Automatically sets the nomail flag to true.
103  
104 =item * lastmail
105  
106 The location of the counter file, that stores the ids of the last reports
107 processed.
108  
109 =item * mailrc
110  
111 The location of the 01mailrc.txt file stored locally. By default the location
112 is assumed to be 'data/01mailrc.txt'. If the confirguration is not set, or the
113 file cannot be found, it will be dynamically downloaded from CPAN.
114  
115 =item * logfile
116  
117 The location of the logfile. If not provided, logging is disabled.
118  
119 =item * logclean
120  
121 By default this is set to 0, append to existing log. If set to 1, will create
122 a new log or overwrite any existing log, on the first call to log a message,
123 then will automatically reset to 0, so as to append any further messages.
124  
125 =back
126  
127 =cut
128  
129 # -------------------------------------
130 # Library Modules
131  
132 22 ▶use Compress::Zlib;
Subroutine BEGIN: called CC=1 SCAR=0.0
133 22 ▶use Config::IniFiles;
Subroutine BEGIN: called CC=1 SCAR=0.0
134 22 ▶use CPAN::Testers::Common::DBUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
135 22 ▶use CPAN::Testers::Common::Utils qw(guid_to_nntp);
Subroutine BEGIN: called CC=1 SCAR=0.0
136 22 ▶use CPAN::Testers::Fact::LegacyReport;
Subroutine BEGIN: called CC=1 SCAR=0.0
137 22 ▶use CPAN::Testers::Fact::TestSummary;
Subroutine BEGIN: called CC=1 SCAR=0.0
138 22 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
139 22 ▶use Email::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
140 22 ▶use Email::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
141 22 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
142 22 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
143 22 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
144 22 ▶use Getopt::ArgvFile default=>1;
Subroutine BEGIN: called CC=1 SCAR=0.0
145 22 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
146 22 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
147 22 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
148 22 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
149 22 ▶use Math::Random::MT;
Subroutine BEGIN: called CC=1 SCAR=0.0
150 22 ▶use Metabase::Resource;
Subroutine BEGIN: called CC=1 SCAR=0.0
151 22 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
152 22 ▶use MIME::QuotedPrint;
Subroutine BEGIN: called CC=1 SCAR=0.0
153 22 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
154 22 ▶use Parse::CPAN::Authors;
Subroutine BEGIN: called CC=1 SCAR=0.0
155 22 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
156 22 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
157 22 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
158 22 ▶use WWW::Mechanize;
Subroutine BEGIN: called CC=1 SCAR=0.0
159  
160 22 ▶use base qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
161  
162 # -------------------------------------
163 # Variables
164  
165 # default configuration settings
166 22 my %default = (
167 lastmail => '_lastmail',
168 verbose => 0,
169 nomail => 1,
170 logclean => 0,
171 mode => 'daily',
172 mailrc => 'data/01mailrc.txt'
173 );
174  
175 22 my $sponsorfile = 'sponsors.json';
176  
177 22 my (%AUTHORS,%PREFS,@SPONSORS,$MT,$IHEART);
178  
179 22 my %MODES = (
180 daily => { type => 1, period => '24 hours', report => 'Daily Summary' },
181 weekly => { type => 2, period => '7 days', report => 'Weekly Summary' }, # typically a Saturday
182 reports => { type => 3, period => '', report => 'Test' },
183 monthly => { type => 4, period => 'month', report => 'Monthly Summary' },
184 sun => { type => 5, period => '7 days', report => 'Weekly Summary' },
185 mon => { type => 6, period => '7 days', report => 'Weekly Summary' },
186 tue => { type => 7, period => '7 days', report => 'Weekly Summary' },
187 wed => { type => 8, period => '7 days', report => 'Weekly Summary' },
188 thu => { type => 9, period => '7 days', report => 'Weekly Summary' },
189 fri => { type => 10, period => '7 days', report => 'Weekly Summary' },
190 sat => { type => 11, period => '7 days', report => 'Weekly Summary' },
191 );
192  
193 22 my $FROM = 'CPAN Tester Report Server <do_not_reply@cpantesters.org>';
194 22 my $HOW = '/usr/sbin/sendmail -bm';
195 22 my $HEAD = 'To: "NAME" <EMAIL>
196 From: FROM
197 Date: DATE
198 Subject: SUBJECT
199  
200 ';
201  
202 22 my @dotw = ( "Sunday", "Monday", "Tuesday", "Wednesday",
203 "Thursday", "Friday", "Saturday" );
204  
205 22 my @months = (
206 { 'id' => 1, 'value' => "January", },
207 { 'id' => 2, 'value' => "February", },
208 { 'id' => 3, 'value' => "March", },
209 { 'id' => 4, 'value' => "April", },
210 { 'id' => 5, 'value' => "May", },
211 { 'id' => 6, 'value' => "June", },
212 { 'id' => 7, 'value' => "July", },
213 { 'id' => 8, 'value' => "August", },
214 { 'id' => 9, 'value' => "September", },
215 { 'id' => 10, 'value' => "October", },
216 { 'id' => 11, 'value' => "November", },
217 { 'id' => 12, 'value' => "December" },
218 );
219  
220 22 our %phrasebook = (
221 'LastReport' => "SELECT MAX(id) FROM cpanstats.cpanstats",
222 'GetEarliest' => "SELECT id FROM cpanstats.cpanstats WHERE fulldate > ? ORDER BY id LIMIT 1",
223  
224 'FindAuthorType' => "SELECT pauseid FROM prefs_distributions WHERE report = ?",
225  
226 'GetReports' => "SELECT id,guid,dist,version,platform,perl,state FROM cpanstats.cpanstats WHERE id > ? AND state IN ('pass','fail','na','unknown') ORDER BY id",
227 'GetReports2' => "SELECT c.id,c.guid,c.dist,c.version,c.platform,c.perl,c.state FROM cpanstats.cpanstats AS c INNER JOIN cpanstats.ixlatest AS x ON x.dist=c.dist WHERE c.id > ? AND c.state IN ('pass','fail','na','unknown') AND author IN (%s) ORDER BY c.id",
228 'GetReportCount' => "SELECT id FROM cpanstats.cpanstats WHERE platform=? AND perl=? AND state=? AND id < ? AND dist=? AND version=? LIMIT 2",
229 'GetLatestDistVers' => "SELECT version FROM cpanstats.uploads WHERE dist=? ORDER BY released DESC LIMIT 1",
230 'GetAuthor' => "SELECT author FROM cpanstats.uploads WHERE dist=? AND version=? LIMIT 1",
231 'GetAuthors' => "SELECT author,dist,version FROM cpanstats.uploads",
232  
233 'GetAuthorPrefs' => "SELECT * FROM prefs_authors WHERE pauseid=?",
234 'GetDefaultPrefs' => "SELECT * FROM prefs_authors AS a INNER JOIN prefs_distributions AS d ON d.pauseid=a.pauseid AND d.distribution='-' WHERE a.pauseid=?",
235 'GetDistPrefs' => "SELECT * FROM prefs_distributions WHERE pauseid=? AND distribution=?",
236 'InsertAuthorLogin' => 'INSERT INTO prefs_authors (active,lastlogin,pauseid) VALUES (1,?,?)',
237 'InsertDistPrefs' => "INSERT INTO prefs_distributions (pauseid,distribution,ignored,report,grade,tuple,version,patches,perl,platform) VALUES (?,?,0,1,'FAIL','FIRST','LATEST',0,'ALL','ALL')",
238  
239 'GetArticle' => "SELECT * FROM articles.articles WHERE id=?",
240  
241 'GetReportTest' => "SELECT id,guid,dist,version,platform,perl,state FROM cpanstats.cpanstats WHERE id = ? AND state IN ('pass','fail','na','unknown') ORDER BY id",
242  
243 'GetMetabaseByGUID' => 'SELECT * FROM metabase.metabase WHERE guid=?',
244 'GetTestersEmail' => 'SELECT * FROM metabase.testers_email',
245 'GetTesters' => 'SELECT * FROM metabase.testers_email ORDER BY id'
246 );
247  
248 #----------------------------------------------------------------------------
249 # The Application Programming Interface
250  
251 22 __PACKAGE__->mk_accessors(
252 qw( lastmail verbose nomail test logfile logclean mode mailrc tt pause ));
253  
254 # -------------------------------------
255 # The Public Interface Functions
256  
257 sub new {
258 2 ▶ my $class = shift;
Subroutine new: called CC=21 SCAR=53.2
Pod documented
259 2 my %hash = @_;
260  
261 2 my $self = {};
262 2 bless $self, $class;
263  
264 2 my %options;
265 2 ▶ GetOptions( \%options,
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions(\%options, "config=s", "lastmail=s", "mailrc=s", "test=i", "logfile=s", "logclean", "verbose", "nomail", "mode=s", "help|h", "version|v") or help(1) 0 2 2
266 'config=s',
267 'lastmail=s',
268 'mailrc=s',
269 'test=i',
270 'logfile=s',
271 'logclean',
272 'verbose',
273 'nomail',
274 'mode=s',
275 'help|h',
276 'version|v'
277 ) or help(1);
278  
279 # default to API settings if no command line option
280 2 for(qw(config help version)) {
281 6 ▶ $options{$_} ||= $hash{$_} if(defined $hash{$_});
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash{$_} 1 5 6
Condition33%1/3
$options{$_} ||= $hash{$_}
l!l&&r!l&&!r
010
MC/DC0%0/2
$options{$_} ||= $hash{$_}
$options{$_} $hash{$_}
Truth table33%1/3
A ||= B
A= $options{$_}B= $hash{$_}
ABresult
1X1
011
000
282 }
283  
284 2 ▶ $self->help(1) if($options{help});
Branch: 1 branch
BranchTrueFalseTotal
if $options{"help"} 0 2 2
285 2 ▶ $self->help(0) if($options{version});
Branch: 1 branch
BranchTrueFalseTotal
if $options{"version"} 0 2 2
286  
287 # ensure we have a configuration file
288 2 ▶ die "Must specify a configuration file\n" unless( $options{config});
Branch: 1 branch
BranchTrueFalseTotal
unless $options{"config"} 1 1 2
289 1 ▶ die "Configuration file [$options{config}] not found\n" unless(-f $options{config});
Branch: 1 branch
BranchTrueFalseTotal
unless -f $options{"config"} 1 0 1
290  
291 # load configuration
292 0 my $cfg = Config::IniFiles->new( -file => $options{config} );
293  
294 # configure databases
295 0 for my $db (qw(CPANPREFS)) {
296 0 ▶ die "No configuration for $db database\n" unless($cfg->SectionExists($db));
Branch: 1 branch
BranchTrueFalseTotal
unless $cfg->SectionExists($db) 0 0 0
297 0 my %opts;
298 0 for my $key (qw(driver database dbfile dbhost dbport dbuser dbpass)) {
299 0 my $val = $cfg->val($db,$key);
300 0 ▶ $opts{$key} = $val if(defined $val);
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 0 0 0
301 }
302 0 $self->{$db} = CPAN::Testers::Common::DBUtils->new(%opts);
303 0 ▶ die "Cannot configure $db database\n" unless($self->{$db});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{$db} 0 0 0
304 0 ▶ $self->{db}->{mysql_auto_reconnect} = 1 if($opts{driver} =~ /mysql/i);
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"driver"} =~ /mysql/i 0 0 0
305 }
306  
307 0 $self->test( $self->_defined_or( $options{test}, $hash{test}, $cfg->val('SETTINGS','test' ), 0 ) );
308 0 ▶ $options{nomail} = 1 if($self->test);
Branch: 1 branch
BranchTrueFalseTotal
if $self->test 0 0 0
309  
310 0 $self->verbose( $self->_defined_or( $options{verbose}, $hash{verbose}, $cfg->val('SETTINGS','verbose' ), $default{verbose}) );
311 0 $self->nomail( $self->_defined_or( $options{nomail}, $hash{nomail}, $cfg->val('SETTINGS','nomail' ), $default{nomail}) );
312 0 $self->lastmail($self->_defined_or( $options{lastmail}, $hash{lastmail}, $cfg->val('SETTINGS','lastmail' ), $default{lastmail}) );
313 0 $self->mailrc( $self->_defined_or( $options{mailrc}, $hash{mailrc}, $cfg->val('SETTINGS','mailrc' ), $default{mailrc} ) );
314 0 $self->logfile( $self->_defined_or( $options{logfile}, $hash{logfile}, $cfg->val('SETTINGS','logfile' ) ) );
315 0 $self->logclean($self->_defined_or( $options{logclean}, $hash{logclean}, $cfg->val('SETTINGS','logclean' ), $default{logclean} ) );
316 0 $self->mode(lc $self->_defined_or( $options{mode}, $hash{mode}, $cfg->val('SETTINGS','mode' ), $default{mode} ) );
317  
318 0 $IHEART = $cfg->val('SETTINGS','iheart_random' );
319  
320 0 my $mode = $self->mode;
321 0 ▶ if($mode =~ /day/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode =~ /day/) 0 0 0
322 0 $mode = substr($mode,0,3);
323 0 $self->mode($mode);
324 }
325  
326 0 ▶ unless($mode =~ /^(daily|weekly|reports|monthly|sun|mon|tue|wed|thu|fri|sat)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mode =~ /^(daily|weekly|reports|monthly|sun|mon|tue|wed|thu|fri|sat)$/) 0 0 0
327 0 die "mode can MUST be 'daily', 'weekly', 'monthly', 'reports', or a day of the week.\n";
328 }
329  
330 0 $self->pause($self->_download_mailrc());
331  
332 # set up API to Template Toolkit
333 0 $self->tt( Template->new(
334 {
335 EVAL_PERL => 1,
336 INCLUDE_PATH => [ 'templates' ],
337 }
338 ));
339  
340 0 my @testers = $self->{CPANPREFS}->get_query('hash',$phrasebook{'GetTestersEmail'});
341 0 for my $tester (@testers) {
342 0 ▶ $self->{testers}{$tester->{creator}}{name} ||= $tester->{fullname};
Condition0%0/3
$self->{"testers"}{$tester->{"creator"}}{"name"} ||= $tester->{"fullname"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"testers"}{$tester->{"creator"}}{"name"} ||= $tester->{"fullname"}
$self->{"testers"}{$tester->{"creator"}}{"name"} $tester->{"fullname"}
Truth table0%0/3
A ||= B
A= $self->{"testers"}{$tester->{"creator"}}{"name"}B= $tester->{"fullname"}
ABresult
1X1
011
000
343 0 ▶ $self->{testers}{$tester->{creator}}{email} ||= $tester->{email};
Condition0%0/3
$self->{"testers"}{$tester->{"creator"}}{"email"} ||= $tester->{"email"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"testers"}{$tester->{"creator"}}{"email"} ||= $tester->{"email"}
$self->{"testers"}{$tester->{"creator"}}{"email"} $tester->{"email"}
Truth table0%0/3
A ||= B
A= $self->{"testers"}{$tester->{"creator"}}{"email"}B= $tester->{"email"}
ABresult
1X1
011
000
344 }
345  
346 0 $self->_load_authors();
347 0 $self->_load_testers();
348 0 $self->_load_sponsors();
349  
350 0 return $self;
351 }
352  
353 sub check_reports {
354 0 ▶ my $self = shift;
Subroutine check_reports: not called CC=90 SCAR=90.1
Pod documented
355 0 my $mode = $self->mode;
356 0 my $report_type = $MODES{$mode}->{type};
357 0 my $last_id = int( $self->_get_lastid() );
358 0 my (%reports,%tvars);
359  
360 0 $self->_log( "INFO: START checking reports in '$mode' mode\n" );
361 0 $self->_log( "INFO: last_id=$last_id\n" );
362  
363 0 my $next;
364 0 ▶ if($self->test) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->test) { } 0 0 0
elsif ($mode ne 'daily') { } 0 0 0
365 0 $next = $self->{CPANPREFS}->iterator('hash',$phrasebook{'GetReportTest'},$self->test);
366 } elsif($mode ne 'daily') {
367 0 my @authors = $self->{CPANPREFS}->get_query('hash',$phrasebook{'FindAuthorType'}, $report_type);
368 0 ▶ return $self->_set_lastid() unless(@authors);
Branch: 1 branch
BranchTrueFalseTotal
unless @authors 0 0 0
369 0 my $sql = sprintf $phrasebook{'GetReports2'}, join(',',map {"'$_->{pauseid}'"} @authors);
370 0 $next = $self->{CPANPREFS}->iterator('hash',$sql,$last_id);
371 } else {
372 # find all reports since last update
373 0 $next = $self->{CPANPREFS}->iterator('hash',$phrasebook{'GetReports'},$last_id);
374 0 ▶ unless($next) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($next) 0 0 0
375 0 $self->_log( "INFO: STOP checking reports\n" );
376 0 return;
377 }
378 }
379  
380 0 my $rows = 0;
381 0 ▶ while( my $row = $next->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = &$next()) 0 0 0
382 0 $rows++;
383 0 ▶ $self->_log( "DEBUG: processing report: $row->{id}\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
384  
385 0 $self->{counts}{REPORTS}++;
386 0 $last_id = $row->{id};
387 0 $row->{state} = uc $row->{state};
388 0 $self->{counts}{$row->{state}}++;
389  
390 0 ▶ $self->_log( "DEBUG: dist: $row->{dist} $row->{version} $row->{state}\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
391  
392 0 my $author = $self->_get_author($row->{dist}, $row->{version});
393 0 ▶ $self->_log( "DEBUG: author: ".($author||'')."\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
Condition0%0/2
$author || ''
l!l
00
MC/DC0%0/1
$author || ''
$author
Truth table0%0/2
A
A= $author
Aresult
11
00
394 0 ▶ next unless($author);
Branch: 1 branch
BranchTrueFalseTotal
unless $author 0 0 0
395  
396 0 ▶ unless($author) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($author) 0 0 0
397 0 $self->_log( "WARN: author not found for distribution [$row->{dist}], [$row->{version}]\n" );
398 0 next;
399 }
400  
401 0 ▶ $row->{version} ||= '';
Condition0%0/2
$row->{"version"} ||= ""
l!l
00
MC/DC0%0/1
$row->{"version"} ||= ""
$row->{"version"}
Truth table0%0/2
A
A= $row->{"version"}
Aresult
11
00
402 0 ▶ $row->{platform} ||= '';
Condition0%0/2
$row->{"platform"} ||= ""
l!l
00
MC/DC0%0/1
$row->{"platform"} ||= ""
$row->{"platform"}
Truth table0%0/2
A
A= $row->{"platform"}
Aresult
11
00
403 0 ▶ $row->{perl} ||= '';
Condition0%0/2
$row->{"perl"} ||= ""
l!l
00
MC/DC0%0/1
$row->{"perl"} ||= ""
$row->{"perl"}
Truth table0%0/2
A
A= $row->{"perl"}
Aresult
11
00
404  
405 # get author preferences
406 0 ▶ my $prefs = $self->_get_prefs($author) || next;
Condition0%0/2
$self->_get_prefs($author) || (next)
l!l
00
MC/DC0%0/1
$self->_get_prefs($author) || (next)
$self->_get_prefs($author)
Truth table0%0/2
A
A= $self->_get_prefs($author)
Aresult
11
00
407  
408 # do we need to worry about this author?
409 0 ▶ if($prefs->{active} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prefs->{"active"} == 2) 0 0 0
410 0 $self->{counts}{NOMAIL}++;
411 0 ▶ $self->_log( "DEBUG: author: $author - not active\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
412 0 next;
413 }
414  
415 # get distribution preferences
416 0 $prefs = $self->_get_prefs($author, $row->{dist});
417 0 ▶ $self->_log( "DEBUG: dist prefs: " .($prefs ? 'Found' : 'Not Found')."\n" ) if($self->verbose);
Branch: 2 branches
BranchTrueFalseTotal
if $self->verbose 0 0 0
$prefs ? : 0 0 0
418 0 ▶ next unless($prefs);
Branch: 1 branch
BranchTrueFalseTotal
unless $prefs 0 0 0
419 0 ▶ $self->_log( "DEBUG: dist prefs: ignored=" .($prefs->{ignored} || 0)."\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
Condition0%0/2
$prefs->{'ignored'} || 0
l!l
00
MC/DC0%0/1
$prefs->{'ignored'} || 0
$prefs->{'ignored'}
Truth table0%0/2
A
A= $prefs->{'ignored'}
Aresult
11
00
420 0 ▶ next if($prefs->{ignored});
Branch: 1 branch
BranchTrueFalseTotal
if $prefs->{"ignored"} 0 0 0
421 0 ▶ $self->_log( "DEBUG: dist prefs: report=$prefs->{report}, report type=$report_type\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
422 0 ▶ next if($prefs->{report} != $report_type);
Branch: 1 branch
BranchTrueFalseTotal
if $prefs->{"report"} != $report_type 0 0 0
423 0 ▶ $self->_log( "DEBUG: dist prefs: $row->{state}=" .($prefs->{grades}{$row->{state}}||'undef')."\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
Condition0%0/2
$prefs->{'grades'}{$row->{'state'}} || 'undef'
l!l
00
MC/DC0%0/1
$prefs->{'grades'}{$row->{'state'}} || 'undef'
$prefs->{'grades'}{$row->{'state'}}
Truth table0%0/2
A
A= $prefs->{'grades'}{$row->{'state'}}
Aresult
11
00
424 0 ▶ $self->_log( "DEBUG: dist prefs: ALL=" .($prefs->{grades}{ALL}||'undef')."\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
Condition0%0/2
$prefs->{'grades'}{'ALL'} || 'undef'
l!l
00
MC/DC0%0/1
$prefs->{'grades'}{'ALL'} || 'undef'
$prefs->{'grades'}{'ALL'}
Truth table0%0/2
A
A= $prefs->{'grades'}{'ALL'}
Aresult
11
00
425 0 ▶ next unless($prefs->{grades}{$row->{state}} || $prefs->{grades}{'ALL'});
Branch: 1 branch
BranchTrueFalseTotal
unless $prefs->{"grades"}{$row->{"state"}} or $prefs->{"grades"}{"ALL"} 0 0 0
Condition0%0/3
$prefs->{"grades"}{$row->{"state"}} or $prefs->{"grades"}{"ALL"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$prefs->{"grades"}{$row->{"state"}} or $prefs->{"grades"}{"ALL"}
$prefs->{"grades"}{$row->{"state"}} $prefs->{"grades"}{"ALL"}
Truth table0%0/3
A or B
A= $prefs->{"grades"}{$row->{"state"}}B= $prefs->{"grades"}{"ALL"}
ABresult
1X1
011
000
426 0 ▶ $self->_log( "DEBUG: dist prefs: CONTINUE\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
427  
428 # Check whether distribution version is required.
429 # If version set to 'LATEST' check this is the current version, if set
430 # to 'ALL' then we should allow EVERYTHING through, otherwise filter
431 # on the requested versions.
432  
433 0 ▶ if($row->{version} && $prefs->{version} && $prefs->{version} ne 'ALL') {
Branch: 1 branch
BranchTrueFalseTotal
if ($row->{"version"} and $prefs->{"version"} and $prefs->{"version"} ne "ALL") 0 0 0
Condition0%0/6
$row->{"version"} and $prefs->{"version"} and $prefs->{"version"} ne "ALL"
!ll&&!rl&&r
000
$row->{"version"} and $prefs->{"version"}
!ll&&!rl&&r
000
MC/DC0%0/3
$row->{"version"} and $prefs->{"version"} and $prefs->{"version"} ne "ALL"
$row->{"version"} $prefs->{"version"} $prefs->{"version"} ne "ALL"
Truth table0%0/4
A and B and C
A= $row->{"version"}B= $prefs->{"version"}C= $prefs->{"version"} ne "ALL"
ABCresult
0XX0
10X0
1100
1111
434 0 ▶ if($prefs->{version} eq 'LATEST') {
Branch: 1 branch
BranchTrueFalseTotal
if ($prefs->{'version'} eq 'LATEST') { } 0 0 0
435 0 my @vers = $self->{CPANPREFS}->get_query('array',$phrasebook{'GetLatestDistVers'},$row->{dist});
436 0 ▶ $self->_log( "DEBUG: dist prefs: vers=".(scalar(@vers))."\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
437 0 ▶ $self->_log( "DEBUG: dist prefs: version=$vers[0]->[0], $row->{version}\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
438 0 ▶ next if(@vers && $vers[0]->[0] ne $row->{version});
Branch: 1 branch
BranchTrueFalseTotal
if @vers and $vers[0][0] ne $row->{"version"} 0 0 0
Condition0%0/3
@vers and $vers[0][0] ne $row->{"version"}
!ll&&!rl&&r
000
MC/DC0%0/2
@vers and $vers[0][0] ne $row->{"version"}
@vers $vers[0][0] ne $row->{"version"}
Truth table0%0/3
A and B
A= @versB= $vers[0][0] ne $row->{"version"}
ABresult
0X0
100
111
439 } else {
440 0 $prefs->{version} =~ s/\s*//g;
441 0 my %m = map {$_ => 1} split(',',$prefs->{version});
442 0 ▶ $self->_log( "DEBUG: dist prefs: $row->{version}\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
443 0 ▶ next unless($m{$row->{version}});
Branch: 1 branch
BranchTrueFalseTotal
unless $m{$row->{"version"}} 0 0 0
444 }
445 }
446  
447 # Check whether this platform is required.
448 0 ▶ if($row->{platform} && $prefs->{platform} && $prefs->{platform} ne 'ALL') {
Branch: 1 branch
BranchTrueFalseTotal
if ($row->{"platform"} and $prefs->{"platform"} and $prefs->{"platform"} ne "ALL") 0 0 0
Condition0%0/6
$row->{"platform"} and $prefs->{"platform"} and $prefs->{"platform"} ne "ALL"
!ll&&!rl&&r
000
$row->{"platform"} and $prefs->{"platform"}
!ll&&!rl&&r
000
MC/DC0%0/3
$row->{"platform"} and $prefs->{"platform"} and $prefs->{"platform"} ne "ALL"
$row->{"platform"} $prefs->{"platform"} $prefs->{"platform"} ne "ALL"
Truth table0%0/4
A and B and C
A= $row->{"platform"}B= $prefs->{"platform"}C= $prefs->{"platform"} ne "ALL"
ABCresult
0XX0
10X0
1100
1111
449 0 $prefs->{platform} =~ s/\s*//g;
450 0 $prefs->{platform} =~ s/,/|/g;
451 0 $prefs->{platform} =~ s/\./\\./g;
452 0 $prefs->{platform} =~ s/^(\w+)\|//;
453 0 ▶ if($1 && $1 eq 'NOT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 and $1 eq 'NOT') { } 0 0 0
Condition0%0/3
$1 and $1 eq "NOT"
!ll&&!rl&&r
000
MC/DC0%0/2
$1 and $1 eq "NOT"
$1 $1 eq "NOT"
Truth table0%0/3
A and B
A= $1B= $1 eq "NOT"
ABresult
0X0
100
111
454 0 ▶ $self->_log( "DEBUG: dist prefs: $row->{platform}, =~ $prefs->{platform}\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
455 0 ▶ next if($row->{platform} =~ /$prefs->{platform}/);
Branch: 1 branch
BranchTrueFalseTotal
if $row->{"platform"} =~ /$prefs->{"platform"}/ 0 0 0
456 } else {
457 0 ▶ $self->_log( "DEBUG: dist prefs: $row->{platform}, !~ $prefs->{platform}\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
458 0 ▶ next if($row->{platform} !~ /$prefs->{platform}/);
Branch: 1 branch
BranchTrueFalseTotal
unless $row->{"platform"} =~ /$prefs->{"platform"}/ 0 0 0
459 }
460 }
461  
462 # Check whether this perl version is required.
463 0 ▶ if($row->{perl} && $prefs->{perl} && $prefs->{perl} ne 'ALL') {
Branch: 1 branch
BranchTrueFalseTotal
if ($row->{"perl"} and $prefs->{"perl"} and $prefs->{"perl"} ne "ALL") 0 0 0
Condition0%0/6
$row->{"perl"} and $prefs->{"perl"} and $prefs->{"perl"} ne "ALL"
!ll&&!rl&&r
000
$row->{"perl"} and $prefs->{"perl"}
!ll&&!rl&&r
000
MC/DC0%0/3
$row->{"perl"} and $prefs->{"perl"} and $prefs->{"perl"} ne "ALL"
$row->{"perl"} $prefs->{"perl"} $prefs->{"perl"} ne "ALL"
Truth table0%0/4
A and B and C
A= $row->{"perl"}B= $prefs->{"perl"}C= $prefs->{"perl"} ne "ALL"
ABCresult
0XX0
10X0
1100
1111
464 0 my $perlv = $row->{perl};
465 0 $perlv = $row->{perl};
466 0 $perlv =~ s/\s.*//;
467  
468 0 $prefs->{perl} =~ s/\s*//g;
469 0 $prefs->{perl} =~ s/,/|/g;
470 0 $prefs->{perl} =~ s/\./\\./g;
471 0 my $v = version->new("$perlv")->numify;
472 0 $prefs->{platform} =~ s/^(\w+)\|//;
473 0 ▶ if($1 && $1 eq 'NOT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 and $1 eq 'NOT') { } 0 0 0
Condition0%0/3
$1 and $1 eq "NOT"
!ll&&!rl&&r
000
MC/DC0%0/2
$1 and $1 eq "NOT"
$1 $1 eq "NOT"
Truth table0%0/3
A and B
A= $1B= $1 eq "NOT"
ABresult
0X0
100
111
474 0 ▶ $self->_log( "DEBUG: dist prefs: $perlv || $v =~ $prefs->{perl}\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
475 0 ▶ next if($perlv =~ /$prefs->{perl}/ && $v =~ /$prefs->{perl}/);
Branch: 1 branch
BranchTrueFalseTotal
if $perlv =~ /$prefs->{"perl"}/ and $v =~ /$prefs->{"perl"}/ 0 0 0
Condition0%0/3
$perlv =~ /$prefs->{"perl"}/ and $v =~ /$prefs->{"perl"}/
!ll&&!rl&&r
000
MC/DC0%0/2
$perlv =~ /$prefs->{"perl"}/ and $v =~ /$prefs->{"perl"}/
$perlv =~ /$prefs->{"perl"}/ $v =~ /$prefs->{"perl"}/
Truth table0%0/3
A and B
A= $perlv =~ /$prefs->{"perl"}/B= $v =~ /$prefs->{"perl"}/
ABresult
0X0
100
111
476 } else {
477 0 ▶ $self->_log( "DEBUG: dist prefs: $perlv || $v !~ $prefs->{perl}\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
478 0 ▶ next if($perlv !~ /$prefs->{perl}/ && $v !~ /$prefs->{perl}/);
Branch: 1 branch
BranchTrueFalseTotal
unless $perlv =~ /$prefs->{"perl"}/ or $v =~ /$prefs->{"perl"}/ 0 0 0
Condition0%0/3
$perlv =~ /$prefs->{"perl"}/ or $v =~ /$prefs->{"perl"}/
l!l&&r!l&&!r
000
MC/DC0%0/2
$perlv =~ /$prefs->{"perl"}/ or $v =~ /$prefs->{"perl"}/
$perlv =~ /$prefs->{"perl"}/ $v =~ /$prefs->{"perl"}/
Truth table0%0/3
A or B
A= $perlv =~ /$prefs->{"perl"}/B= $v =~ /$prefs->{"perl"}/
ABresult
1X1
011
000
479 }
480 }
481  
482 # Check whether patches are required.
483 0 ▶ $self->_log( "DEBUG: dist prefs: patches=$prefs->{patches}, row perl $row->{perl}\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
484 0 ▶ next if(!$prefs->{patches} && $row->{perl} =~ /(RC\d+|patch)/);
Branch: 1 branch
BranchTrueFalseTotal
if not $prefs->{"patches"} and $row->{"perl"} =~ /(RC\d+|patch)/ 0 0 0
Condition0%0/3
not $prefs->{"patches"} and $row->{"perl"} =~ /(RC\d+|patch)/
!ll&&!rl&&r
000
MC/DC0%0/2
not $prefs->{"patches"} and $row->{"perl"} =~ /(RC\d+|patch)/
not $prefs->{"patches"} $row->{"perl"} =~ /(RC\d+|patch)/
Truth table0%0/3
not(A) and B
A= not $prefs->{"patches"}B= $row->{"perl"} =~ /(RC\d+|patch)/
ABresult
0X0
100
111
485  
486 # check whether only first instance required
487 0 ▶ if($prefs->{tuple} eq 'FIRST') {
Branch: 1 branch
BranchTrueFalseTotal
if ($prefs->{"tuple"} eq "FIRST") 0 0 0
488 my @count = $self->{CPANPREFS}->get_query('array',$phrasebook{'GetReportCount'},
489 0 $row->{platform}, $row->{perl}, $row->{state}, $row->{id}, $row->{dist}, $row->{version});
490 0 ▶ $self->_log( "DEBUG: dist prefs: tuple=FIRST, count=".(scalar(@count))."\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
491 0 ▶ next if(@count > 0);
Branch: 1 branch
BranchTrueFalseTotal
if @count > 0 0 0 0
492 }
493  
494 0 ▶ $self->_log( "DEBUG: report is being added to mailshot\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
495  
496 0 ▶ if($mode eq 'reports') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "reports") 0 0 0
497 0 $self->_send_report($author,$row);
498 }
499  
500 0 ▶ push @{$reports{$author}->{dists}{$row->{dist}}->{versions}{$row->{version}}->{platforms}{$row->{platform}}->{perls}{$row->{perl}}->{states}{uc $row->{state}}->{value}}, ($row->{guid} || $row->{id});
Condition0%0/3
$row->{'guid'} || $row->{'id'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$row->{'guid'} || $row->{'id'}
$row->{'guid'} $row->{'id'}
Truth table0%0/3
A || B
A= $row->{'guid'}B= $row->{'id'}
ABresult
1X1
011
000
501 }
502  
503 0 $self->_log( "INFO: STOP checking reports in '$mode' mode\n" );
504  
505 0 ▶ return $self->_set_lastid() unless($rows);
Branch: 1 branch
BranchTrueFalseTotal
unless $rows 0 0 0
506  
507 0 ▶ if($mode ne 'reports') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode ne "reports") 0 0 0
508 0 $self->_log( "INFO: START parsing data in '$mode' mode\n" );
509 0 ▶ $self->_log( "DEBUG: processing authors: ".(scalar(keys %reports))."\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
510  
511 0 for my $author (sort keys %reports) {
512 0 ▶ $self->_log( "DEBUG: $author\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
513  
514 0 my $pause = $self->pause->author($author);
515 0 ▶ $tvars{name} = $pause ? $pause->name : $author;
Branch: 1 branch
BranchTrueFalseTotal
$pause ? : 0 0 0
516 0 $tvars{author} = $author;
517 0 $tvars{dists} = ();
518  
519 # get author preferences
520 0 my $prefs = $self->_get_prefs($author);
521  
522 # active:
523 # 0 - new author, no correspondance
524 # 1 - new author, notification mailed
525 # 2 - author requested no mail
526 # 3 - author requested summary report
527  
528 0 ▶ if(!$prefs->{active} || $prefs->{active} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $prefs->{"active"} or $prefs->{"active"} == 0) 0 0 0
Condition0%0/3
not $prefs->{"active"} or $prefs->{"active"} == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not $prefs->{"active"} or $prefs->{"active"} == 0
not $prefs->{"active"} $prefs->{"active"} == 0
Truth table0%0/3
not(A) or B
A= not $prefs->{"active"}B= $prefs->{"active"} == 0
ABresult
1X1
011
000
529 0 $tvars{subject} = 'Welcome to CPAN Testers';
530 0 $self->_write_mail('notification.eml',\%tvars);
531 0 $self->{counts}{NEWAUTH}++;
532  
533 # insert author defaults, however check that they don't already
534 # exists in the system first, in case entries are out of sync.
535 0 my @auth = $self->{CPANPREFS}->get_query('hash',$phrasebook{'GetAuthorPrefs'}, $author);
536 0 ▶ $self->{CPANPREFS}->do_query($phrasebook{'InsertAuthorLogin'}, time(), $author) unless(@auth);
Branch: 1 branch
BranchTrueFalseTotal
unless @auth 0 0 0
537 0 my @dist = $self->{CPANPREFS}->get_query('hash',$phrasebook{'GetDistPrefs'}, $author,'-');
538 0 ▶ $self->{CPANPREFS}->do_query($phrasebook{'InsertDistPrefs'}, $author, '-') unless(@dist);
Branch: 1 branch
BranchTrueFalseTotal
unless @dist 0 0 0
539 }
540  
541 0 ▶ $self->_log( "DEBUG: $author - distributions = ".(scalar(keys %{$reports{$author}->{dists}}))."\n" ) if($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
542  
543 0 my ($reports,@e);
544 0 for my $dist (sort keys %{$reports{$author}->{dists}}) {
545 0 my $v = $reports{$author}->{dists}{$dist};
546 0 my @d;
547 0 for my $version (sort keys %{$v->{versions}}) {
548 0 my $w = $v->{versions}{$version};
549 0 my @c;
550 0 for my $platform (sort keys %{$w->{platforms}}) {
551 0 my $x = $w->{platforms}{$platform};
552 0 my @b;
553 0 for my $perl (sort keys %{$x->{perls}}) {
554 0 my $y = $x->{perls}{$perl};
555 0 my @a;
556 0 for my $state (sort keys %{$y->{states}}) {
557 0 my $z = $y->{states}{$state};
558 0 push @a, {state => $state, ids => $z->{value}};
559 0 $reports++;
560 }
561 0 push @b, {perl => $perl, states => \@a};
562 }
563 0 push @c, {platform => $platform, perls => \@b};
564 }
565 0 push @d, {version => $version, platforms => \@c};
566 }
567 0 push @e, {dist => $dist, versions => \@d};
568 }
569  
570 0 ▶ next unless($reports);
Branch: 1 branch
BranchTrueFalseTotal
unless $reports 0 0 0
571 0 ▶ if($self->verbose) { $self->_log( "DEBUG: $author - reports = $reports\n" ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) { } 0 0 0
572 0 else { $self->_log( "INFO: $author - dists=".(scalar(keys %{$reports{$author}->{dists}})).", reports=$reports\n" ) }
573  
574 0 $tvars{dists} = \@e;
575 0 $tvars{period} = $MODES{$mode}->{period};
576 0 $tvars{report} = $MODES{$mode}->{report};
577 0 $tvars{subject} = "CPAN Testers $tvars{report} Report";
578  
579 0 $self->_write_mail('mailer.eml',\%tvars);
580 }
581  
582 0 $self->_log( "INFO: STOP parsing data in '$mode' mode\n" );
583 }
584  
585 0 $self->_set_lastid($last_id);
586 }
587  
588 sub check_counts {
589 0 ▶ my $self = shift;
Subroutine check_counts: not called CC=4 SCAR=30.0
Pod documented
590 0 my $mode = $self->mode;
591  
592 0 $self->_log( "INFO: COUNTS for '$mode' mode:\n" );
593 0 my @counts = qw(REPORTS PASS FAIL UNKNOWN NA NOMAIL MAILS NEWAUTH GOOD BAD);
594 0 ▶ push @counts, 'TEST' if($self->nomail);
Branch: 1 branch
BranchTrueFalseTotal
if $self->nomail 0 0 0
595  
596 0 for(@counts) {
597 0 ▶ $self->{counts}{$_} ||= 0;
Condition0%0/2
$self->{"counts"}{$_} ||= 0
l!l
00
MC/DC0%0/1
$self->{"counts"}{$_} ||= 0
$self->{"counts"}{$_}
Truth table0%0/2
A
A= $self->{"counts"}{$_}
Aresult
11
00
598 0 $self->_log( sprintf "INFO: %7s = %6d\n", $_, $self->{counts}{$_} );
599 }
600 }
601  
602 sub help {
603 0 ▶ my ($self,$full) = @_;
Subroutine help: not called CC=2 SCAR=17.9
Pod documented
604  
605 0 ▶ if($full) {
Branch: 1 branch
BranchTrueFalseTotal
if ($full) 0 0 0
606 0 print <<HERE;
607  
608 Usage: $0 --config=<file> \\
609 [--logfile=<file> [--logclean]] [--verbose] [--nomail] \\
610 [--test=<id>] [--lastmail=<file>] \\
611 [--mode=(daily|weekly|report|monthly|sun|mon|tue|wed|thu|fri|sat)] \\
612 [-h] [-v]
613  
614 --config=<file> database configuration file
615 --logfile=<file> log file (*)
616 --logclean 0 = append, 1 = overwrite (*)
617 --verbose print additional log messages
618 --nomail nomail flag, no mail sent if true (*)
619 --test=<id> test an id in debug mode, no mail sent (*)
620 --lastmail=<file> lastmail counter file (*)
621 --mode run mode (*)
622 -h this help screen
623 -v program version
624  
625 NOTES:
626 * - these will override any settings within the configuration file.
627 HERE
628  
629 }
630  
631 0 print "$0 v$VERSION\n";
632 0 exit(0);
633 }
634  
635 #----------------------------------------------------------------------------
636 # Internal Methods
637  
638 sub _get_lastid {
639 0 ▶ my ($self,$id) = @_;
Subroutine _get_lastid: not called CC=5 SCAR=34.0
640 0 my $mode = $self->mode;
641  
642 0 ▶ unless( -f $self->lastmail ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $self->lastmail) 0 0 0
643 0 mkpath(dirname($self->lastmail));
644 0 overwrite_file( $self->lastmail, 'daily=0,weekly=0,reports=0' );
645 }
646  
647 0 ▶ if (defined $id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id) 0 0 0
648 0 my $text = read_file($self->lastmail);
649 0 ▶ if($text =~ m!$mode=\d+!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /$mode=\d+/) { } 0 0 0
650 0 $text =~ s!($mode=)\d+!$1$id!;
651 } else {
652 0 $text .= ",$mode=$id"; # auto add mode
653 }
654 0 $text =~ s/\s+//g;
655 0 overwrite_file( $self->lastmail, $text );
656 0 return $id;
657 }
658  
659 0 my $text = read_file($self->lastmail);
660 0 ▶ return $id if(($id) = $text =~ m!$mode=(\d+)!);
Branch: 1 branch
BranchTrueFalseTotal
if ($id) = $text =~ /$mode=(\d+)/ 0 0 0
661 0 return $self->_get_earliest(); # mode not found, find earliest id based on mode
662 }
663  
664 sub _set_lastid {
665 0 ▶ my ($self,$id) = @_;
Subroutine _set_lastid: not called CC=4 SCAR=30.0
666  
667 0 ▶ if(!defined $id) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $id) 0 0 0
668 0 my @lastid = $self->{CPANPREFS}->get_query('array',$phrasebook{'LastReport'});
669 0 ▶ $id = @lastid ? $lastid[0]->[0] : 0;
Branch: 1 branch
BranchTrueFalseTotal
@lastid ? : 0 0 0
670 }
671  
672 0 $self->_log( "INFO: new last_id=$id\n" );
673 0 $self->_log( "INFO: STOP checking reports\n" );
674  
675 0 ▶ return $id if($self->nomail);
Branch: 1 branch
BranchTrueFalseTotal
if $self->nomail 0 0 0
676  
677 0 $self->_get_lastid($id);
678 }
679  
680 sub _get_earliest {
681 0 ▶ my $self = shift;
Subroutine _get_earliest: not called CC=15 SCAR=54.8
682 0 my $mode = $self->mode;
683  
684 0 my @date = localtime(time);
685 0 $date[5] += 1900;
686 0 $date[4] += 1;
687 0 ▶ if($mode eq 'monthly') {
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq 'monthly') { } 0 0 0
elsif ($mode eq 'daily' or $mode eq 'reports') { } 0 0 0
688 0 $date[4] -= 1;
689 0 $date[3] = 1;
690 ▶ } elsif($mode eq 'daily' || $mode eq 'reports') {
Condition0%0/3
$mode eq "daily" or $mode eq "reports"
l!l&&r!l&&!r
000
MC/DC0%0/2
$mode eq "daily" or $mode eq "reports"
$mode eq "daily" $mode eq "reports"
Truth table0%0/3
A or B
A= $mode eq "daily"B= $mode eq "reports"
ABresult
1X1
011
000
691 0 $date[3] -= 1;
692 } else {
693 0 $date[3] -=7;
694 }
695  
696 0 ▶ if($date[3] < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($date[3] < 1) 0 0 0
697 0 $date[4] -= 1;
698 0 ▶ if($date[4] == 2 && $date[5] % 4) {
Branch: 3 branches
BranchTrueFalseTotal
if ($date[4] == 2 and $date[5] % 4) { } 0 0 0
elsif ($date[3] == 2) { } 0 0 0
elsif ($date[3] == 4 or $date[3] == 6 or $date[3] == 9 or $date[3] == 11) { } 0 0 0
Condition0%0/3
$date[4] == 2 and $date[5] % 4
!ll&&!rl&&r
000
MC/DC0%0/2
$date[4] == 2 and $date[5] % 4
$date[4] == 2 $date[5] % 4
Truth table0%0/3
A and B
A= $date[4] == 2B= $date[5] % 4
ABresult
0X0
100
111
699 0 $date[3] = 28 - $date[3];
700 } elsif($date[3] == 2) {
701 0 $date[3] = 29 - $date[3];
702 ▶ } elsif($date[3] == 4 || $date[3] == 6 || $date[3] == 9 || $date[3] == 11) {
Condition0%0/9
$date[3] == 4 or $date[3] == 6 or $date[3] == 9 or $date[3] == 11
l!l&&r!l&&!r
000
$date[3] == 4 or $date[3] == 6 or $date[3] == 9
l!l&&r!l&&!r
000
$date[3] == 4 or $date[3] == 6
l!l&&r!l&&!r
000
MC/DC0%0/4
$date[3] == 4 or $date[3] == 6 or $date[3] == 9 or $date[3] == 11
$date[3] == 4 $date[3] == 6 $date[3] == 9 $date[3] == 11
Truth table0%0/5
A or B or C or D
A= $date[3] == 4B= $date[3] == 6C= $date[3] == 9D= $date[3] == 11
ABCDresult
1XXX1
01XX1
001X1
00011
00000
703 0 $date[3] = 30 - $date[3];
704 } else {
705 0 $date[3] = 31 - $date[3];
706 }
707 0 ▶ if($date[4] < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($date[4] < 1) 0 0 0
708 0 $date[4] = 12;
709 0 $date[5] -= 1;
710 }
711 }
712  
713 0 my $fulldate = sprintf "%04d%02d%02d000000", $date[5], $date[4], $date[3];
714 0 my @report = $self->{CPANPREFS}->get_query('array',$phrasebook{'GetEarliest'}, $fulldate);
715 0 ▶ return 0 unless(@report);
Branch: 1 branch
BranchTrueFalseTotal
unless @report 0 0 0
716 0 ▶ return $report[0]->[0] || 0;
Condition0%0/2
$report[0][0] || 0
l!l
00
MC/DC0%0/1
$report[0][0] || 0
$report[0][0]
Truth table0%0/2
A
A= $report[0][0]
Aresult
11
00
717 }
718  
719 sub _get_prefs {
720 0 ▶ my $self = shift;
Subroutine _get_prefs: not called CC=13 SCAR=52.0
721 0 my ($author,$dist) = @_;
722 0 my $active = 0;
723  
724 0 ▶ return unless($author);
Branch: 1 branch
BranchTrueFalseTotal
unless $author 0 0 0
725  
726 # get distribution defaults
727 0 ▶ if($author && $dist) {
Branch: 1 branch
BranchTrueFalseTotal
if ($author and $dist) 0 0 0
Condition0%0/3
$author and $dist
!ll&&!rl&&r
000
MC/DC0%0/2
$author and $dist
$author $dist
Truth table0%0/3
A and B
A= $authorB= $dist
ABresult
0X0
100
111
728 0 ▶ if(defined $PREFS{$author}{dists}{$dist}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PREFS{$author}{"dists"}{$dist}) 0 0 0
729 0 return $PREFS{$author}{dists}{$dist};
730 }
731  
732 0 my @rows = $self->{CPANPREFS}->get_query('hash',$phrasebook{'GetDistPrefs'}, $author,$dist);
733 0 ▶ if(@rows) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rows) 0 0 0
734 0 $PREFS{$author}{dists}{$dist} = $self->_parse_prefs($rows[0]);
735 0 return $PREFS{$author}{dists}{$dist};
736 }
737  
738 # fall through and assume author defaults
739 }
740  
741 # get author defaults
742 0 ▶ if($author) {
Branch: 1 branch
BranchTrueFalseTotal
if ($author) 0 0 0
743 0 ▶ if(defined $PREFS{$author}{default}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $PREFS{$author}{"default"}) 0 0 0
744 0 return $PREFS{$author}{default};
745 }
746  
747 0 my @auth = $self->{CPANPREFS}->get_query('hash',$phrasebook{'GetAuthorPrefs'}, $author);
748 0 ▶ if(@auth) {
Branch: 1 branch
BranchTrueFalseTotal
if (@auth) 0 0 0
749 0 ▶ $PREFS{$author}{default}{active} = $auth[0]->{active} || 0;
Condition0%0/2
$auth[0]{'active'} || 0
l!l
00
MC/DC0%0/1
$auth[0]{'active'} || 0
$auth[0]{'active'}
Truth table0%0/2
A
A= $auth[0]{'active'}
Aresult
11
00
750  
751 0 my @rows = $self->{CPANPREFS}->get_query('hash',$phrasebook{'GetDefaultPrefs'}, $author);
752 0 ▶ if(@rows) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rows) { } 0 0 0
753 0 $PREFS{$author}{default} = $self->_parse_prefs($rows[0]);
754 0 ▶ $PREFS{$author}{default}{active} = $rows[0]->{active} || 0;
Condition0%0/2
$rows[0]{'active'} || 0
l!l
00
MC/DC0%0/1
$rows[0]{'active'} || 0
$rows[0]{'active'}
Truth table0%0/2
A
A= $rows[0]{'active'}
Aresult
11
00
755 0 return $PREFS{$author}{default};
756 } else {
757 0 $self->{CPANPREFS}->do_query($phrasebook{'InsertDistPrefs'}, $author, '-');
758 0 $active = $PREFS{$author}{default}{active};
759 }
760 }
761  
762 # fall through and assume new author
763 }
764  
765 0 ▶ $dist ||= '-';
Condition0%0/2
$dist ||= "-"
l!l
00
MC/DC0%0/1
$dist ||= "-"
$dist
Truth table0%0/2
A
A= $dist
Aresult
11
00
766  
767 # use global defaults
768 0 my %prefs = (
769 active => $active,
770 ignored => 0,
771 report => 1,
772 grades => {'FAIL' => 1},
773 tuple => 'FIRST',
774 version => 'LATEST',
775 patches => 0,
776 perl => 'ALL',
777 platform => 'ALL',
778 );
779 0 $PREFS{$author}{dists}{$dist} = \%prefs;
780 0 return \%prefs;
781 }
782  
783 sub _parse_prefs {
784 0 ▶ my ($self,$row) = @_;
Subroutine _parse_prefs: not called CC=2 SCAR=17.9
785 0 my %hash;
786  
787 0 ▶ $row->{grade} ||= 'FAIL';
Condition0%0/2
$row->{"grade"} ||= "FAIL"
l!l
00
MC/DC0%0/1
$row->{"grade"} ||= "FAIL"
$row->{"grade"}
Truth table0%0/2
A
A= $row->{"grade"}
Aresult
11
00
788 0 my %grades = map {$_ => 1} split(',',$row->{grade});
789  
790 0 $hash{grades} = \%grades;
791 0 $hash{ignored} = $self->_defined_or($row->{ignored}, 0);
792 0 $hash{report} = $self->_defined_or($row->{report}, 1);
793 0 $hash{tuple} = $self->_defined_or($row->{tuple}, 'FIRST');
794 0 $hash{version} = $self->_defined_or($row->{version}, 'LATEST');
795 0 $hash{patches} = $self->_defined_or($row->{patches}, 0);
796 0 $hash{perl} = $self->_defined_or($row->{perl}, 'ALL');
797 0 $hash{platform} = $self->_defined_or($row->{platform}, 'ALL');
798  
799 0 return \%hash;
800 }
801  
802 sub _send_report {
803 0 ▶ my ($self,$author,$row) = @_;
Subroutine _send_report: not called CC=12 SCAR=50.5
804 0 my %tvars;
805  
806 0 my $nntpid = guid_to_nntp($row->{guid});
807  
808 # old NNTP article lookup
809 0 ▶ if($nntpid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nntpid) { } 0 0 0
810 # get article
811 0 my @rows = $self->{CPANPREFS}->get_query('hash',$phrasebook{'GetArticle'}, $nntpid);
812  
813 #$self->_log( "ARTICLE: $nntpid: $rows[0]->{article}\n" );
814  
815 # disassemble article
816 0 ▶ $rows[0]->{article} = decode_qp($rows[0]->{article}) if($rows[0]->{article} =~ /=3D/);
Branch: 1 branch
BranchTrueFalseTotal
if $rows[0]{"article"} =~ /=3D/ 0 0 0
817 0 my $mail = Email::Simple->new($rows[0]->{article});
818 0 ▶ return unless $mail;
Branch: 1 branch
BranchTrueFalseTotal
unless $mail 0 0 0
819  
820 # get from & subject line
821 0 my $from = $mail->header("From");
822 0 my $subject = $mail->header("Subject");
823 0 ▶ return unless $subject;
Branch: 1 branch
BranchTrueFalseTotal
unless $subject 0 0 0
824  
825 0 my ($address) = Email::Address->parse($from);
826 0 my $reply = sprintf "%s\@%s", $address->user, $address->host;
827  
828 # extract the body
829 0 my $encoding = $mail->header('Content-Transfer-Encoding');
830 0 my $body = $mail->body;
831 0 ▶ $body = decode_base64($body) if($encoding && $encoding eq 'base64');
Branch: 1 branch
BranchTrueFalseTotal
if $encoding and $encoding eq "base64" 0 0 0
Condition0%0/3
$encoding and $encoding eq "base64"
!ll&&!rl&&r
000
MC/DC0%0/2
$encoding and $encoding eq "base64"
$encoding $encoding eq "base64"
Truth table0%0/3
A and B
A= $encodingB= $encoding eq "base64"
ABresult
0X0
100
111
832  
833 # set up new mail headers
834 0 my $pause = $self->pause->author($author);
835 0 ▶ %tvars = (
Branch: 1 branch
BranchTrueFalseTotal
$pause ? : 0 0 0
836 author => $author,
837 name => ($pause ? $pause->name : $author),
838 subject => $subject,
839 from => $reply,
840 body => $body,
841 reply => $reply
842 );
843  
844 # new Metabase lookup
845 } else {
846 0 my @rows = $self->{CPANPREFS}->get_query('hash',$phrasebook{'GetMetabaseByGUID'},$row->{guid});
847 0 ▶ return unless(@rows);
Branch: 1 branch
BranchTrueFalseTotal
unless @rows 0 0 0
848  
849 0 my $data = eval { decode_json($rows[0]->{report}) };
850 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
851 0 $self->_log( "WARN: Bad JSON in metabase report $row->{guid}\n" );
852 0 return;
853 }
854
855 0 my $fact = CPAN::Testers::Fact::LegacyReport->from_struct( $data->{'CPAN::Testers::Fact::LegacyReport'} );
856 0 my $body = $fact->{content}{textreport};
857  
858 0 my $report = CPAN::Testers::Fact::TestSummary->from_struct( $data->{'CPAN::Testers::Fact::TestSummary'} );
859 0 my $state = uc $report->{content}{grade};
860 0 my $osname = $report->{content}{osname};
861 0 my $perl = $report->{content}{perl_version};
862  
863 0 my $distro = Metabase::Resource->new( $report->{metadata}{core}{resource} );
864 0 my $dist = $distro->metadata->{dist_name};
865 0 my $version = $distro->metadata->{dist_version};
866 0 my $author2 = $distro->metadata->{author};
867  
868 0 my ($tester_name,$tester_email) = $self->_get_tester( $report->creator );
869  
870 0 my $subject = sprintf "%s %s-%s %s %s", $state, $dist, $version, $perl, $osname;
871  
872 # set up new mail headers
873 0 ▶ my $pause = $author2 ? $self->pause->author($author2) : $self->pause->author($author);
Branch: 1 branch
BranchTrueFalseTotal
$author2 ? : 0 0 0
874 0 ▶ %tvars = (
Branch: 1 branch
BranchTrueFalseTotal
$pause ? : 0 0 0
875 author => $author,
876 name => ($pause ? $pause->name : $author),
877 subject => $subject,
878 from => $tester_email,
879 body => $body,
880 reply => $tester_email
881 );
882 }
883  
884 # send data
885 0 $self->_write_mail('report.eml',\%tvars);
886 }
887  
888 sub _write_mail {
889 0 ▶ my ($self,$template,$parms) = @_;
Subroutine _write_mail: not called CC=10 SCAR=47.0
890  
891 0 ▶ unless($parms->{author}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parms->{"author"}) 0 0 0
892 0 $self->_log( "INFO: BAD: $parms->{author} [$parms->{name}]\n" );
893 0 $self->{counts}{BAD}++;
894 0 return;
895 }
896  
897 0 ▶ my $from = $parms->{from} || $FROM;
Condition0%0/3
$parms->{'from'} || $FROM
l!l&&r!l&&!r
000
MC/DC0%0/2
$parms->{'from'} || $FROM
$parms->{'from'} $FROM
Truth table0%0/3
A || B
A= $parms->{'from'}B= $FROM
ABresult
1X1
011
000
898 0 ▶ my $subject = $parms->{subject} || 'CPAN Testers Daily Reports';
Condition0%0/2
$parms->{'subject'} || 'CPAN Testers Daily Reports'
l!l
00
MC/DC0%0/1
$parms->{'subject'} || 'CPAN Testers Daily Reports'
$parms->{'subject'}
Truth table0%0/2
A
A= $parms->{'subject'}
Aresult
11
00
899 0 my $cmd = qq!| $HOW $parms->{author}\@cpan.org!;
900  
901 0 $self->{counts}{MAILS}++;
902  
903 0 my $DATE = $self->_emaildate();
904 0 $DATE =~ s/\s+$//;
905  
906 0 my $sponsor = $self->_get_sponsor();
907 0 $self->_log( "INFO: Get Sponsor: ".Dumper($sponsor)."\n" );
908 0 $parms->{SPONSOR_CATEGORY} = $sponsor->{category};
909 0 $parms->{SPONSOR_NAME} = $sponsor->{title};
910 0 $parms->{SPONSOR_BODY} = $sponsor->{body};
911 0 $parms->{SPONSOR_HREF} = $sponsor->{href};
912 0 $parms->{SPONSOR_URL} = $sponsor->{url};
913  
914 0 my $text;
915 0 ▶ $self->tt->process( $template, $parms, \$text ) || die $self->tt->error;
Branch: 1 branch
BranchTrueFalseTotal
$self->tt->process($template, $parms, \$text) or die $self->tt->error 0 0 0
916  
917 0 ▶ $parms->{name} ||= $parms->{author};
Condition0%0/3
$parms->{"name"} ||= $parms->{"author"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$parms->{"name"} ||= $parms->{"author"}
$parms->{"name"} $parms->{"author"}
Truth table0%0/3
A ||= B
A= $parms->{"name"}B= $parms->{"author"}
ABresult
1X1
011
000
918  
919 0 my $body;
920 0 ▶ $body = "Reply-To: $parms->{reply}\n" if($parms->{reply});
Branch: 1 branch
BranchTrueFalseTotal
if $parms->{"reply"} 0 0 0
921 0 $body .= $HEAD . $text;
922 0 $body =~ s/FROM/$from/g;
923 0 $body =~ s/NAME/$parms->{name}/g;
924 0 $body =~ s/EMAIL/$parms->{author}\@cpan.org/g;
925 0 $body =~ s/DATE/$DATE/g;
926 0 $body =~ s/SUBJECT/$subject/g;
927  
928 0 ▶ if($self->nomail) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->nomail) { } 0 0 0
elsif (my $fh = 'IO::File'->new($cmd)) { } 0 0 0
929 0 $self->_log( "INFO: TEST: $parms->{author}\n" );
930 0 $self->{counts}{TEST}++;
931 0 ▶ my $fh = IO::File->new('mailer-debug.log','a+') or die "Cannot write to debug file [mailer-debug.log]: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new("mailer-debug.log", "a+") or die "Cannot write to debug file [mailer-debug.log]: $!\n" 0 0 0
932 0 print $fh $body;
933 0 $fh->close;
934
935 } elsif(my $fh = IO::File->new($cmd)) {
936 0 print $fh $body;
937 0 $fh->close;
938 0 $self->_log( "INFO: GOOD: $parms->{author}\n" );
939 0 $self->{counts}{GOOD}++;
940  
941 } else {
942 0 $self->_log( "INFO: BAD: $parms->{author}\n" );
943 0 $self->{counts}{BAD}++;
944 }
945 }
946  
947 sub _emaildate {
948 0 ▶ my $self = shift;
Subroutine _emaildate: not called CC=1 SCAR=6.9
949 0 my $t = localtime;
950 0 return $t->strftime("%a, %d %b %Y %H:%M:%S +0000");
951 }
952  
953 sub _download_mailrc {
954 0 ▶ my $self = shift;
Subroutine _download_mailrc: not called CC=6 SCAR=37.4
955 0 my $file = $self->mailrc;
956 0 my $data;
957  
958 0 ▶ if($file && -f $file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file and -f $file) { } 0 0 0
Condition0%0/3
$file and -f $file
!ll&&!rl&&r
000
MC/DC0%0/2
$file and -f $file
$file -f $file
Truth table0%0/3
A and B
A= $fileB= -f $file
ABresult
0X0
100
111
959 0 $data = read_file($file);
960  
961 } else {
962 0 my $url = 'http://www.cpan.org/authors/01mailrc.txt.gz';
963 0 my $ua = LWP::UserAgent->new;
964 0 $ua->timeout(180);
965 0 my $response = $ua->get($url);
966  
967 0 ▶ if ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 0 0
968 0 my $gzipped = $response->content;
969 0 $data = Compress::Zlib::memGunzip($gzipped);
970 0 ▶ die "Error uncompressing data from $url" unless $data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data 0 0 0
971 } else {
972 0 die "Error fetching $url";
973 }
974 }
975  
976 0 my $p = Parse::CPAN::Authors->new($data);
977 0 ▶ die "Cannot parse data from 01mailrc.txt" unless($p);
Branch: 1 branch
BranchTrueFalseTotal
unless $p 0 0 0
978 0 return $p;
979 }
980  
981 sub _load_testers {
982 0 ▶ my $self = shift;
Subroutine _load_testers: not called CC=4 SCAR=30.0
983 0 my $next = $self->{CPANPREFS}->iterator('hash',$phrasebook{'GetTesters'});
984 0 ▶ while(my $row = $next->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = &$next()) 0 0 0
985 0 ▶ $self->{testers}{$row->{resource}}{name} ||= $row->{fullname};
Condition0%0/3
$self->{"testers"}{$row->{"resource"}}{"name"} ||= $row->{"fullname"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"testers"}{$row->{"resource"}}{"name"} ||= $row->{"fullname"}
$self->{"testers"}{$row->{"resource"}}{"name"} $row->{"fullname"}
Truth table0%0/3
A ||= B
A= $self->{"testers"}{$row->{"resource"}}{"name"}B= $row->{"fullname"}
ABresult
1X1
011
000
986 0 ▶ $self->{testers}{$row->{resource}}{email} ||= $row->{email};
Condition0%0/3
$self->{"testers"}{$row->{"resource"}}{"email"} ||= $row->{"email"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"testers"}{$row->{"resource"}}{"email"} ||= $row->{"email"}
$self->{"testers"}{$row->{"resource"}}{"email"} $row->{"email"}
Truth table0%0/3
A ||= B
A= $self->{"testers"}{$row->{"resource"}}{"email"}B= $row->{"email"}
ABresult
1X1
011
000
987 }
988 }
989  
990 sub _get_tester {
991 0 ▶ my ($self,$creator) = @_;
Subroutine _get_tester: not called CC=3 SCAR=24.8
992  
993 0 ▶ return unless($creator && $self->{testers}{$creator});
Branch: 1 branch
BranchTrueFalseTotal
unless $creator and $self->{"testers"}{$creator} 0 0 0
Condition0%0/3
$creator and $self->{"testers"}{$creator}
!ll&&!rl&&r
000
MC/DC0%0/2
$creator and $self->{"testers"}{$creator}
$creator $self->{"testers"}{$creator}
Truth table0%0/3
A and B
A= $creatorB= $self->{"testers"}{$creator}
ABresult
0X0
100
111
994 0 return $self->{testers}{$creator}{name},$self->{testers}{$creator}{email};
995 }
996  
997 sub _load_authors {
998 0 ▶ my $self = shift;
Subroutine _load_authors: not called CC=2 SCAR=17.9
999 0 my $next = $self->{CPANPREFS}->iterator('hash',$phrasebook{'GetAuthors'});
1000 0 ▶ while(my $row = $next->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = &$next()) 0 0 0
1001 0 $AUTHORS{$row->{dist}}{$row->{version}} = $row->{author};
1002 }
1003 }
1004  
1005 sub _get_author {
1006 0 ▶ my ($self,$dist,$vers) = @_;
Subroutine _get_author: not called CC=3 SCAR=24.8
1007 0 ▶ return unless($dist && $vers);
Branch: 1 branch
BranchTrueFalseTotal
unless $dist and $vers 0 0 0
Condition0%0/3
$dist and $vers
!ll&&!rl&&r
000
MC/DC0%0/2
$dist and $vers
$dist $vers
Truth table0%0/3
A and B
A= $distB= $vers
ABresult
0X0
100
111
1008 0 return $AUTHORS{$dist}{$vers};
1009 }
1010  
1011 sub _get_authorX {
1012 0 ▶ my $self = shift;
Subroutine _get_authorX: not called CC=6 SCAR=37.4
1013 0 my ($dist,$vers) = @_;
1014 0 ▶ return unless($dist && $vers);
Branch: 1 branch
BranchTrueFalseTotal
unless $dist and $vers 0 0 0
Condition0%0/3
$dist and $vers
!ll&&!rl&&r
000
MC/DC0%0/2
$dist and $vers
$dist $vers
Truth table0%0/3
A and B
A= $distB= $vers
ABresult
0X0
100
111
1015  
1016 0 ▶ unless($AUTHORS{$dist} && $AUTHORS{$dist}{$vers}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($AUTHORS{$dist} and $AUTHORS{$dist}{$vers}) 0 0 0
Condition0%0/3
$AUTHORS{$dist} and $AUTHORS{$dist}{$vers}
!ll&&!rl&&r
000
MC/DC0%0/2
$AUTHORS{$dist} and $AUTHORS{$dist}{$vers}
$AUTHORS{$dist} $AUTHORS{$dist}{$vers}
Truth table0%0/3
A and B
A= $AUTHORS{$dist}B= $AUTHORS{$dist}{$vers}
ABresult
0X0
100
111
1017 0 my @author = $self->{CPANPREFS}->get_query('array',$phrasebook{'GetAuthor'}, $dist, $vers);
1018 0 ▶ $AUTHORS{$dist}{$vers} = @author ? $author[0]->[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@author ? : 0 0 0
1019 }
1020 0 return $AUTHORS{$dist}{$vers};
1021 }
1022  
1023 sub _load_sponsors {
1024 0 ▶ my $self = shift;
Subroutine _load_sponsors: not called CC=11 SCAR=48.8
1025 0 my $json;
1026  
1027 0 my $mech = WWW::Mechanize->new();
1028 0 $mech->agent_alias( 'Linux Mozilla' );
1029 0 eval { $mech->get( $IHEART ) };
1030  
1031 # if the network connection failed...
1032 0 ▶ if($@ || !$mech->success() || !$mech->content()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not $mech->success or not $mech->content) { } 0 0 0
Condition0%0/6
$@ or not $mech->success or not $mech->content
l!l&&r!l&&!r
000
$@ or not $mech->success
l!l&&r!l&&!r
000
MC/DC0%0/3
$@ or not $mech->success or not $mech->content
$@ not $mech->success not $mech->content
Truth table0%0/4
A or not(B) or not(C)
A= $@B= not $mech->successC= not $mech->content
ABCresult
1XX1
01X1
0011
0000
1033 0 ▶ if(-f $sponsorfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $sponsorfile) { } 0 0 0
1034 0 $json = read_file($sponsorfile);
1035 } else {
1036 0 return;
1037 }
1038 } else {
1039 0 $json = $mech->content();
1040 }
1041  
1042 0 my $data = decode_json($json);
1043  
1044 0 ▶ return unless($data);
Branch: 1 branch
BranchTrueFalseTotal
unless $data 0 0 0
1045  
1046 0 for my $item (@$data) {
1047 0 for my $link (@{$item->{links}}) {
1048 push @SPONSORS, {
1049 category => $item->{category},
1050 title => $link->{title},
1051 body => $link->{body},
1052 href => $link->{href},
1053 url => $link->{href}
1054 0 };
1055  
1056 0 ▶ $SPONSORS[-1]{url} =~ s!^https?://(?:www\.)?([^/]+).*!$1! if($SPONSORS[-1]{url});
Branch: 1 branch
BranchTrueFalseTotal
if $SPONSORS[-1]{"url"} 0 0 0
1057 0 ▶ $SPONSORS[-1]{body} =~ s!</p>\s*<p[^>]*>!!g if($SPONSORS[-1]{body});
Branch: 1 branch
BranchTrueFalseTotal
if $SPONSORS[-1]{"body"} 0 0 0
1058 0 ▶ $SPONSORS[-1]{body} =~ s!<[^>]+>!!g if($SPONSORS[-1]{body});
Branch: 1 branch
BranchTrueFalseTotal
if $SPONSORS[-1]{"body"} 0 0 0
1059 }
1060 }
1061  
1062 # save file in case the network connection fails
1063 0 overwrite_file($sponsorfile, $json);
1064  
1065 #$self->_log( "INFO: " . scalar(@SPONSORS) . " Sponsors loaded\n" );
1066 #$self->_log( "INFO: Sponsors: " . Dumper(\@SPONSORS) );
1067  
1068 0 $MT = Math::Random::MT->new(time);
1069 }
1070  
1071 sub _get_sponsor {
1072 0 ▶ my $self = shift;
Subroutine _get_sponsor: not called CC=1 SCAR=6.9
1073 0 my $rand = $MT->rand(scalar(@SPONSORS));
1074 0 $self->_log( "INFO: Sponsors: rand=$rand: " . Dumper($SPONSORS[$rand]) );
1075 0 return $SPONSORS[$rand];
1076 }
1077  
1078 sub _log {
1079 0 ▶ my $self = shift;
Subroutine _log: not called CC=5 SCAR=34.0
1080 0 ▶ my $log = $self->logfile or return;
Branch: 1 branch
BranchTrueFalseTotal
my $log = $self->logfile or return 0 0 0
1081 0 ▶ mkpath(dirname($log)) unless(-f $log);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $log 0 0 0
1082  
1083 0 my $t = localtime;
1084 0 my $s = $t->strftime("%Y/%m/%d %H:%M:%S");
1085  
1086 0 ▶ my $mode = $self->logclean ? 'w+' : 'a+';
Branch: 1 branch
BranchTrueFalseTotal
$self->logclean ? : 0 0 0
1087 0 $self->logclean(0);
1088  
1089 0 ▶ my $fh = IO::File->new($log,$mode) or die "Cannot write to log file [$log]: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new($log, $mode) or die "Cannot write to log file [$log]: $!\n" 0 0 0
1090 0 print $fh "$s: " . join(' ', @_);
1091 0 $fh->close;
1092 }
1093  
1094 sub _defined_or {
1095 0 ▶ my $self = shift;
Subroutine _defined_or: not called CC=3 SCAR=24.8
1096 0 ▶ while(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1097 0 my $value = shift;
1098 0 ▶ return $value if(defined $value);
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 0 0 0
1099 }
1100  
1101 0 return;
1102 }
1103  
1104 22 1;
1105  
1106 __END__
↑ Summary