CPANAuthors/Utils/Packages.pm

filter: Statementstmt 96.6% 86 / 89 Branchbran 70.0% 14 / 20 Conditioncond 50.0% 7 / 14 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 100% 18 / 18 Podpod n/a totaltotal 84.5% 126 / 149 CC 17 SCAR 18.0
CC
17
Cov
87%
_dist_from_path
13.7
_parse
6.0
contains
2.1
CRAP 6.0
« CPANAuthors.pm ↑ Summary CPANAuthors/Utils/Kwalitee.pm »
1 package Acme::CPANAuthors::Utils::Packages;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use CPAN::DistnameInfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use base 'Acme::CPANAuthors::Utils::CPANIndex';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶sub _preambles {qw(
Subroutine _preambles: called CC=1 SCAR=0.0
10 file url description columns intended_for
11 written_by line_count last_updated
12 )}
13  
14 10 ▶sub _mappings {+{
Subroutine _mappings: called CC=1 SCAR=0.0
15 10 package => 'packages',
16 distribution => 'dists',
17 latest_distribution => 'latest_dists',
18 }}
19  
20 2 ▶sub _parse {
Subroutine _parse: called CC=6 SCAR=17.9
21 2 my ($self, $file) = @_;
22  
23 2 my $handle = $self->_handle($file);
24  
25 2 my $done_preambles = 0;
26 2 ▶ while (my $line = $handle->getline) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = $handle->getline) 36 2 38
27 36 $line =~ s/\r?\n$//;
28 36 ▶ unless ($done_preambles) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($done_preambles) 18 18 36
29 18 ▶ if ($line =~ /^\s*$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /^\s*$/) { } 2 16 18
elsif (() = $line =~ /^([^:]+):\s*(.*)/) { } 16 0 16
30 2 $done_preambles = 1;
31 }
32 elsif (my ($key, $value) = $line =~ /^([^:]+):\s*(.*)/) {
33 16 $key =~ tr/A-Z\-/a-z_/;
34 16 $self->{preambles}{$key} = $value;
35 }
36 18 next;
37 }
38  
39 18 my ($package, $version, $path) = split ' ', $line;
40  
41 18 my $dist = $self->_dist_from_path($path);
42  
43 18 my $pkg = Acme::CPANAuthors::Utils::Packages::Package->new({
44 package => $package,
45 version => $version,
46 distribution => $dist,
47 });
48  
49 18 ▶ push @{ $dist->{packages} ||= [] }, $pkg;
Condition100%2/2
$dist->{"packages"} ||= []
l!l
414
MC/DC100%1/1
$dist->{"packages"} ||= []
$dist->{"packages"}
Truth table100%2/2
A
A= $dist->{"packages"}
Aresult
11
00
50  
51 18 $self->{packages}{$package} = $pkg;
52 }
53 }
54  
55 18 ▶sub _dist_from_path {
Subroutine _dist_from_path: called CC=11 SCAR=26.1
56 18 my ($self, $path) = @_;
57  
58 18 my $dist = $self->{dists}{$path};
59 18 ▶ return $dist if $dist;
Branch: 1 branch
BranchTrueFalseTotal
if $dist 4 14 18
60  
61 14 my $info = CPAN::DistnameInfo->new($path);
62 14 $dist = Acme::CPANAuthors::Utils::Packages::Distribution->new({
63 prefix => $path,
64 dist => $info->dist,
65 version => $info->version,
66 maturity => $info->maturity,
67 filename => $info->filename,
68 cpanid => $info->cpanid,
69 distvname => $info->distvname,
70 });
71  
72 14 $self->{dists}{$path} = $dist;
73  
74 14 ▶ return unless defined $dist->version && $dist->dist;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dist->version and $dist->dist 0 14 14
Condition33%1/3
defined $dist->version and $dist->dist
!ll&&!rl&&r
0014
MC/DC0%0/2
defined $dist->version and $dist->dist
defined $dist->version $dist->dist
Truth table33%1/3
A and B
A= defined $dist->versionB= $dist->dist
ABresult
0X0
100
111
75  
76 # see if it's latest
77 14 my $distname = $info->dist;
78 14 my $latest = $self->{latest_dists}{$distname};
79 14 ▶ unless ($latest) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($latest) 12 2 14
80 12 $self->{latest_dists}{$distname} = $dist;
81 12 return $dist;
82 }
83 2 my ($distv, $latestv);
84 2 eval {
85 2 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
86 2 ▶ $distv = version->new( $dist->version || 0 );
Condition50%1/2
$dist->version || 0
l!l
20
MC/DC0%0/1
$dist->version || 0
$dist->version
Truth table50%1/2
A
A= $dist->version
Aresult
11
00
87 2 ▶ $latestv = version->new( $latest->version || 0 );
Condition50%1/2
$latest->version || 0
l!l
20
MC/DC0%0/1
$latest->version || 0
$latest->version
Truth table50%1/2
A
A= $latest->version
Aresult
11
00
88 };
89 2 ▶ if ($distv && $latestv) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distv and $latestv) { } 2 0 2
Condition33%1/3
$distv and $latestv
!ll&&!rl&&r
002
MC/DC0%0/2
$distv and $latestv
$distv $latestv
Truth table33%1/3
A and B
A= $distvB= $latestv
ABresult
0X0
100
111
90 2 ▶ if ($distv > $latestv) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distv > $latestv) 0 2 2
91 0 $self->{latest_dists}{$distname} = $dist;
92 }
93 }
94 else {
95 2 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
96 0 ▶ if ($dist->version > $latest->version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist->version > $latest->version) 0 0 0
97 0 $self->{latest_dists}{$distname} = $dist;
98 }
99 }
100  
101 2 $dist;
102 }
103  
104 package #
105 Acme::CPANAuthors::Utils::Packages::Distribution;
106  
107 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
108 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
109 2 ▶use base 'Class::Accessor::Fast';
Subroutine BEGIN: called CC=1 SCAR=0.0
110  
111 2 __PACKAGE__->mk_ro_accessors(qw/
112 prefix
113 dist
114 version
115 maturity
116 filename
117 cpanid
118 distvname
119 packages
120 /);
121  
122 2 *path = *prefix;
123 2 *name = *dist;
124 2 *pauseid = *cpanid;
125  
126 1 ▶sub contains { @{ shift->{packages} || [] } }
Subroutine contains: called CC=2 SCAR=7.2
Condition50%1/2
+(shift())->{'packages'} || []
l!l
10
MC/DC0%0/1
+(shift())->{'packages'} || []
+(shift())->{'packages'}
Truth table50%1/2
A
A= +(shift())->{'packages'}
Aresult
11
00
127  
128 package #
129 Acme::CPANAuthors::Utils::Packages::Package;
130  
131 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
132 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
133 2 ▶use base 'Class::Accessor::Fast';
Subroutine BEGIN: called CC=1 SCAR=0.0
134  
135 2 __PACKAGE__->mk_ro_accessors(qw/
136 package
137 version
138 distribution
139 /);
140  
141 2 *name = *package;
142  
143 2 1;
144  
145 __END__
« CPANAuthors.pm ↑ Summary CPANAuthors/Utils/Kwalitee.pm »