blib/lib/CPAN/Version.pm

filter: Statementstmt 85.2% 58 / 68 Branchbran 66.6% 28 / 42 Conditioncond 80.0% 20 / 25 MC/DCmcdc 61.5% 8 / 13 Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 8 totaltotal 74.1% 123 / 166 CC 34 SCAR 28.3
CC
34
Cov
79%
vcmp
23.8
readable
22.6
float2vv
6.0
CRAP 17.0
« blib/lib/CPAN/Exception/yaml_process_error.pm ↑ Summary blib/lib/CPAN/Distroprefs.pm »
1 package CPAN::Version;
2  
3 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 $VERSION = "5.5003";
6  
7 # CPAN::Version::vcmp courtesy Jost Krieger
8 sub vcmp {
9 192 ▶ my($self,$l,$r) = @_;
Subroutine vcmp: called CC=23 SCAR=31.7
Pod undocumented
10 192 local($^W) = 0;
11 192 ▶ CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 192 192
12  
13 # treat undef as zero
14 192 ▶ $l = 0 if $l eq 'undef';
Branch: 1 branch
BranchTrueFalseTotal
if $l eq "undef" 10 182 192
15 192 ▶ $r = 0 if $r eq 'undef';
Branch: 1 branch
BranchTrueFalseTotal
if $r eq "undef" 6 186 192
16  
17 192 ▶ return 0 if $l eq $r; # short circuit for quicker success
Branch: 1 branch
BranchTrueFalseTotal
if $l eq $r 7 185 192
18  
19 185 for ($l,$r) {
20 370 s/_//g;
21 }
22 185 ▶ CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 185 185
23 185 for ($l,$r) {
24 370 ▶ next unless tr/.// > 1 || /^v/;
Branch: 1 branch
BranchTrueFalseTotal
unless tr/.// > 1 or /^v/ 264 106 370
Condition100%3/3
tr/.// > 1 or /^v/
l!l&&r!l&&!r
7630264
MC/DC100%2/2
tr/.// > 1 or /^v/
tr/.// > 1 /^v/
Truth table100%3/3
A or B
A= tr/.// > 1B= /^v/
ABresult
1X1
011
000
25 106 s/^v?/v/;
26 106 ▶ 1 while s/\.0+(\d)/.$1/; # remove leading zeroes per group
Branch: 1 branch
BranchTrueFalseTotal
s/\.0+(\d)/.$1/ and do { '???' } 36 106 142
27 }
28 185 ▶ CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 185 185
29 185 ▶ if ($l=~/^v/ <=> $r=~/^v/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /^v/ <=> $r =~ /^v/) 76 109 185
30 76 for ($l,$r) {
31 152 ▶ next if /^v/;
Branch: 1 branch
BranchTrueFalseTotal
if /^v/ 76 76 152
32 76 $_ = $self->float2vv($_);
33 }
34 }
35 185 ▶ CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 185 185
36 185 my $lvstring = "v0";
37 185 my $rvstring = "v0";
38 185 ▶ if ($] >= 5.006
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= "5.006" and $l =~ /^v/ and $r =~ /^v/) 91 94 185
Condition66%4/6
$] >= "5.006" and $l =~ /^v/ and $r =~ /^v/
!ll&&!rl&&r
94091
$] >= "5.006" and $l =~ /^v/
!ll&&!rl&&r
09491
MC/DC33%1/3
$] >= "5.006" and $l =~ /^v/ and $r =~ /^v/
$] >= "5.006" $l =~ /^v/ $r =~ /^v/
Truth table50%2/4
A and B and C
A= $] >= "5.006"B= $l =~ /^v/C= $r =~ /^v/
ABCresult
0XX0
10X0
1100
1111
39 && $l =~ /^v/
40 && $r =~ /^v/) {
41 91 $lvstring = $self->vstring($l);
42 91 $rvstring = $self->vstring($r);
43 91 ▶ CPAN->debug(sprintf "lv[%vd] rv[%vd]", $lvstring, $rvstring) if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 91 91
44 }
45  
46 return (
47 185 ▶ ($l ne "undef") <=> ($r ne "undef")
Condition88%8/9
($l ne 'undef') <=> ($r ne 'undef') || $lvstring cmp $rvstring || $l <=> $r || $l cmp $r
l!l&&r!l&&!r
1361138
($l ne "undef") <=> ($r ne "undef") or $lvstring cmp $rvstring or $l <=> $r
l!l&&r!l&&!r
538349
($l ne "undef") <=> ($r ne "undef") or $lvstring cmp $rvstring
l!l&&r!l&&!r
053132
MC/DC75%3/4
($l ne 'undef') <=> ($r ne 'undef') || $lvstring cmp $rvstring || $l <=> $r || $l cmp $r
($l ne "undef") <=> ($r ne "undef") $lvstring cmp $rvstring $l <=> $r $l cmp $r
Truth table80%4/5
A or B or C || D
A= ($l ne "undef") <=> ($r ne "undef")B= $lvstring cmp $rvstringC= $l <=> $rD= $l cmp $r
ABCDresult
1XXX1
01XX1
001X1
00011
00000
48 ||
49 $lvstring cmp $rvstring
50 ||
51 $l <=> $r
52 ||
53 $l cmp $r
54 );
55 }
56  
57 sub vgt {
58 69 ▶ my($self,$l,$r) = @_;
Subroutine vgt: called CC=1 SCAR=0.0
Pod undocumented
59 69 $self->vcmp($l,$r) > 0;
60 }
61  
62 sub vlt {
63 39 ▶ my($self,$l,$r) = @_;
Subroutine vlt: called CC=1 SCAR=0.0
Pod undocumented
64 39 $self->vcmp($l,$r) < 0;
65 }
66  
67 sub vge {
68 24 ▶ my($self,$l,$r) = @_;
Subroutine vge: called CC=1 SCAR=0.0
Pod undocumented
69 24 $self->vcmp($l,$r) >= 0;
70 }
71  
72 sub vle {
73 0 ▶ my($self,$l,$r) = @_;
Subroutine vle: not called CC=1 SCAR=6.9
Pod undocumented
74 0 $self->vcmp($l,$r) <= 0;
75 }
76  
77 sub vstring {
78 182 ▶ my($self,$n) = @_;
Subroutine vstring: called CC=2 SCAR=7.1
Pod undocumented
79 182 ▶ $n =~ s/^v// or die "CPAN::Version::vstring() called with invalid arg [$n]";
Branch: 1 branch
BranchTrueFalseTotal
$n =~ s/^v// or die "CPAN::Version::vstring() called with invalid arg [$n]" 0 182 182
80 182 pack "U*", split /\./, $n;
81 }
82  
83 # vv => visible vstring
84 sub float2vv {
85 76 ▶ my($self,$n) = @_;
Subroutine float2vv: called CC=6 SCAR=17.9
Pod undocumented
86 76 my($rev) = int($n);
87 76 ▶ $rev ||= 0;
Condition100%2/2
$rev ||= 0
l!l
5125
MC/DC100%1/1
$rev ||= 0
$rev
Truth table100%2/2
A
A= $rev
Aresult
11
00
88 76 my($mantissa) = $n =~ /\.(\d{1,12})/; # limit to 12 digits to limit
89 # architecture influence
90 76 ▶ $mantissa ||= 0;
Condition100%2/2
$mantissa ||= 0
l!l
679
MC/DC100%1/1
$mantissa ||= 0
$mantissa
Truth table100%2/2
A
A= $mantissa
Aresult
11
00
91 76 ▶ $mantissa .= "0" while length($mantissa)%3;
Branch: 1 branch
BranchTrueFalseTotal
length($mantissa) % 3 and do { $mantissa .= '0' } 45 76 121
92 76 my $ret = "v" . $rev;
93 76 ▶ while ($mantissa) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mantissa) 120 76 196
94 120 ▶ $mantissa =~ s/(\d{1,3})// or
Branch: 1 branch
BranchTrueFalseTotal
$mantissa =~ s/(\d{1,3})// or die "Panic: length>0 but not a digit? mantissa[$mantissa]" 0 120 120
95 die "Panic: length>0 but not a digit? mantissa[$mantissa]";
96 120 $ret .= ".".int($1);
97 }
98 # warn "n[$n]ret[$ret]";
99 76 $ret =~ s/(\.0)+/.0/; # v1.0.0 => v1.0
100 76 $ret;
101 }
102  
103 sub readable {
104 17 ▶ my($self,$n) = @_;
Subroutine readable: called CC=6 SCAR=31.2
Pod undocumented
105 17 $n =~ /^([\w\-\+\.]+)/;
106  
107 17 ▶ return $1 if defined $1 && length($1)>0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $1 and length $1 > 0 17 0 17
Condition33%1/3
defined $1 and length $1 > 0
!ll&&!rl&&r
0017
MC/DC0%0/2
defined $1 and length $1 > 0
defined $1 length $1 > 0
Truth table33%1/3
A and B
A= defined $1B= length $1 > 0
ABresult
0X0
100
111
108 # if the first user reaches version v43, he will be treated as "+".
109 # We'll have to decide about a new rule here then, depending on what
110 # will be the prevailing versioning behavior then.
111  
112 0 ▶ if ($] < 5.006) { # or whenever v-strings were introduced
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.006") 0 0 0
113 # we get them wrong anyway, whatever we do, because 5.005 will
114 # have already interpreted 0.2.4 to be "0.24". So even if he
115 # indexer sends us something like "v0.2.4" we compare wrongly.
116  
117 # And if they say v1.2, then the old perl takes it as "v12"
118  
119 0 ▶ if (defined $CPAN::Frontend) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $CPAN::Frontend) { } 0 0 0
120 0 $CPAN::Frontend->mywarn("Suspicious version string seen [$n]\n");
121 } else {
122 0 warn("Suspicious version string seen [$n]\n");
123 }
124 0 return $n;
125 }
126 0 my $better = sprintf "v%vd", $n;
127 0 ▶ CPAN->debug("n[$n] better[$better]") if $CPAN::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
128 0 return $better;
129 }
130  
131 27 1;
132  
133 __END__
« blib/lib/CPAN/Exception/yaml_process_error.pm ↑ Summary blib/lib/CPAN/Distroprefs.pm »