blib/lib/CPAN/Testers/Common/Article.pm

filter: Statementstmt 96.1% 175 / 182 Branchbran 84.8% 56 / 66 Conditioncond 93.9% 31 / 33 MC/DCmcdc 85.0% 17 / 20 Subroutinesub 100% 17 / 17 Podpod 100% 5 / 5 totaltotal 93.1% 301 / 323 SCAR 39.9
CC
53
Cov
93%
parse_report
28.1
_extract_perl_version
8.0
_extract_date
8.0
CRAP 53.9
↑ Summary
1 package CPAN::Testers::Common::Article;
2  
3 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 $VERSION = '0.46';
8  
9 #----------------------------------------------------------------------------
10 # Library Modules
11  
12 8 ▶use CPAN::DistnameInfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use Email::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use MIME::QuotedPrint;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 8 ▶use base qw( Class::Accessor::Fast );
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 #----------------------------------------------------------------------------
21 # Variables
22  
23 8 my %month = (
24 Jan => 1, Feb => 2, Mar => 3, Apr => 4, May => 5, Jun => 6,
25 Jul => 7, Aug => 8, Sep => 9, Oct => 10, Nov => 11, Dec => 12,
26 );
27  
28 8 my @perl_extractions = (
29 # Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
30 # Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
31 qr/Summary of my (?:perl(?:\d+)?)? \((?:revision )?(\d+(?:\.\d+)?) (?:version|patchlevel) (\d+) subversion\s+(\d+) ?(.*?)\) configuration/,
32  
33 # the following is experimental and may provide incorrect data
34 qr!/(?:(?:site_perl|perl|perl5|\.?cpanplus)/|perl-)(5)\.?([6-9]|1[0-2])\.?(\d+)/!,
35  
36 # this dissects the report introduction and is used in the event that
37 # the report gets truncated and no perl -V information is available.
38 qr/on Perl (\d+)\.(\d+)(?:\.(\d+))?/i,
39 );
40  
41 8 my %regexes = (
42 # with time
43 1 => { re => qr/(?:\w+,)?\s+(\d+)\s+(\w+)\s+(\d+)\s+(\d+):(\d+)/, f => [qw(day month year hour min)] }, # Wed, 13 September 2004 06:29
44 2 => { re => qr/(\d+)\s+(\w+)\s+(\d+)\s+(\d+):(\d+)/, f => [qw(day month year hour min)] }, # 13 September 2004 06:29
45 3 => { re => qr/(\w+)?\s+(\d+),?\s+(\d+)\s+(\d+):(\d+)/, f => [qw(month day year hour min)] }, # September 22, 1999 06:29
46  
47 # just the date
48 4 => { re => qr/(?:\w+,)?\s+(\d+)\s+(\w+)\s+(\d+)/, f => [qw(day month year)] }, # Wed, 13 September 2004
49 5 => { re => qr/(\d+)\s+(\w+)\s+(\d+)/, f => [qw(day month year)] }, # 13 September 2004
50 6 => { re => qr/(\w+)?\s+(\d+),?\s+(\d+)/, f => [qw(month day year)] }, # September 22, 1999
51 );
52  
53 8 my $OSNAMES = qr/(cygwin|freebsd|netbsd|openbsd|darwin|linux|cygwin|darwin|MSWin32|dragonfly|solaris|MacOS|irix|mirbsd|gnu|bsdos|aix|sco|os2|haiku|beos|midnight)/i;
54 8 my %OSNAMES = (
55 'MacPPC' => 'macos',
56 'osf' => 'dec_osf',
57 'pa-risc' => 'hpux',
58 's390' => 'os390',
59 'VMS_' => 'vms',
60 'ARCHREV_0' => 'hpux',
61 'linuxThis' => 'linux',
62 'linThis' => 'linux',
63 'linuThis' => 'linux',
64 'lThis' => 'linux',
65 'openThis' => 'openbsd',
66 );
67  
68 #----------------------------------------------------------------------------
69 # The Public API
70  
71 8 __PACKAGE__->mk_accessors(
72 qw(
73 raw cooked header body
74 postdate date epoch status from distribution version
75 perl osname osvers archname subject author filename
76 osname_patterns osname_fixes
77 )
78 );
79  
80 sub new {
81 18 ▶ my($class, $article) = @_;
Subroutine new: called CC=6 SCAR=17.9
Pod documented
82 18 my $self = {};
83 18 bless $self, $class;
84  
85 18 $self->raw($article);
86 18 ▶ $article = decode_qp($article) if($article =~ /=3D/);
Branch: 1 branch
BranchTrueFalseTotal
if $article =~ /=3D/ 10 8 18
87 18 $self->cooked($article);
88  
89 18 my $mail;
90 18 eval { $mail = Email::Simple->new($article) };
91 18 ▶ return unless $mail;
Branch: 1 branch
BranchTrueFalseTotal
unless $mail 0 18 18
92  
93 18 $self->header($mail->header_obj());
94 18 $self->body($mail->body());
95  
96 18 ▶ return if $mail->header("In-Reply-To");
Branch: 1 branch
BranchTrueFalseTotal
if $mail->header("In-Reply-To") 2 16 18
97  
98 16 my $from = $mail->header("From");
99 16 my $subject = $mail->header("Subject");
100 16 ▶ return unless $subject;
Branch: 1 branch
BranchTrueFalseTotal
unless $subject 2 14 16
101 14 ▶ return if $subject =~ /::/; # it's supposed to be a distribution
Branch: 1 branch
BranchTrueFalseTotal
if $subject =~ /::/ 1 13 14
102  
103 13 $self->osname_patterns( $OSNAMES );
104 13 $self->osname_fixes( \%OSNAMES );
105  
106 13 $self->{mail} = $mail;
107 13 $self->{from} = $from;
108 13 $self->{subject} = $subject;
109  
110 13 ($self->{postdate},$self->{date},$self->{epoch}) = $self->_parse_date($mail);
111  
112 13 return $self;
113 }
114  
115 sub parse_upload {
116 10 ▶ my $self = shift;
Subroutine parse_upload: called CC=5 SCAR=16.1
Pod documented
117 10 my $mail = $self->{mail};
118 10 my $subject = $self->{subject};
119  
120 10 ▶ return 0 unless($subject =~ /CPAN Upload:\s+([-\w\/\.\+]+)/i);
Branch: 1 branch
BranchTrueFalseTotal
unless $subject =~ m[CPAN Upload:\s+([-\w/\.\+]+)]i 3 7 10
121 7 my $distvers = $1;
122  
123 # only record supported archives
124 7 ▶ return 0 if($distvers !~ /\.(?:(?:tar\.|t)(?:gz|bz2)|zip)$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $distvers =~ /\.(?:(?:tar\.|t)(?:gz|bz2)|zip)$/ 2 5 7
125  
126 # CPAN::DistnameInfo doesn't support .tar.bz2 files ... yet
127 5 $distvers =~ s/\.(?:tar\.|t)bz2$//i;
128 5 ▶ $distvers .= '.tar.gz' unless $distvers =~ /\.(?:(?:tar\.|t)gz|zip)$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $distvers =~ /\.(?:(?:tar\.|t)gz|zip)$/i 1 4 5
129  
130 # CPAN::DistnameInfo doesn't support old form of uploads
131 5 my @parts = split("/",$distvers);
132 5 ▶ if(@parts == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parts == 2) 1 4 5
133 1 my ($first,$second,$rest) = split(//,$distvers,3);
134 1 $distvers = "$first/$first$second/$first$second$rest";
135 }
136  
137 5 my $d = CPAN::DistnameInfo->new($distvers);
138 5 $self->distribution($d->dist);
139 5 $self->version($d->version);
140 5 $self->author($d->cpanid);
141 5 $self->filename($d->filename);
142  
143 5 return 1;
144 }
145  
146 sub parse_report {
147 12 ▶ my $self = shift;
Subroutine parse_report: called CC=27 SCAR=33.4
Pod documented
148 12 my $mail = $self->{mail};
149 12 my $from = $self->{from};
150 12 my $subject = $self->{subject};
151  
152 12 my ($status, $distversion, $platform, $osver) = split /\s+/, $subject;
153 12 ▶ return 0 unless $status =~ /^(PASS|FAIL|UNKNOWN|NA)$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $status =~ /^(PASS|FAIL|UNKNOWN|NA)$/i 2 10 12
154  
155 10 ▶ $platform ||= "";
Condition100%2/2
$platform ||= ""
l!l
64
MC/DC100%1/1
$platform ||= ""
$platform
Truth table100%2/2
A
A= $platform
Aresult
11
00
156 10 $platform =~ s/[\s&,<].*//;
157  
158 10 ▶ $distversion ||= "";
Condition100%2/2
$distversion ||= ""
l!l
91
MC/DC100%1/1
$distversion ||= ""
$distversion
Truth table100%2/2
A
A= $distversion
Aresult
11
00
159 10 $distversion =~ s!/$!!;
160 10 $distversion =~ s/\.tar.*/.tar.gz/;
161 10 ▶ $distversion .= '.tar.gz' unless $distversion =~ /\.(tar|tgz|zip)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $distversion =~ /\.(tar|tgz|zip)/ 10 0 10
162  
163 10 my $d = CPAN::DistnameInfo->new($distversion);
164 10 my ($dist, $version) = ($d->dist, $d->version);
165 10 ▶ return 0 unless defined $dist;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dist 1 9 10
166 9 ▶ return 0 unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 1 8 9
167  
168 8 my $encoding = $mail->header('Content-Transfer-Encoding');
169 8 my $head = $mail->header("X-Test-Reporter-Perl");
170 8 my $body = $mail->body;
171 8 ▶ $body = decode_base64($body) if($encoding && $encoding eq 'base64');
Branch: 1 branch
BranchTrueFalseTotal
if $encoding and $encoding eq "base64" 0 8 8
Condition66%2/3
$encoding and $encoding eq "base64"
!ll&&!rl&&r
260
MC/DC0%0/2
$encoding and $encoding eq "base64"
$encoding $encoding eq "base64"
Truth table66%2/3
A and B
A= $encodingB= $encoding eq "base64"
ABresult
0X0
100
111
172  
173 8 my $perl = $self->_extract_perl_version($body,$head);
174  
175 8 my ($osname) = $body =~ /(?:Summary of my perl5|Platform:).*?osname=([^\s\n,<\']+)/s;
176 8 my ($osvers) = $body =~ /(?:Summary of my perl5|Platform:).*?osvers=([^\s\n,<\']+)/s;
177 8 my ($archname) = $body =~ /(?:Summary of my perl5|Platform:).*?archname=([^\s\n&,<\']+)/s;
178 8 ▶ $archname =~ s/\n.*// if($archname);
Branch: 1 branch
BranchTrueFalseTotal
if $archname 3 5 8
179  
180 8 $self->status($status);
181 8 $self->distribution($dist);
182 8 $self->version($version);
183 8 ▶ $self->from($from || "");
Condition100%2/2
$from || ''
l!l
35
MC/DC100%1/1
$from || ''
$from
Truth table100%2/2
A
A= $from
Aresult
11
00
184 8 $self->perl($perl);
185 8 $self->filename($d->filename);
186  
187 8 ▶ unless($archname || $platform) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($archname or $platform) 3 5 8
Condition100%3/3
$archname or $platform
l!l&&r!l&&!r
323
MC/DC100%2/2
$archname or $platform
$archname $platform
Truth table100%3/3
A or B
A= $archnameB= $platform
ABresult
1X1
011
000
188 3 ▶ if($osname && $osvers) { $platform = "$osname-$osvers" }
Branch: 2 branches
BranchTrueFalseTotal
if ($osname and $osvers) { } 1 2 3
elsif ($osname) { } 1 1 2
Condition100%3/3
$osname and $osvers
!ll&&!rl&&r
111
MC/DC100%2/2
$osname and $osvers
$osname $osvers
Truth table100%3/3
A and B
A= $osnameB= $osvers
ABresult
0X0
100
111
189 1 elsif($osname) { $platform = $osname }
190 }
191  
192 8 ▶ unless($osname) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($osname) 2 6 8
193 2 my $patterns = $self->osname_patterns;
194 2 my $fixes = $self->osname_fixes;
195  
196 2 for my $text ($platform, $archname) {
197 3 ▶ next unless($text);
Branch: 1 branch
BranchTrueFalseTotal
unless $text 2 1 3
198 1 ▶ if($text =~ $patterns) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /$patterns/) { } 1 0 1
199 1 $osname = $1;
200 } else {
201 0 for my $rx (keys %$fixes) {
202 0 ▶ if($text =~ /$rx/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /$rx/i) 0 0 0
203 0 $osname = $fixes->{$rx};
204 0 last;
205 }
206 }
207 }
208 1 ▶ last if($osname);
Branch: 1 branch
BranchTrueFalseTotal
if $osname 1 0 1
209 }
210 }
211  
212 8 ▶ $osvers ||= $osver;
Condition66%2/3
$osvers ||= $osver
l!l&&r!l&&!r
503
MC/DC50%1/2
$osvers ||= $osver
$osvers $osver
Truth table66%2/3
A ||= B
A= $osversB= $osver
ABresult
1X1
011
000
213  
214 8 ▶ $self->osname($osname || "");
Condition100%2/2
$osname || ''
l!l
71
MC/DC100%1/1
$osname || ''
$osname
Truth table100%2/2
A
A= $osname
Aresult
11
00
215 8 ▶ $self->osvers($osvers || "");
Condition100%2/2
$osvers || ''
l!l
53
MC/DC100%1/1
$osvers || ''
$osvers
Truth table100%2/2
A
A= $osvers
Aresult
11
00
216 8 ▶ $self->archname($archname || $platform);
Condition100%3/3
$archname || $platform
l!l&&r!l&&!r
341
MC/DC100%2/2
$archname || $platform
$archname $platform
Truth table100%3/3
A || B
A= $archnameB= $platform
ABresult
1X1
011
000
217  
218 8 return 1;
219 }
220  
221 sub passed {
222 3 ▶ my $self = shift;
Subroutine passed: called CC=1 SCAR=0.0
Pod documented
223 3 return $self->status eq 'PASS';
224 }
225  
226 sub failed {
227 3 ▶ my $self = shift;
Subroutine failed: called CC=1 SCAR=0.0
Pod documented
228 3 return $self->status eq 'FAIL';
229 }
230  
231 #----------------------------------------------------------------------------
232 # The Private Methods
233  
234 sub _parse_date {
235 13 ▶ my ($self,$mail) = @_;
Subroutine _parse_date: called CC=4 SCAR=15.2
236 13 my ($date1,$date2,$date3) = $self->_extract_date($mail->header("Date"));
237 13 my @received = $mail->header("Received");
238  
239 13 for my $hdr (@received) {
240 68 ▶ next unless($hdr =~ /.*;\s+(.*)\s*$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $hdr =~ /.*;\s+(.*)\s*$/ 0 68 68
241 68 my ($dt1,$dt2,$dt3) = $self->_extract_date($1);
242 68 ▶ if($dt2 > $date2 + 1200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dt2 > $date2 + 1200) 0 68 68
243 0 $date1 = $dt1;
244 0 $date2 = $dt2;
245 0 $date3 = $dt3;
246 }
247 }
248  
249 #print STDERR " ... X.[Date: ".($date||'')."]\n";
250 13 return($date1,$date2,$date3);
251 }
252  
253 sub _extract_date {
254 93 ▶ my ($self,$date) = @_;
Subroutine _extract_date: called CC=8 SCAR=20.8
255 93 my (%fields,@fields,$index);
256  
257 #print STDERR "# ... 0.[Date: ".($date||'')."]\n";
258  
259 93 for my $inx (sort {$a <=> $b} keys %regexes) {
260 187 (@fields) = ($date =~ $regexes{$inx}->{re});
261 187 ▶ if(@fields) {
Branch: 1 branch
BranchTrueFalseTotal
if (@fields) 90 97 187
262 90 $index = $inx;
263 90 last;
264 }
265 }
266  
267 93 ▶ return('000000','000000000000',0) unless($index);
Branch: 1 branch
BranchTrueFalseTotal
unless $index 3 90 93
268  
269 90 @fields{@{$regexes{$index}->{f}}} = @fields;
270  
271 90 $fields{month} = substr($fields{month},0,3);
272 90 $fields{mon} = $month{$fields{month}};
273 90 ▶ return('000000','000000000000',0) unless($fields{mon} && $fields{year} > 1998);
Branch: 1 branch
BranchTrueFalseTotal
unless $fields{"mon"} and $fields{"year"} > 1998 2 88 90
Condition100%3/3
$fields{"mon"} and $fields{"year"} > 1998
!ll&&!rl&&r
1188
MC/DC100%2/2
$fields{"mon"} and $fields{"year"} > 1998
$fields{"mon"} $fields{"year"} > 1998
Truth table100%3/3
A and B
A= $fields{"mon"}B= $fields{"year"} > 1998
ABresult
0X0
100
111
274  
275 88 ▶ $fields{$_} ||= 0 for(qw(sec min hour day mon year));
Condition100%2/2
$fields{$_} ||= 0
l!l
43296
MC/DC100%1/1
$fields{$_} ||= 0
$fields{$_}
Truth table100%2/2
A
A= $fields{$_}
Aresult
11
00
276 88 my @date = map { $fields{$_} } qw(sec min hour day mon year);
277  
278 #print STDERR "# ... 1.[$_][$fields{$_}]\n" for(qw(year month day hour min));
279 88 my $short = sprintf "%04d%02d", $fields{year}, $fields{mon};
280 88 my $long = sprintf "%04d%02d%02d%02d%02d", $fields{year}, $fields{mon}, $fields{day}, $fields{hour}, $fields{min};
281 88 $date[4]--;
282 88 my $epoch = timegm(@date);
283  
284 88 return($short,$long,$epoch);
285 }
286  
287 # there are a number of test reports that either omitted the perl version
288 # completely, or have had it truncated by the NNTP mail server. In more recent
289 # reports the perl version number is also listed towards the beginning of the
290 # report. The cocde below now attempts to find something in all known places.
291  
292 sub _extract_perl_version {
293 22 ▶ my ($self, $body, $head) = @_;
Subroutine _extract_perl_version: called CC=8 SCAR=20.8
294 22 my ($rev, $ver, $sub, $extra);
295  
296 22 for my $regex (@perl_extractions) {
297 41 ($rev, $ver, $sub, $extra) = $body =~ /$regex/si;
298 41 ▶ last if(defined $rev);
Branch: 1 branch
BranchTrueFalseTotal
if defined $rev 15 26 41
299 }
300  
301 22 ▶ return 0 unless(defined $rev);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rev 7 15 22
302  
303 #$ver ||= 0; # current patterns require ver and sub values
304 #$sub ||= 0;
305  
306 15 my $perl = $rev + ($ver / 1000) + ($sub / 1000000);
307 15 $rev = int($perl);
308 15 $ver = int(($perl*1000)%1000);
309 15 $sub = int(($perl*1000000)%1000);
310  
311 # check for a release candidate (classed as a patch)
312 15 ▶ if($head && $head =~ /v5\.\d+\.\d+ (RC\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($head and $head =~ /v5\.\d+\.\d+ (RC\d+)/) 1 14 15
Condition100%3/3
$head and $head =~ /v5\.\d+\.\d+ (RC\d+)/
!ll&&!rl&&r
1311
MC/DC100%2/2
$head and $head =~ /v5\.\d+\.\d+ (RC\d+)/
$head $head =~ /v5\.\d+\.\d+ (RC\d+)/
Truth table100%3/3
A and B
A= $headB= $head =~ /v5\.\d+\.\d+ (RC\d+)/
ABresult
0X0
100
111
313 1 ▶ $extra .= ' ' if($extra);
Branch: 1 branch
BranchTrueFalseTotal
if $extra 0 1 1
314 1 $extra .= "$1";
315 }
316  
317 15 my $version = sprintf "%d.%d.%d", $rev, $ver, $sub;
318 15 ▶ $version .= " $extra" if $extra;
Branch: 1 branch
BranchTrueFalseTotal
if $extra 3 12 15
319 15 return $version;
320 }
321  
322 8 1;
323  
324 __END__
↑ Summary