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

filter: Statementstmt 87.4% 396 / 453 Branchbran 74.5% 170 / 228 Conditioncond 60.0% 69 / 115 MC/DCmcdc 20.9% 13 / 62 Subroutinesub 100% 33 / 33 Podpod 100% 13 / 13 totaltotal 76.7% 694 / 904 SCAR 62.1
CC
192
Cov
80%
print_addresses
130.2
backup
62.3
load_addresses
47.4
CRAP 497.0
↑ Summary
1 package CPAN::Testers::Data::Addresses;
2  
3 14 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 14 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 $VERSION = '0.16';
9 14 $|++;
10  
11 #----------------------------------------------------------------------------
12 # Library Modules
13  
14 14 ▶use base qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 14 ▶use CPAN::Testers::Common::DBUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 14 ▶use Config::IniFiles;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 14 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 14 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 14 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 14 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 14 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 14 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 #----------------------------------------------------------------------------
26 # Variables
27  
28 14 my (%backups);
29  
30 14 my %phrasebook = (
31 'AllAddresses' => q{SELECT * FROM tester_address},
32 'AllAddressesFull' => q{SELECT a.*,p.name,p.pause FROM tester_address AS a INNER JOIN tester_profile AS p ON p.testerid=a.testerid},
33 'UpdateAddressIndex' => q{REPLACE INTO ixaddress (id,guid,addressid,fulldate) VALUES (?,?,?,?)},
34  
35 'InsertAddress' => q{INSERT INTO tester_address (testerid,address,email) VALUES (?,?,?)},
36 'GetAddressByText' => q{SELECT * FROM tester_address WHERE address = ?},
37 'LinkAddress' => q{UPDATE tester_address SET testerid=? WHERE addressid=?},
38  
39 'GetTesterByPause' => q{SELECT testerid FROM tester_profile WHERE pause = ?},
40 'GetTesterByName' => q{SELECT testerid FROM tester_profile WHERE name = ?},
41 'InsertTester' => q{INSERT INTO tester_profile (name,pause) VALUES (?,?)},
42  
43 'AllReports' => q{SELECT id,guid,tester,fulldate FROM cpanstats WHERE type=2 AND id > ? ORDER BY id LIMIT 1000000},
44 'GetTestersByMonth' => q{SELECT DISTINCT c.id,c.guid,c.tester,c.fulldate FROM cpanstats c LEFT JOIN ixaddress x ON x.id=c.id LEFT JOIN tester_address a ON a.addressid=x.addressid WHERE a.address IS NULL AND c.postdate >= '%s' AND c.state IN ('pass','fail','na','unknown')},
45 'GetTesters' => q{SELECT DISTINCT c.id,c.guid,c.tester,c.fulldate FROM cpanstats c LEFT JOIN ixaddress x ON x.id=c.id LEFT JOIN tester_address a ON a.addressid=x.addressid WHERE a.address IS NULL AND c.state IN ('pass','fail','na','unknown')},
46  
47 # Database backup requests
48 'DeleteBackup' => 'DELETE FROM addresses',
49 'CreateBackup' => 'CREATE TABLE addresses (testerid int, name text, pause text, PRIMARY KEY (testerid))',
50 'SelectBackup' => 'SELECT * FROM tester_profile',
51 'InsertBackup' => 'INSERT INTO addresses (testerid,name,pause) VALUES (?,?,?)',
52  
53 # Consolidations
54 'DuplicateAddresses' => q{SELECT address,count(*) AS count FROM tester_address GROUP BY address ORDER BY count DESC},
55 'UpdateAddress' => q{UPDATE ixaddress SET addressid=? WHERE addressid=?},
56 'DeleteAddress' => q{DELETE FROM tester_address WHERE addressid=?},
57 );
58  
59 14 my %defaults = (
60 'address' => 'data/addresses.txt',
61 'mailrc' => 'data/01mailrc.txt',
62 'lastfile' => 'data/_lastid',
63 'month' => 199000,
64 'match' => 0,
65 'logclean' => 0
66 );
67  
68 #----------------------------------------------------------------------------
69 # The Application Programming Interface
70  
71 sub new {
72 18 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
73  
74 18 my $self = {};
75 18 bless $self, $class;
76  
77 18 $self->_init_options(@_);
78 13 return $self;
79 }
80  
81 sub DESTROY {
82 18 ▶ my $self = shift;
Subroutine DESTROY: called CC=2 SCAR=6.9
83 18 ▶ $self->{fh}->close if($self->{fh});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"fh"} 6 12 18
84 }
85  
86 14 __PACKAGE__->mk_accessors(qw( lastfile logfile logclean dbh ));
87  
88 sub process {
89 4 ▶ my $self = shift;
Subroutine process: called CC=5 SCAR=17.0
Pod documented
90  
91 4 ▶ if($self->{options}{update}) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->{'options'}{'update'}) { } 2 2 4
elsif ($self->{'options'}{'reindex'}) { } 1 1 2
elsif ($self->{'options'}{'backup'}) { } 0 1 1
elsif ($self->{'options'}{'clean'}) { } 0 1 1
92 2 $self->update();
93  
94 } elsif($self->{options}{reindex}) {
95 1 $self->reindex();
96  
97 } elsif($self->{options}{backup}) {
98 0 $self->backup();
99  
100 } elsif($self->{options}{clean}) {
101 0 $self->clean();
102  
103 } else {
104 1 $self->search();
105 }
106 }
107  
108 sub search {
109 1 ▶ my $self = shift;
Subroutine search: called CC=1 SCAR=0.0
Pod documented
110 1 $self->_log("starting search");
111  
112 1 $self->load_addresses();
113 1 $self->match_addresses();
114 1 $self->print_addresses();
115  
116 1 $self->_log("stopping search");
117 }
118  
119 sub update {
120 2 ▶ my $self = shift;
Subroutine update: called CC=20 SCAR=30.1
Pod documented
121 2 my ($new,$all,$add,$err) = (0,0,0,0);
122 2 $self->_log("starting update");
123  
124 2 ▶ my $fh = IO::File->new($self->{options}{update}) or die "Cannot open mailrc file [$self->{options}{update}]: $!";
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new($self->{"options"}{"update"}) or die qq[Cannot open mailrc file [$self->{"options"}{"update"}]: $!] 0 2 2
125 2 ▶ while(<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 10 2 12
126 10 s/\s+$//;
127 10 ▶ next unless($_);
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 10 10
128  
129 10 my ($reportid,$guid,$fulldate,$addressid,$testerid,$address,$name,$pause,$display,$match) = split(',');
130 10 ▶ unless($address && ($name || $display)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($address and $name || $display) 3 7 10
Condition66%4/6
$address and $name || $display
!ll&&!rl&&r
280
$name or $display
l!l&&r!l&&!r
701
MC/DC0%0/3
$address and $name || $display
$address $name $display
Truth table50%2/4
A and B or C
A= $addressB= $nameC= $display
ABCresult
0XX0
1000
11X1
1011
131 3 $self->_log("... bogus line: $_");
132 3 $err++;
133 3 next;
134 }
135  
136 7 ▶ $addressid ||= 0;
Condition100%2/2
$addressid ||= 0
l!l
43
MC/DC100%1/1
$addressid ||= 0
$addressid
Truth table100%2/2
A
A= $addressid
Aresult
11
00
137 7 ▶ $testerid ||= 0;
Condition100%2/2
$testerid ||= 0
l!l
43
MC/DC100%1/1
$testerid ||= 0
$testerid
Truth table100%2/2
A
A= $testerid
Aresult
11
00
138 7 ▶ $name ||= $display;
Condition33%1/3
$name ||= $display
l!l&&r!l&&!r
700
MC/DC0%0/2
$name ||= $display
$name $display
Truth table33%1/3
A ||= B
A= $nameB= $display
ABresult
1X1
011
000
139 7 ▶ $pause ||= '';
Condition50%1/2
$pause ||= ""
l!l
70
MC/DC0%0/1
$pause ||= ""
$pause
Truth table50%1/2
A
A= $pause
Aresult
11
00
140  
141 7 $all++;
142 7 ▶ if($testerid == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($testerid == 0) 3 4 7
143 3 my @rows;
144 3 ▶ @rows = $self->dbh->get_query('hash',$phrasebook{'GetTesterByPause'},$pause) if($pause);
Branch: 1 branch
BranchTrueFalseTotal
if $pause 3 0 3
145 3 ▶ @rows = $self->dbh->get_query('hash',$phrasebook{'GetTesterByName'},$name) unless(@rows);
Branch: 1 branch
BranchTrueFalseTotal
unless @rows 2 1 3
146  
147 3 ▶ if(@rows) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rows) { } 1 2 3
148 1 $testerid = $rows[0]->{testerid};
149 } else {
150 2 $testerid = $self->dbh->id_query($phrasebook{'InsertTester'},$name,$pause);
151 2 $new++;
152 }
153 }
154  
155 7 ▶ if($addressid == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($addressid == 0) 3 4 7
156 3 my @rows = $self->dbh->get_query('hash',$phrasebook{'GetAddressByText'},$address);
157 3 ▶ if(@rows) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rows) { } 1 2 3
158 1 $addressid = $rows[0]->{addressid};
159 } else {
160 2 $addressid = $self->dbh->id_query($phrasebook{'InsertAddress'},$testerid,$address,_extract_email($address));
161 2 $add++;
162 }
163 }
164  
165 7 $self->dbh->do_query($phrasebook{'LinkAddress'},$testerid,$addressid);
166 7 $self->_log("... profile => address: ($testerid,$name,$pause) => ($addressid,$address)");
167  
168 7 ▶ next unless($reportid && $guid && $fulldate);
Branch: 1 branch
BranchTrueFalseTotal
unless $reportid and $guid and $fulldate 2 4 6
Condition100%6/6
$reportid and $guid and $fulldate
!ll&&!rl&&r
214
$reportid and $guid
!ll&&!rl&&r
115
MC/DC100%3/3
$reportid and $guid and $fulldate
$reportid $guid $fulldate
Truth table100%4/4
A and B and C
A= $reportidB= $guidC= $fulldate
ABCresult
0XX0
10X0
1100
1111
169 4 $self->dbh->do_query($phrasebook{'UpdateAddressIndex'},$reportid,$guid,$addressid,$fulldate);
170 }
171  
172 2 $self->_printout("$all addresses mapped");
173 2 $self->_printout("$new new testers");
174 2 $self->_printout("$add addresses added");
175 2 $self->_printout("$err bogus lines");
176  
177 2 $self->_log("$all addresses mapped, $new new addresses");
178 2 $self->_log("stopping update");
179 }
180  
181 sub reindex {
182 1 ▶ my $self = shift;
Subroutine reindex: called CC=6 SCAR=17.9
Pod documented
183  
184 1 $self->_log("starting reindex");
185  
186 # load known addresses
187 1 my %address;
188 1 my $next = $self->dbh->iterator('hash',$phrasebook{'AllAddresses'});
189 1 ▶ while( my $row = $next->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = &$next()) 5 1 6
190 5 $address{$row->{address}} = $row->{addressid};
191 }
192  
193 # search through reports updating the index
194 1 ▶ my $lastid = defined $self->{options}{lastid} ? $self->{options}{lastid} : $self->_lastid();
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'options'}{'lastid'} ? : 0 1 1
195 1 ▶ $next = $self->dbh->iterator('hash',$phrasebook{'AllReports'},($lastid || 0));
Condition50%1/2
$lastid || 0
l!l
01
MC/DC0%0/1
$lastid || 0
$lastid
Truth table50%1/2
A
A= $lastid
Aresult
11
00
196 1 ▶ while( my $row = $next->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = &$next()) 33 1 34
197 #print STDERR "row: $row->{id} $row->{tester}\n";
198 33 ▶ if($address{$row->{tester}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($address{$row->{'tester'}}) { } 24 9 33
199 24 $self->_log("FOUND - row: $row->{id} $row->{tester}");
200 24 $self->dbh->do_query($phrasebook{'UpdateAddressIndex'},$row->{id},$row->{guid},$address{$row->{tester}},$row->{fulldate});
201 } else {
202 9 $self->_log("NEW - row: $row->{id} $row->{tester}");
203 9 $address{$row->{tester}} = $self->dbh->id_query($phrasebook{'InsertAddress'},0,$row->{tester},_extract_email($row->{tester}));
204 9 $self->dbh->do_query($phrasebook{'UpdateAddressIndex'},$row->{id},$row->{guid},$address{$row->{tester}},$row->{fulldate});
205 }
206  
207 33 $lastid = $row->{id};
208 }
209 1 $self->_lastid($lastid);
210 1 $self->_log("stopping reindex");
211 }
212  
213 sub clean {
214 1 ▶ my $self = shift;
Subroutine clean: called CC=5 SCAR=16.1
Pod documented
215 1 $self->_log("starting clean");
216  
217 1 my $next = $self->dbh->iterator('hash',$phrasebook{'DuplicateAddresses'});
218 1 ▶ while( my $row = $next->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = &$next()) 2 0 2
219 2 $self->_log("count=$row->{count}, address=$row->{address}");
220  
221 2 ▶ last if($row->{count} <= 1);
Branch: 1 branch
BranchTrueFalseTotal
if $row->{"count"} <= 1 1 1 2
222  
223 1 my %addr;
224 1 my @rows = $self->dbh->get_query('hash',$phrasebook{'GetAddressByText'},$row->{address});
225 1 $self->_log("- count=".scalar(@rows).", address=$row->{address}");
226 1 for my $addr (@rows) {
227 5 $self->_log("id=$addr->{addressid}, address=$addr->{address}");
228 5 ▶ if($addr{$addr->{address}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($addr{$addr->{'address'}}) { } 4 1 5
229 4 $self->_log("replace $addr->{addressid},'$addr->{address}' => $addr{$addr->{address}}->{addressid},'$addr{$addr->{address}}->{address}'");
230 4 $self->dbh->do_query($phrasebook{'UpdateAddress'},$addr{$addr->{address}}->{addressid},$addr->{addressid});
231 4 $self->dbh->do_query($phrasebook{'DeleteAddress'},$addr->{addressid});
232  
233 } else {
234 1 $addr{$addr->{address}} = $addr;
235 }
236 }
237 }
238  
239 1 $self->_log("stopping clean");
240 }
241  
242 sub backup {
243 1 ▶ my $self = shift;
Subroutine backup: called CC=10 SCAR=41.3
Pod documented
244  
245 1 for my $driver (keys %{$self->{backups}}) {
246 2 ▶ if($self->{backups}{$driver}{'exists'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'backups'}{$driver}{'exists'}) { } 0 2 2
elsif ($driver =~ /(CSV|SQLite)/i) { } 2 0 2
247 0 $self->{backups}{$driver}{db}->do_query($phrasebook{'DeleteBackup'});
248 } elsif($driver =~ /(CSV|SQLite)/i) {
249 2 $self->{backups}{$driver}{db}->do_query($phrasebook{'CreateBackup'});
250 }
251 }
252  
253 0 $self->_log("Backup via DBD drivers");
254  
255 0 my $rows = $self->dbh->iterator('array',$phrasebook{'SelectBackup'});
256 0 ▶ while(my $row = $rows->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = &$rows()) 0 0 0
257 0 for my $driver (keys %{$self->{backups}}) {
258 0 $self->{backups}{$driver}{db}->do_query($phrasebook{'InsertBackup'},@$row);
259 }
260 }
261  
262 # handle the CSV exception
263 0 ▶ if($self->{backups}{CSV}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"backups"}{"CSV"}) 0 0 0
264 0 $self->_log("Backup to CSV file");
265 0 $self->{backups}{CSV}{db} = undef; # close db handle
266 0 ▶ my $fh1 = IO::File->new('addresses','r') or die "Cannot read temporary database file 'addresses'\n";
Branch: 1 branch
BranchTrueFalseTotal
my $fh1 = "IO::File"->new("addresses", "r") or die "Cannot read temporary database file 'addresses'\n" 0 0 0
267 0 ▶ my $fh2 = IO::File->new($self->{backups}{CSV}{dbfile},'w+') or die "Cannot write to CSV database file $self->{backups}{CSV}{dbfile}\n";
Branch: 1 branch
BranchTrueFalseTotal
my $fh2 = "IO::File"->new($self->{"backups"}{"CSV"}{"dbfile"}, "w+") or die qq[Cannot write to CSV database file $self->{"backups"}{"CSV"}{"dbfile"}\n] 0 0 0
268 0 ▶ while(<$fh1>) { print $fh2 $_ }
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh1)) 0 0 0
269 0 $fh1->close;
270 0 $fh2->close;
271 0 unlink('addresses');
272 }
273 }
274  
275 sub load_addresses {
276 3 ▶ my $self = shift;
Subroutine load_addresses: called CC=30 SCAR=38.6
Pod documented
277
278 3 my $next = $self->dbh->iterator('hash',$phrasebook{'AllAddressesFull'});
279 3 ▶ while( my $row = $next->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = &$next()) 16 3 19
280 16 ▶ $self->{named_map}{$row->{name}} = { name => $row->{name}, pause => $row->{pause}, addressid => $row->{addressid}, testerid => $row->{testerid}, match => '# MAPPED NAME' } if($row->{name});
Branch: 1 branch
BranchTrueFalseTotal
if $row->{"name"} 16 0 16
281 16 ▶ $self->{paused_map}{$row->{pause}} = { name => $row->{name}, pause => $row->{pause}, addressid => $row->{addressid}, testerid => $row->{testerid}, match => '# MAPPED PAUSE' } if($row->{pause});
Branch: 1 branch
BranchTrueFalseTotal
if $row->{"pause"} 16 0 16
282 16 $self->{parsed_map}{$row->{address}} = { name => $row->{name}, pause => $row->{pause}, addressid => $row->{addressid}, testerid => $row->{testerid}, match => '# MAPPED ADDRESS' };
283 16 ▶ next unless($row->{email});
Branch: 1 branch
BranchTrueFalseTotal
unless $row->{"email"} 0 16 16
284 16 $self->{address_map}{$row->{email}} = { name => $row->{name}, pause => $row->{pause}, addressid => $row->{addressid}, testerid => $row->{testerid}, match => '# MAPPED EMAIL' };
285  
286 16 my ($local,$domain) = split(/\@/,$row->{email});
287 16 ▶ next unless($domain);
Branch: 1 branch
BranchTrueFalseTotal
unless $domain 0 16 16
288 16 $self->{domain_map}{$domain} = { name => $row->{name}, pause => $row->{pause}, addressid => $row->{addressid}, testerid => $row->{testerid}, match => '# MAPPED DOMAIN' };
289 }
290  
291 3 ▶ if($self->{options}{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"options"}{"verbose"}) 0 3 3
292 0 $self->_log( "named entries = " . scalar(keys %{ $self->{named_map} }) . "\n" );
293 0 $self->_log( "paused entries = " . scalar(keys %{ $self->{paused_map} }) . "\n" );
294 0 $self->_log( "parsed entries = " . scalar(keys %{ $self->{parsed_map} }) . "\n" );
295 0 $self->_log( "address entries = " . scalar(keys %{ $self->{address_map} }) . "\n" );
296 0 $self->_log( "domain entries = " . scalar(keys %{ $self->{domain_map} }) . "\n" );
297 }
298  
299 3 $next = $self->dbh->iterator('hash',$phrasebook{'AllAddresses'});
300 3 ▶ while( my $row = $next->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = &$next()) 26 3 29
301 26 ▶ next if($self->{parsed_map}{$row->{address}});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"parsed_map"}{$row->{"address"}} 16 10 26
302 10 $self->{stored_map}{$row->{address}} = { name => '', pause => '', addressid => $row->{addressid}, testerid => 0, match => '# STORED ADDRESS' };
303 }
304  
305 3 ▶ my $fh = IO::File->new($self->{options}{mailrc}) or die "Cannot open mailrc file [$self->{options}{mailrc}]: $!";
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new($self->{"options"}{"mailrc"}) or die qq[Cannot open mailrc file [$self->{"options"}{"mailrc"}]: $!] 0 3 3
306 3 ▶ while(<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 15 3 18
307 15 s/\s+$//;
308 15 ▶ next if(/^$/);
Branch: 1 branch
BranchTrueFalseTotal
if /^$/ 0 15 15
309  
310 15 my ($alias,$name,$email) = (/alias\s+([A-Z]+)\s+"([^<]+) <([^>]+)>"/);
311 15 ▶ next unless($alias);
Branch: 1 branch
BranchTrueFalseTotal
unless $alias 0 15 15
312  
313 15 ▶ my $testerid = $self->{address_map}{$email} ? $self->{address_map}{$email}->{testerid} : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'address_map'}{$email} ? : 5 10 15
314 15 ▶ my $addressid = $self->{address_map}{$email} ? $self->{address_map}{$email}->{addressid} : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'address_map'}{$email} ? : 5 10 15
315  
316 15 $self->{pause_map}{lc($alias)} = { name => $name, pause => $alias, testerid => $testerid, addressid => $addressid, match => '# PAUSE ID' };
317 15 $self->{cpan_map}{lc($email)} = { name => $name, pause => $alias, testerid => $testerid, addressid => $addressid, match => '# CPAN EMAIL' };
318 }
319 3 $fh->close;
320  
321 3 ▶ if($self->{options}{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"options"}{"verbose"}) 0 3 3
322 0 $self->_log( "pause entries = " . scalar(keys %{ $self->{pause_map} }) . "\n" );
323 0 $self->_log( "cpan entries = " . scalar(keys %{ $self->{cpan_map} }) . "\n" );
324 }
325  
326 # grab all records for the month
327 my $sql = $self->{options}{month}
328 ? sprintf $phrasebook{'GetTestersByMonth'}, $self->{options}{month}
329 3 ▶ : $phrasebook{'GetTesters'};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'options'}{'month'} ? : 3 0 3
330 3 ▶ if($self->{options}{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"options"}{"verbose"}) 0 3 3
331 0 $self->_log( "sql = $sql\n" );
332 }
333 3 $next = $self->dbh->iterator('array',$sql);
334 3 $self->{parsed} = 0;
335 3 ▶ while(my $row = $next->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = &$next()) 70 3 73
336 70 $self->{parsed}++;
337 70 my $email = _extract_email($row->[2]);
338  
339 70 ▶ my $testerid = $self->{parsed_map}{$row->[2]} ? $self->{parsed_map}{$row->[2]}->{testerid} : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'parsed_map'}{$row->[2]} ? : 12 58 70
340 70 ▶ my $addressid = $self->{parsed_map}{$row->[2]} ? $self->{parsed_map}{$row->[2]}->{addressid} : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'parsed_map'}{$row->[2]} ? : 12 58 70
341 70 ▶ $addressid ||= $self->{stored_map}{$row->[2]} ? $self->{stored_map}{$row->[2]}->{addressid} : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'stored_map'}{$row->[2]} ? : 0 58 58
Condition66%2/3
$addressid ||= $self->{"stored_map"}{$row->[2]} ? $self->{"stored_map"}{$row->[2]}{"addressid"} : 0
l!l&&r!l&&!r
12058
MC/DC50%1/2
$addressid ||= $self->{"stored_map"}{$row->[2]} ? $self->{"stored_map"}{$row->[2]}{"addressid"} : 0
$addressid $self->{"stored_map"}{$row->[2]} ? $self->{"stored_map"}{$row->[2]}{"addressid"} : 0
Truth table66%2/3
A ||= B
A= $addressidB= $self->{"stored_map"}{$row->[2]} ? $self->{"stored_map"}{$row->[2]}{"addressid"} : 0
ABresult
1X1
011
000
342 70 ▶ $testerid ||= $self->{address_map}{$email} ? $self->{address_map}{$email}->{testerid} : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'address_map'}{$email} ? : 6 52 58
Condition100%3/3
$testerid ||= $self->{"address_map"}{$email} ? $self->{"address_map"}{$email}{"testerid"} : 0
l!l&&r!l&&!r
12652
MC/DC100%2/2
$testerid ||= $self->{"address_map"}{$email} ? $self->{"address_map"}{$email}{"testerid"} : 0
$testerid $self->{"address_map"}{$email} ? $self->{"address_map"}{$email}{"testerid"} : 0
Truth table100%3/3
A ||= B
A= $testeridB= $self->{"address_map"}{$email} ? $self->{"address_map"}{$email}{"testerid"} : 0
ABresult
1X1
011
000
343 70 ▶ $addressid ||= $self->{address_map}{$email} ? $self->{address_map}{$email}->{addressid} : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'address_map'}{$email} ? : 6 52 58
Condition100%3/3
$addressid ||= $self->{"address_map"}{$email} ? $self->{"address_map"}{$email}{"addressid"} : 0
l!l&&r!l&&!r
12652
MC/DC100%2/2
$addressid ||= $self->{"address_map"}{$email} ? $self->{"address_map"}{$email}{"addressid"} : 0
$addressid $self->{"address_map"}{$email} ? $self->{"address_map"}{$email}{"addressid"} : 0
Truth table100%3/3
A ||= B
A= $addressidB= $self->{"address_map"}{$email} ? $self->{"address_map"}{$email}{"addressid"} : 0
ABresult
1X1
011
000
344  
345 70 ▶ next if($testerid && $addressid);
Branch: 1 branch
BranchTrueFalseTotal
if $testerid and $addressid 18 52 70
Condition66%2/3
$testerid and $addressid
!ll&&!rl&&r
52018
MC/DC50%1/2
$testerid and $addressid
$testerid $addressid
Truth table66%2/3
A and B
A= $testeridB= $addressid
ABresult
0X0
100
111
346
347 52 $self->{unparsed_map}{$row->[2]} = {
348 reportid => $row->[0],
349 guid => $row->[1],
350 fulldate => $row->[3],
351 testerid => $testerid,
352 addressid => $addressid,
353 'sort' => '',
354 email => $email
355 };
356 }
357  
358 3 ▶ if($self->{options}{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"options"}{"verbose"}) 0 3 3
359 0 $self->_log( "rows = $self->{parsed}\n" );
360 0 $self->_log( "unparsed entries = " . scalar(keys %{ $self->{unparsed_map} }) . "\n" );
361 }
362 }
363  
364 sub match_addresses {
365 3 ▶ my $self = shift;
Subroutine match_addresses: called CC=8 SCAR=21.1
Pod documented
366  
367 # if($self->{options}{verbose}) {
368 # use Data::Dumper;
369 # $self->_log( "named_map=". Dumper($self->{named_map}) );
370 # $self->_log( "unparsed_map=". Dumper($self->{unparsed_map}) );
371 # $self->_log( "parsed_map=" . Dumper($self->{parsed_map}) );
372 # $self->_log( "paused_map=" . Dumper($self->{paused_map}) );
373 # $self->_log( "pause_map=" . Dumper($self->{pause_map}) );
374 # $self->_log( "cpan_map=" . Dumper($self->{cpan_map}) );
375 # $self->_log( "domain_map=" . Dumper($self->{domain_map}) );
376 # $self->_log( "address_map=" . Dumper($self->{address_map}) );
377 # $self->_log( "stored_map=" . Dumper($self->{stored_map}) );
378 # }
379  
380 3 for my $key (keys %{ $self->{unparsed_map} }) {
381 18 my $email = _extract_email($key);
382 18 ▶ unless($email) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($email) 0 18 18
383 0 push @{$self->{result}{NOEMAIL}}, $key;
384 0 next;
385 }
386 18 $email = lc($email);
387 18 my ($local,$domain) = split(/\@/,$email);
388 #print STDERR "email=[$email], local=[$local], domain=[$domain]\n" if($email =~ /indiana/);
389 18 ▶ next if($self->map_address($key,$local,$domain,$email));
Branch: 1 branch
BranchTrueFalseTotal
if $self->map_address($key, $local, $domain, $email) 2 16 18
390  
391 16 my $last = 0;
392 16 my @parts = split(/\./,$domain);
393 16 ▶ while(@parts > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parts > 1) 24 11 35
394 24 my $domain2 = join(".",@parts);
395 #print STDERR "domain2=[$domain2]\n" if($email =~ /indiana/);
396 24 ▶ if($self->map_domain($key,$local,$domain2,$email)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->map_domain($key, $local, $domain2, $email)) 5 19 24
397 5 $last = 1;
398 5 last;
399 }
400 19 shift @parts;
401 }
402  
403 16 ▶ next if($last);
Branch: 1 branch
BranchTrueFalseTotal
if $last 5 11 16
404 11 ▶ next if($self->map_name($key));
Branch: 1 branch
BranchTrueFalseTotal
if $self->map_name($key) 0 11 11
405 }
406 }
407  
408 sub print_addresses {
409 3 ▶ my $self = shift;
Subroutine print_addresses: called CC=42 SCAR=48.7
Pod documented
410 3 my $text = '';
411  
412 3 ▶ if($self->{result}{NOMAIL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"result"}{"NOMAIL"}) 0 3 3
413 0 $self->_printout( "ERRORS:" );
414 0 for my $email (sort @{$self->{result}{NOMAIL}}) {
415 0 $self->_printout( "NOMAIL: $email" );
416 }
417 }
418  
419 3 $self->_printout( "\nMATCH:" );
420 3 for my $key (sort {$self->{unparsed_map}{$a}->{match} cmp $self->{unparsed_map}{$b}->{match}}
421 18 grep {$self->{unparsed_map}{$_}->{match}}
422 3 keys %{ $self->{unparsed_map} }) {
423 9 ▶ if($self->{unparsed_map}{$key}->{match} && $self->{unparsed_map}{$key}->{match} !~ /SUGGESTION/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'unparsed_map'}{$key}{'match'} and not $self->{'unparsed_map'}{$key}{'match'} =~ /SUGGESTION/) { } 7 2 9
Condition66%2/3
$self->{"unparsed_map"}{$key}{"match"} and not $self->{"unparsed_map"}{$key}{"match"} =~ /SUGGESTION/
!ll&&!rl&&r
027
MC/DC50%1/2
$self->{"unparsed_map"}{$key}{"match"} and not $self->{"unparsed_map"}{$key}{"match"} =~ /SUGGESTION/
$self->{"unparsed_map"}{$key}{"match"} not $self->{"unparsed_map"}{$key}{"match"} =~ /SUGGESTION/
Truth table66%2/3
A and not(B)
A= $self->{"unparsed_map"}{$key}{"match"}B= not $self->{"unparsed_map"}{$key}{"match"} =~ /SUGGESTION/
ABresult
0X0
100
111
424 $self->_printout(
425 sprintf "%d,%s,%s,%d,%d,%s,%s,%s,%s,%s",
426 ($self->{unparsed_map}{$key}->{reportid} || 0),
427 ($self->{unparsed_map}{$key}->{guid} || ''),
428 ($self->{unparsed_map}{$key}->{fulldate} || ''),
429  
430 ($self->{unparsed_map}{$key}->{addressid} || 0),
431 ($self->{unparsed_map}{$key}->{testerid} || 0),
432 $key,
433 ($self->{unparsed_map}{$key}->{name} || ''),
434 ($self->{unparsed_map}{$key}->{pause} || ''),
435 ($self->{unparsed_map}{$key}->{display} || ''),
436 7 ▶ ($self->{unparsed_map}{$key}->{match} || '')
Condition55%10/18
$self->{'unparsed_map'}{$key}{'reportid'} || 0
l!l
70
$self->{'unparsed_map'}{$key}{'guid'} || ''
l!l
70
$self->{'unparsed_map'}{$key}{'fulldate'} || ''
l!l
70
$self->{'unparsed_map'}{$key}{'addressid'} || 0
l!l
07
$self->{'unparsed_map'}{$key}{'testerid'} || 0
l!l
52
$self->{'unparsed_map'}{$key}{'name'} || ''
l!l
70
$self->{'unparsed_map'}{$key}{'pause'} || ''
l!l
70
$self->{'unparsed_map'}{$key}{'display'} || ''
l!l
07
$self->{'unparsed_map'}{$key}{'match'} || ''
l!l
70
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'reportid'} || 0
$self->{'unparsed_map'}{$key}{'reportid'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'guid'} || ''
$self->{'unparsed_map'}{$key}{'guid'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'fulldate'} || ''
$self->{'unparsed_map'}{$key}{'fulldate'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'addressid'} || 0
$self->{'unparsed_map'}{$key}{'addressid'}
MC/DC100%1/1
$self->{'unparsed_map'}{$key}{'testerid'} || 0
$self->{'unparsed_map'}{$key}{'testerid'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'name'} || ''
$self->{'unparsed_map'}{$key}{'name'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'pause'} || ''
$self->{'unparsed_map'}{$key}{'pause'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'display'} || ''
$self->{'unparsed_map'}{$key}{'display'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'match'} || ''
$self->{'unparsed_map'}{$key}{'match'}
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'reportid'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'guid'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'fulldate'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'addressid'}
Aresult
11
00
Truth table100%2/2
A
A= $self->{'unparsed_map'}{$key}{'testerid'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'name'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'pause'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'display'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'match'}
Aresult
11
00
437 );
438 7 delete $self->{unparsed_map}{$key};
439 } else {
440 2 my ($local,$domain) = $self->{unparsed_map}{$key}->{email} =~ /([-+=\w.]+)\@([^\s]+)/;
441 2 ▶ ($local,$domain) = $key =~ /([-+=\w.]+)\@([^\s]+)/ unless($local && $domain);
Branch: 1 branch
BranchTrueFalseTotal
unless $local and $domain 0 2 2
Condition33%1/3
$local and $domain
!ll&&!rl&&r
002
MC/DC0%0/2
$local and $domain
$local $domain
Truth table33%1/3
A and B
A= $localB= $domain
ABresult
0X0
100
111
442 2 ▶ if($domain) {
Branch: 1 branch
BranchTrueFalseTotal
if ($domain) { } 2 0 2
443 2 my @parts = split(/\./,$domain);
444 2 $self->{unparsed_map}{$key}{'sort'} = join(".",reverse @parts) . '@' . $local;
445 } else {
446 0 print STDERR "FAIL: $key\n";
447 0 $self->{unparsed_map}{$key}{'sort'} = '';
448 }
449 }
450 }
451  
452 3 $self->_printout( "\nSUGGESTIONS:" );
453 3 for my $key (sort {$self->{unparsed_map}{$a} cmp $self->{unparsed_map}{$b}}
454 11 ▶ grep {$self->{unparsed_map}{$_}->{match} && $self->{unparsed_map}{$_}->{match} =~ /SUGGESTION/}
Branch: 1 branch
BranchTrueFalseTotal
$self->{"unparsed_map"}{$_}{"match"} and $self->{"unparsed_map"}{$_}{"match"} =~ /SUGGESTION/ 2 9 11
455 3 keys %{ $self->{unparsed_map} }) {
456 $self->_printout(
457 sprintf "%d,%s,%s,%d,%d,%s,%s,%s,%s,%s",
458 ($self->{unparsed_map}{$key}->{reportid} || 0),
459 ($self->{unparsed_map}{$key}->{guid} || ''),
460 ($self->{unparsed_map}{$key}->{fulldate} || ''),
461  
462 ($self->{unparsed_map}{$key}->{addressid} || 0),
463 ($self->{unparsed_map}{$key}->{testerid} || 0),
464 $key,
465 ($self->{unparsed_map}{$key}->{name} || ''),
466 ($self->{unparsed_map}{$key}->{pause} || ''),
467 ($self->{unparsed_map}{$key}->{display} || ''),
468 2 ▶ ($self->{unparsed_map}{$key}->{match} || '')
Condition50%9/18
$self->{'unparsed_map'}{$key}{'reportid'} || 0
l!l
20
$self->{'unparsed_map'}{$key}{'guid'} || ''
l!l
20
$self->{'unparsed_map'}{$key}{'fulldate'} || ''
l!l
20
$self->{'unparsed_map'}{$key}{'addressid'} || 0
l!l
02
$self->{'unparsed_map'}{$key}{'testerid'} || 0
l!l
02
$self->{'unparsed_map'}{$key}{'name'} || ''
l!l
02
$self->{'unparsed_map'}{$key}{'pause'} || ''
l!l
02
$self->{'unparsed_map'}{$key}{'display'} || ''
l!l
20
$self->{'unparsed_map'}{$key}{'match'} || ''
l!l
20
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'reportid'} || 0
$self->{'unparsed_map'}{$key}{'reportid'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'guid'} || ''
$self->{'unparsed_map'}{$key}{'guid'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'fulldate'} || ''
$self->{'unparsed_map'}{$key}{'fulldate'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'addressid'} || 0
$self->{'unparsed_map'}{$key}{'addressid'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'testerid'} || 0
$self->{'unparsed_map'}{$key}{'testerid'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'name'} || ''
$self->{'unparsed_map'}{$key}{'name'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'pause'} || ''
$self->{'unparsed_map'}{$key}{'pause'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'display'} || ''
$self->{'unparsed_map'}{$key}{'display'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'match'} || ''
$self->{'unparsed_map'}{$key}{'match'}
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'reportid'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'guid'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'fulldate'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'addressid'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'testerid'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'name'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'pause'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'display'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'match'}
Aresult
11
00
469 );
470 2 delete $self->{unparsed_map}{$key};
471 }
472  
473 3 $self->_printout( '' );
474 3 ▶ return if($self->{options}{match});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"options"}{"match"} 0 3 3
475  
476 #use Data::Dumper;
477 #print STDERR Dumper(\%{ $self->{unparsed_map} });
478  
479 3 my @mails;
480 3 $self->_printout( "PATTERNS:" );
481 3 for my $key (sort { $self->{unparsed_map}{$a}{'sort'} cmp $self->{unparsed_map}{$b}{'sort'} } keys %{ $self->{unparsed_map} }) {
482 9 ▶ next unless($key);
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 9 9
483 $self->_printout(
484 sprintf "%d,%s,%s,%d,%d,%s,%s,%s,%s,%s,%s",
485 ($self->{unparsed_map}{$key}->{reportid} || 0),
486 ($self->{unparsed_map}{$key}->{guid} || ''),
487 ($self->{unparsed_map}{$key}->{fulldate} || ''),
488  
489 ($self->{unparsed_map}{$key}->{addressid} || 0),
490 ($self->{unparsed_map}{$key}->{testerid} || 0),
491 $key,
492 ($self->{unparsed_map}{$key}->{name} || ''),
493 ($self->{unparsed_map}{$key}->{pause} || ''),
494 ($self->{unparsed_map}{$key}->{match} || ''),
495 ($self->{unparsed_map}{$key}->{display} || ''),
496 9 ▶ ($self->{unparsed_map}{$key}->{'sort'} || '')
Condition50%10/20
$self->{'unparsed_map'}{$key}{'reportid'} || 0
l!l
90
$self->{'unparsed_map'}{$key}{'guid'} || ''
l!l
90
$self->{'unparsed_map'}{$key}{'fulldate'} || ''
l!l
90
$self->{'unparsed_map'}{$key}{'addressid'} || 0
l!l
09
$self->{'unparsed_map'}{$key}{'testerid'} || 0
l!l
09
$self->{'unparsed_map'}{$key}{'name'} || ''
l!l
09
$self->{'unparsed_map'}{$key}{'pause'} || ''
l!l
09
$self->{'unparsed_map'}{$key}{'match'} || ''
l!l
09
$self->{'unparsed_map'}{$key}{'display'} || ''
l!l
09
$self->{'unparsed_map'}{$key}{'sort'} || ''
l!l
09
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'reportid'} || 0
$self->{'unparsed_map'}{$key}{'reportid'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'guid'} || ''
$self->{'unparsed_map'}{$key}{'guid'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'fulldate'} || ''
$self->{'unparsed_map'}{$key}{'fulldate'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'addressid'} || 0
$self->{'unparsed_map'}{$key}{'addressid'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'testerid'} || 0
$self->{'unparsed_map'}{$key}{'testerid'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'name'} || ''
$self->{'unparsed_map'}{$key}{'name'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'pause'} || ''
$self->{'unparsed_map'}{$key}{'pause'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'match'} || ''
$self->{'unparsed_map'}{$key}{'match'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'display'} || ''
$self->{'unparsed_map'}{$key}{'display'}
MC/DC0%0/1
$self->{'unparsed_map'}{$key}{'sort'} || ''
$self->{'unparsed_map'}{$key}{'sort'}
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'reportid'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'guid'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'fulldate'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'addressid'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'testerid'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'name'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'pause'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'match'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'display'}
Aresult
11
00
Truth table50%1/2
A
A= $self->{'unparsed_map'}{$key}{'sort'}
Aresult
11
00
497 );
498 }
499 }
500  
501 sub map_address {
502 22 ▶ my ($self,$key,$local,$domain,$email) = @_;
Subroutine map_address: called CC=10 SCAR=23.2
Pod documented
503  
504 22 ▶ if($self->{address_map}{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"address_map"}{$key}) 1 21 22
505 1 $self->{unparsed_map}{$key}->{$_} = $self->{address_map}{$key}->{$_} for(qw(testerid addressid name pause match));
506 1 return 1;
507 }
508  
509 21 ▶ if($self->{address_map}{$email}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"address_map"}{$email}) 0 21 21
510 0 $self->{unparsed_map}{$key}->{$_} = $self->{address_map}{$email}->{$_} for(qw(testerid addressid name pause match));
511 0 return 1;
512 }
513  
514 21 ▶ if($domain eq 'cpan.org') {
Branch: 1 branch
BranchTrueFalseTotal
if ($domain eq "cpan.org") 7 14 21
515 7 ▶ if($self->{pause_map}{$local}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"pause_map"}{$local}) 3 4 7
516 3 $self->{unparsed_map}{$key}->{$_} = $self->{pause_map}{$local}->{$_} for(qw(testerid addressid name pause match));
517 3 return 1;
518 }
519 }
520  
521 18 ▶ if($self->{cpan_map}{$email}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cpan_map"}{$email}) 1 17 18
522 1 $self->{unparsed_map}{$key}->{$_} = $self->{cpan_map}{$email}->{$_} for(qw(testerid addressid name pause match));
523 1 return 1;
524 }
525  
526 17 return 0;
527 }
528  
529 sub map_domain {
530 43 ▶ my ($self,$key,$local,$domain,$email) = @_;
Subroutine map_domain: called CC=11 SCAR=24.3
Pod documented
531  
532 43 for my $filter (@{$self->{filters}}) {
533 122 ▶ return 0 if($domain =~ /^$filter$/);
Branch: 1 branch
BranchTrueFalseTotal
if $domain =~ /^$filter$/ 16 106 122
534 }
535  
536 27 ▶ if($self->{domain_map}{$domain}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"domain_map"}{$domain}) 7 20 27
537 7 $self->{unparsed_map}{$key}->{$_} = $self->{domain_map}{$domain}->{$_} for(qw(testerid name pause match));
538 7 $self->{unparsed_map}{$key}->{match} .= " - $domain";
539 7 return 1;
540 }
541  
542 20 for my $map (keys %{ $self->{domain_map} }) {
543 73 ▶ if($map =~ /\b$domain$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($map =~ /\b$domain$/) 0 73 73
544 0 $self->{unparsed_map}{$key}->{$_} = $self->{domain_map}{$map}->{$_} for(qw(testerid name pause match));
545 0 $self->{unparsed_map}{$key}->{match} .= " - $domain - $map";
546 0 return 1;
547 }
548 }
549  
550 20 for my $map (keys %{ $self->{domain_map} }) {
551 72 ▶ if($domain =~ /\b$map$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($domain =~ /\b$map$/) 1 71 72
552 1 $self->{unparsed_map}{$key}->{$_} = $self->{domain_map}{$map}->{$_} for(qw(testerid name pause match));
553 1 $self->{unparsed_map}{$key}->{match} .= " - $domain - $map";
554 1 return 1;
555 }
556 }
557  
558 19 return 0;
559 }
560  
561 sub map_name {
562 11 ▶ my ($self,$key) = @_;
Subroutine map_name: called CC=7 SCAR=21.8
Pod documented
563 11 my ($name) = $key =~ /\(+"?([^"\)]+)"?\)+/;
564 11 ▶ ($name) = $key =~ /^\s*"?([^"<]+)"?\s+</ unless($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $name 11 0 11
565 11 ▶ return 0 unless($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $name 9 2 11
566  
567 2 ▶ if($self->{named_map}{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"named_map"}{$name}) 0 2 2
568 0 $self->{unparsed_map}{$key}->{$_} = $self->{named_map}{$name}->{$_} for(qw(testerid name pause match));
569 0 return 1;
570 }
571  
572 2 ▶ if($self->{paused_map}{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"paused_map"}{$name}) 0 2 2
573 0 $self->{unparsed_map}{$key}->{$_} = $self->{paused_map}{$name}->{$_} for(qw(testerid name pause match));
574 0 return 1;
575 }
576  
577 2 $self->{unparsed_map}{$key}{display} = $name;
578 2 $self->{unparsed_map}{$key}{match} = '# SUGGESTION';
579  
580 2 return 0;
581 }
582  
583 #----------------------------------------------------------------------------
584 # Private Methods
585  
586 sub _lastid {
587 8 ▶ my ($self,$id) = @_;
Subroutine _lastid: called CC=4 SCAR=13.9
588 8 my $f = $self->lastfile();
589  
590 8 ▶ unless( -f $f) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $f) 2 6 8
591 2 mkpath(dirname($f));
592 2 overwrite_file( $f, 0 );
593 2 ▶ $id ||= 0;
Condition50%1/2
$id ||= 0
l!l
02
MC/DC0%0/1
$id ||= 0
$id
Truth table50%1/2
A
A= $id
Aresult
11
00
594 }
595  
596 8 ▶ if($id) { overwrite_file( $f, $id ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($id) { } 2 6 8
597 6 else { $id = read_file($f); }
598  
599 8 return $id;
600 }
601  
602 sub _extract_email {
603 111 ▶ my $str = shift;
Subroutine _extract_email: called CC=2 SCAR=7.1
604 #my ($email) = $str =~ /([-+=\w.]+\@(?:[-\w]+\.)+(?:com|net|org|info|biz|edu|museum|mil|gov|[a-z]{2,2}))/i;
605 111 my ($email) = $str =~ /([-+=\w.]+\@[-\w\.]+)/i;
606 111 ▶ return $email || '';
Condition50%1/2
$email || ''
l!l
1110
MC/DC0%0/1
$email || ''
$email
Truth table50%1/2
A
A= $email
Aresult
11
00
607 }
608  
609 sub _init_options {
610 18 ▶ my $self = shift;
Subroutine _init_options: called CC=37 SCAR=37.5
611 18 my %hash = @_;
612 18 $self->{options} = {};
613 18 my @options = qw(mailrc update clean reindex lastid backup month match verbose lastfile logfile logclean output);
614 18 my %options;
615  
616 18 ▶ GetOptions( \%options,
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions(\%options, "config|c=s", "update|u=s", "clean", "reindex|r", "lastid|l=i", "backup|b", "mailrc|m=s", "month=s", "match", "output=s", "lastfile=s", "logfile=s", "logclean=i", "verbose|v", "version", "help|h") or $self->_help 0 18 18
617  
618 # mandatory options
619 'config|c=s',
620  
621 # update mode options
622 'update|u=s',
623  
624 # clean mode options
625 'clean',
626  
627 # reindex mode options
628 'reindex|r',
629 'lastid|l=i',
630  
631 # backup mode options
632 'backup|b',
633  
634 # search mode options
635 'mailrc|m=s',
636 'month=s',
637 'match',
638  
639 # other options
640 'output=s',
641 'lastfile=s',
642 'logfile=s',
643 'logclean=i',
644 'verbose|v',
645 'version',
646 'help|h'
647 ) or $self->_help();
648  
649 18 for my $opt (qw(config help version),@options) {
650 288 ▶ $self->{options}{$opt} ||= $hash{$opt} if($hash{$opt});
Branch: 1 branch
BranchTrueFalseTotal
if $hash{$opt} 29 259 288
Condition33%1/3
$self->{"options"}{$opt} ||= $hash{$opt}
l!l&&r!l&&!r
0290
MC/DC0%0/2
$self->{"options"}{$opt} ||= $hash{$opt}
$self->{"options"}{$opt} $hash{$opt}
Truth table33%1/3
A ||= B
A= $self->{"options"}{$opt}B= $hash{$opt}
ABresult
1X1
011
000
651 288 ▶ $self->{options}{$opt} ||= $options{$opt} if($options{$opt});
Branch: 1 branch
BranchTrueFalseTotal
if $options{$opt} 1 287 288
Condition33%1/3
$self->{"options"}{$opt} ||= $options{$opt}
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"options"}{$opt} ||= $options{$opt}
$self->{"options"}{$opt} $options{$opt}
Truth table33%1/3
A ||= B
A= $self->{"options"}{$opt}B= $options{$opt}
ABresult
1X1
011
000
652 }
653  
654 18 ▶ $self->_help(1) if($self->{options}{help});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"options"}{"help"} 2 16 18
655 16 ▶ $self->_help(0) if($self->{options}{version});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"options"}{"version"} 1 15 16
656  
657 15 ▶ $self->_help(1,"Must specify the configuration file") unless( $self->{options}{config});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"options"}{"config"} 1 14 15
658 14 ▶ $self->_help(1,"Configuration file [$self->{options}{config}] not found") unless(-f $self->{options}{config});
Branch: 1 branch
BranchTrueFalseTotal
unless -f $self->{"options"}{"config"} 1 13 14
659  
660 # load configuration
661 13 my $cfg = Config::IniFiles->new( -file => $self->{options}{config} );
662  
663 # configure databases
664 13 my %opts;
665 13 my $db = 'CPANSTATS';
666 13 ▶ die "No configuration for $db database\n" unless($cfg->SectionExists($db));
Branch: 1 branch
BranchTrueFalseTotal
unless $cfg->SectionExists($db) 0 13 13
667 13 $opts{$_} = $cfg->val($db,$_) for(qw(driver database dbfile dbhost dbport dbuser dbpass));
668 13 $self->dbh( CPAN::Testers::Common::DBUtils->new(%opts) );
669 13 ▶ die "Cannot configure $db database\n" unless($self->dbh);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->dbh 0 13 13
670  
671 # use configuration settings or defaults if none provided
672 13 for my $opt (@options) {
673 169 ▶ $self->{options}{$opt} ||= $cfg->val('MASTER',$opt) || $defaults{$opt};
Condition100%6/6
$self->{"options"}{$opt} ||= $cfg->val("MASTER", $opt) || $defaults{$opt}
l!l&&r!l&&!r
1051108
$cfg->val('MASTER', $opt) || $defaults{$opt}
l!l&&r!l&&!r
3813108
MC/DC0%0/3
$self->{"options"}{$opt} ||= $cfg->val("MASTER", $opt) || $defaults{$opt}
$self->{"options"}{$opt} $cfg->val('MASTER', $opt) $defaults{$opt}
Truth table0%0/4
A ||= B || C
A= $self->{"options"}{$opt}B= $cfg->val('MASTER', $opt)C= $defaults{$opt}
ABCresult
1XX1
01X1
0011
0000
674 }
675  
676 # extract filters
677 13 my $filters = $cfg->val('DOMAINS','filters');
678 13 ▶ my @filters = split("\n", $filters) if($filters);
Branch: 1 branch
BranchTrueFalseTotal
if $filters 0 13 13
679 13 ▶ $self->{filters} = \@filters if(@filters);
Branch: 1 branch
BranchTrueFalseTotal
if @filters 0 13 13
680  
681 # mandatory options
682 #for my $opt (qw()) {
683 # $self->_help(1,"No $opt configuration setting given, see help below.") unless( $self->{options}{$opt});
684 # $self->_help(1,"Given $opt file [$self->{options}{$opt}] not a valid file, see help below.") unless(-f $self->{options}{$opt});
685 #}
686  
687 # options to check if provided
688 13 for my $opt (qw(update mailrc)) {
689 26 ▶ next unless( $self->{options}{$opt});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"options"}{$opt} 11 15 26
690 15 ▶ $self->_help(1,"Given $opt file [$self->{options}{$opt}] not a valid file, see help below.") unless(-f $self->{options}{$opt});
Branch: 1 branch
BranchTrueFalseTotal
unless -f $self->{"options"}{$opt} 0 15 15
691 }
692  
693 # clean up potential rogue characters
694 13 ▶ $self->{options}{lastid} =~ s/\D+//g if($self->{options}{lastid});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"options"}{"lastid"} 0 13 13
695  
696 # prime accessors
697 13 $self->lastfile($self->{options}{lastfile});
698 13 $self->logfile($self->{options}{logfile});
699 13 $self->logclean($self->{options}{logclean});
700  
701 # configure backup DBs
702 13 ▶ if($self->{options}{backup}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"options"}{"backup"}) 1 12 13
703 1 ▶ $self->help(1,"No configuration for BACKUPS with backup option") unless($cfg->SectionExists('BACKUPS'));
Branch: 1 branch
BranchTrueFalseTotal
unless $cfg->SectionExists("BACKUPS") 0 1 1
704  
705 # available DBI drivers
706 1 my %DRIVERS_DBI = map { $_ => 1 } DBI->available_drivers();
707  
708 1 my @drivers = $cfg->val('BACKUPS','drivers');
709 1 for my $driver (@drivers) {
710 3 ▶ $self->help(1,"No configuration for backup option '$driver'") unless($cfg->SectionExists($driver));
Branch: 1 branch
BranchTrueFalseTotal
unless $cfg->SectionExists($driver) 0 3 3
711  
712 # ignore drivers that are unavailable
713 3 ▶ unless($DRIVERS_DBI{$driver}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($DRIVERS_DBI{$driver}) 1 2 3
714 1 $self->_log("Backup DBD driver '$driver' is not available");
715 1 next;
716 }
717  
718 2 %opts = ();
719 2 $opts{$_} = $cfg->val($driver,$_) for(qw(driver database dbfile dbhost dbport dbuser dbpass));
720 2 ▶ $self->{backups}{$driver}{'exists'} = $driver =~ /SQLite/i ? -f $opts{database} : 1;
Branch: 1 branch
BranchTrueFalseTotal
$driver =~ /SQLite/i ? : 1 1 2
721  
722 # CSV is a bit of an oddity!
723 2 ▶ if($driver =~ /CSV/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($driver =~ /CSV/i) 1 1 2
724 1 $self->{backups}{$driver}{'exists'} = 0;
725 1 $self->{backups}{$driver}{'dbfile'} = $opts{dbfile};
726 1 $opts{dbfile} = 'uploads';
727 1 unlink($opts{dbfile});
728 }
729  
730 2 $self->{backups}{$driver}{db} = CPAN::Testers::Common::DBUtils->new(%opts);
731 2 ▶ $self->help(1,"Cannot configure BACKUPS database for '$driver'") unless($self->{backups}{$driver}{db});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"backups"}{$driver}{"db"} 0 2 2
732 }
733 }
734  
735 # set output
736 13 ▶ if($self->{options}{output}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"options"}{"output"}) 6 7 13
737 6 ▶ if(my $fh = IO::File->new($self->{options}{output}, 'w+')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fh = "IO::File"->new($self->{"options"}{"output"}, "w+")) 6 0 6
738 6 $self->{fh} = $fh;
739 }
740 }
741  
742 13 ▶ return unless($self->{options}{verbose});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"options"}{"verbose"} 13 0 13
743 0 ▶ print STDERR "config: $_ = ".($self->{options}{$_}||'')."\n" for(@options);
Condition0%0/2
$self->{'options'}{$_} || ''
l!l
00
MC/DC0%0/1
$self->{'options'}{$_} || ''
$self->{'options'}{$_}
Truth table0%0/2
A
A= $self->{'options'}{$_}
Aresult
11
00
744 }
745  
746 sub _help {
747 5 ▶ my ($self,$full,$mess) = @_;
Subroutine _help: called CC=3 SCAR=11.0
748  
749 5 ▶ print "\n$mess\n\n" if($mess);
Branch: 1 branch
BranchTrueFalseTotal
if $mess 2 3 5
750  
751 5 ▶ if($full) {
Branch: 1 branch
BranchTrueFalseTotal
if ($full) 4 1 5
752 4 print "\n";
753 4 print "Usage:$0 ( [--help|h] | --version | --config|c=<file> \\\n";
754 4 print " ( [--update=<file>] \\\n";
755 4 print " | [--reindex] [--lastid=<num>] \\\n";
756 4 print " | [--clean] \\\n";
757 4 print " | [--backup] \\\n";
758 4 print " | [--mailrc|m=<file>] [--month=<string>] [--match] ) \\\n";
759 4 print " [--output=<file>] \\\n";
760 4 print " [--logfile=<file>] [--logclean=(0|1)] \\\n";
761 4 print " [--verbose|v] ) \n\n";
762  
763 # 12345678901234567890123456789012345678901234567890123456789012345678901234567890
764 4 print "This program manages the cpan-tester addresses.\n";
765  
766 4 print "\nFunctional Options:\n";
767 4 print " --config=<file> # path/file to configuration file\n";
768 4 print " [--mailrc=<file>] # path/file to mailrc file\n";
769 4 print " [--output=<file>] # path/file to output file (defaults to STDOUT)\n";
770  
771 4 print "\nUpdate Options:\n";
772 4 print " [--update=<file>] # run in update mode\n";
773  
774 4 print "\nReindex Options:\n";
775 4 print " [--reindex] # run in reindex mode\n";
776 4 print " [--lastid=<num>] # id to start reindex from\n";
777  
778 4 print "\nClean Options:\n";
779 4 print " [--clean] # run in clean mode (de-duplication)\n";
780  
781 4 print "\nBackup Options:\n";
782 4 print " [--backup] # run in backup mode\n";
783  
784 4 print "\nSearch Options:\n";
785 4 print " [--month=<string>] # YYYYMM string to match from\n";
786 4 print " [--match] # display matches only\n";
787  
788 4 print "\nOther Options:\n";
789 4 print " [--verbose] # turn on verbose messages\n";
790 4 print " [--version] # display current version\n";
791 4 print " [--help] # this screen\n";
792  
793 4 print "\nFor further information type 'perldoc $0'\n";
794 }
795  
796 5 print "$0 v$VERSION\n";
797 5 exit(0);
798 }
799  
800 sub _printout {
801 38 ▶ my $self = shift;
Subroutine _printout: called CC=2 SCAR=6.9
802 38 ▶ if(my $fh = $self->{fh}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fh = $self->{'fh'}) { } 34 4 38
803 34 print $fh "@_\n";
804 } else {
805 4 print STDOUT "@_\n";
806 }
807 }
808  
809 sub _log {
810 72 ▶ my $self = shift;
Subroutine _log: called CC=5 SCAR=16.2
811 72 ▶ my $log = $self->logfile or return;
Branch: 1 branch
BranchTrueFalseTotal
my $log = $self->logfile or return 0 72 72
812 72 ▶ mkpath(dirname($log)) unless(-f $log);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $log 2 70 72
813  
814 72 ▶ my $mode = $self->logclean ? 'w+' : 'a+';
Branch: 1 branch
BranchTrueFalseTotal
$self->logclean ? : 1 71 72
815 72 $self->logclean(0);
816  
817 72 my @dt = localtime(time);
818 72 my $dt = sprintf "%04d/%02d/%02d %02d:%02d:%02d", $dt[5]+1900,$dt[4]+1,$dt[3],$dt[2],$dt[1],$dt[0];
819  
820 72 ▶ 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 72 72
821 72 print $fh "$dt ", @_, "\n";
822 72 $fh->close;
823 }
824  
825 14 q!Will code for a damn fine Balti!;
826  
827 __END__
↑ Summary