blib/lib/CPAN/Version.pm

filter: Statementstmt 45.3% 58 / 128 Branchbran 33.3% 28 / 84 Conditioncond 40.0% 20 / 50 MC/DCmcdc 30.7% 8 / 26 Subroutinesub 50.0% 9 / 18 Podpod 0.0% 0 / 16 totaltotal 38.2% 123 / 322 CC 67 SCAR 42.3
CC
67
Cov
40%
vcmp
114.5
vcmp
114.5
readable
31.1
CRAP 69.0
« blib/lib/CPAN/Debug.pm ↑ Summary blib/lib/CPAN/InfoObj.pm »
1 package CPAN::Version;
2  
3 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 29 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 29 $VERSION = "5.5003";
6  
7 # CPAN::Version::vcmp courtesy Jost Krieger
8 193 ▶sub vcmp {
Subroutine vcmp: called CC=23 SCAR=47.4
Pod undocumented
9 0 ▶ my($self,$l,$r) = @_;
Subroutine vcmp: not called CC=23 SCAR=47.4
Pod undocumented
10 0 local($^W) = 0;
11 0 ▶ CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG;
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 193 193
if $CPAN::DEBUG 0 0 0
12  
13 # treat undef as zero
14 0 ▶ $l = 0 if $l eq 'undef';
Branch: 2 branches
BranchTrueFalseTotal
if $l eq "undef" 10 183 193
if $l eq "undef" 0 0 0
15 0 ▶ $r = 0 if $r eq 'undef';
Branch: 2 branches
BranchTrueFalseTotal
if $r eq "undef" 6 187 193
if $r eq "undef" 0 0 0
16  
17 0 ▶ return 0 if $l eq $r; # short circuit for quicker success
Branch: 2 branches
BranchTrueFalseTotal
if $l eq $r 7 186 193
if $l eq $r 0 0 0
18  
19 0 for ($l,$r) {
20 0 s/_//g;
21 }
22 0 ▶ CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG;
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 186 186
if $CPAN::DEBUG 0 0 0
23 0 for ($l,$r) {
24 0 ▶ next unless tr/.// > 1 || /^v/;
Branch: 2 branches
BranchTrueFalseTotal
unless tr/.// > 1 or /^v/ 266 106 372
unless tr/.// > 1 or /^v/ 0 0 0
Condition50%3/6
tr/.// > 1 or /^v/
l!l&&r!l&&!r
7630266
tr/.// > 1 or /^v/
l!l&&r!l&&!r
000
MC/DC100%2/2
tr/.// > 1 or /^v/
tr/.// > 1 /^v/
MC/DC0%0/2
tr/.// > 1 or /^v/
tr/.// > 1 /^v/
Truth table100%3/3
A or B
A= tr/.// > 1B= /^v/
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= tr/.// > 1B= /^v/
ABresult
1X1
011
000
25 0 s/^v?/v/;
26 0 ▶ 1 while s/\.0+(\d)/.$1/; # remove leading zeroes per group
Branch: 2 branches
BranchTrueFalseTotal
s/\.0+(\d)/.$1/ and do { '???' } 36 106 142
s/\.0+(\d)/.$1/ and do { '???' } 0 0 0
27 }
28 0 ▶ CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG;
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 186 186
if $CPAN::DEBUG 0 0 0
29 0 ▶ if ($l=~/^v/ <=> $r=~/^v/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($l =~ /^v/ <=> $r =~ /^v/) 76 110 186
if ($l =~ /^v/ <=> $r =~ /^v/) 0 0 0
30 0 for ($l,$r) {
31 0 ▶ next if /^v/;
Branch: 2 branches
BranchTrueFalseTotal
if /^v/ 76 76 152
if /^v/ 0 0 0
32 0 $_ = $self->float2vv($_);
33 }
34 }
35 0 ▶ CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG;
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 186 186
if $CPAN::DEBUG 0 0 0
36 0 my $lvstring = "v0";
37 0 my $rvstring = "v0";
38 0 ▶ if ($] >= 5.006
Branch: 2 branches
BranchTrueFalseTotal
if ($] >= "5.006" and $l =~ /^v/ and $r =~ /^v/) 91 95 186
if ($] >= "5.006" and $l =~ /^v/ and $r =~ /^v/) 0 0 0
Condition33%4/12
$] >= "5.006" and $l =~ /^v/ and $r =~ /^v/
!ll&&!rl&&r
95091
$] >= "5.006" and $l =~ /^v/
!ll&&!rl&&r
09591
$] >= "5.006" and $l =~ /^v/ and $r =~ /^v/
!ll&&!rl&&r
000
$] >= "5.006" and $l =~ /^v/
!ll&&!rl&&r
000
MC/DC33%1/3
$] >= "5.006" and $l =~ /^v/ and $r =~ /^v/
$] >= "5.006" $l =~ /^v/ $r =~ /^v/
MC/DC0%0/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
Truth table0%0/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 0 $lvstring = $self->vstring($l);
42 0 $rvstring = $self->vstring($r);
43 0 ▶ CPAN->debug(sprintf "lv[%vd] rv[%vd]", $lvstring, $rvstring) if $CPAN::DEBUG;
Branch: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 91 91
if $CPAN::DEBUG 0 0 0
44 }
45  
46 return (
47 0 ▶ ($l ne "undef") <=> ($r ne "undef")
Condition44%8/18
($l ne 'undef') <=> ($r ne 'undef') || $lvstring cmp $rvstring || $l <=> $r || $l cmp $r
l!l&&r!l&&!r
1371138
($l ne "undef") <=> ($r ne "undef") or $lvstring cmp $rvstring or $l <=> $r
l!l&&r!l&&!r
538449
($l ne "undef") <=> ($r ne "undef") or $lvstring cmp $rvstring
l!l&&r!l&&!r
053133
($l ne 'undef') <=> ($r ne 'undef') || $lvstring cmp $rvstring || $l <=> $r || $l cmp $r
l!l&&r!l&&!r
000
($l ne "undef") <=> ($r ne "undef") or $lvstring cmp $rvstring or $l <=> $r
l!l&&r!l&&!r
000
($l ne "undef") <=> ($r ne "undef") or $lvstring cmp $rvstring
l!l&&r!l&&!r
000
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
MC/DC0%0/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
Truth table0%0/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 69 ▶sub vgt {
Subroutine vgt: called CC=1 SCAR=1.2
Pod undocumented
58 0 ▶ my($self,$l,$r) = @_;
Subroutine vgt: not called CC=1 SCAR=1.2
Pod undocumented
59 0 $self->vcmp($l,$r) > 0;
60 }
61  
62 39 ▶sub vlt {
Subroutine vlt: called CC=1 SCAR=1.2
Pod undocumented
63 0 ▶ my($self,$l,$r) = @_;
Subroutine vlt: not called CC=1 SCAR=1.2
Pod undocumented
64 0 $self->vcmp($l,$r) < 0;
65 }
66  
67 25 ▶sub vge {
Subroutine vge: called CC=1 SCAR=1.2
Pod undocumented
68 0 ▶ my($self,$l,$r) = @_;
Subroutine vge: not called CC=1 SCAR=1.2
Pod undocumented
69 0 $self->vcmp($l,$r) >= 0;
70 }
71  
72 0 ▶sub vle {
Subroutine vle: not called CC=1 SCAR=6.9
Pod undocumented
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 182 ▶sub vstring {
Subroutine vstring: called CC=2 SCAR=10.5
Pod undocumented
78 0 ▶ my($self,$n) = @_;
Subroutine vstring: not called CC=2 SCAR=10.5
Pod undocumented
79 0 ▶ $n =~ s/^v// or die "CPAN::Version::vstring() called with invalid arg [$n]";
Branch: 2 branches
BranchTrueFalseTotal
$n =~ s/^v// or die "CPAN::Version::vstring() called with invalid arg [$n]" 182 0 182
$n =~ s/^v// or die "CPAN::Version::vstring() called with invalid arg [$n]" 0 0 0
80 0 pack "U*", split /\./, $n;
81 }
82  
83 # vv => visible vstring
84 76 ▶sub float2vv {
Subroutine float2vv: called CC=6 SCAR=24.1
Pod undocumented
85 0 ▶ my($self,$n) = @_;
Subroutine float2vv: not called CC=6 SCAR=24.1
Pod undocumented
86 0 my($rev) = int($n);
87 0 ▶ $rev ||= 0;
Condition50%2/4
$rev ||= 0
l!l
5125
$rev ||= 0
l!l
00
MC/DC100%1/1
$rev ||= 0
$rev
MC/DC0%0/1
$rev ||= 0
$rev
Truth table100%2/2
A
A= $rev
Aresult
11
00
Truth table0%0/2
A
A= $rev
Aresult
11
00
88 0 my($mantissa) = $n =~ /\.(\d{1,12})/; # limit to 12 digits to limit
89 # architecture influence
90 0 ▶ $mantissa ||= 0;
Condition50%2/4
$mantissa ||= 0
l!l
679
$mantissa ||= 0
l!l
00
MC/DC100%1/1
$mantissa ||= 0
$mantissa
MC/DC0%0/1
$mantissa ||= 0
$mantissa
Truth table100%2/2
A
A= $mantissa
Aresult
11
00
Truth table0%0/2
A
A= $mantissa
Aresult
11
00
91 0 ▶ $mantissa .= "0" while length($mantissa)%3;
Branch: 2 branches
BranchTrueFalseTotal
length($mantissa) % 3 and do { $mantissa .= '0' } 45 76 121
length($mantissa) % 3 and do { $mantissa .= '0' } 0 0 0
92 0 my $ret = "v" . $rev;
93 0 ▶ while ($mantissa) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mantissa) 120 76 196
if ($mantissa) 0 0 0
94 0 ▶ $mantissa =~ s/(\d{1,3})// or
Branch: 2 branches
BranchTrueFalseTotal
$mantissa =~ s/(\d{1,3})// or die "Panic: length>0 but not a digit? mantissa[$mantissa]" 120 0 120
$mantissa =~ s/(\d{1,3})// or die "Panic: length>0 but not a digit? mantissa[$mantissa]" 0 0 0
95 die "Panic: length>0 but not a digit? mantissa[$mantissa]";
96 0 $ret .= ".".int($1);
97 }
98 # warn "n[$n]ret[$ret]";
99 0 $ret =~ s/(\.0)+/.0/; # v1.0.0 => v1.0
100 0 $ret;
101 }
102  
103 17 ▶sub readable {
Subroutine readable: called CC=6 SCAR=34.4
Pod undocumented
104 0 ▶ my($self,$n) = @_;
Subroutine readable: not called CC=6 SCAR=34.4
Pod undocumented
105 0 $n =~ /^([\w\-\+\.]+)/;
106  
107 0 ▶ return $1 if defined $1 && length($1)>0;
Branch: 2 branches
BranchTrueFalseTotal
if defined $1 and length $1 > 0 17 0 17
if defined $1 and length $1 > 0 0 0 0
Condition16%1/6
defined $1 and length $1 > 0
!ll&&!rl&&r
0017
defined $1 and length $1 > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $1 and length $1 > 0
defined $1 length $1 > 0
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
Truth table0%0/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: 2 branches
BranchTrueFalseTotal
if ($] < "5.006") 0 0 0
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: 2 branches
BranchTrueFalseTotal
if (defined $CPAN::Frontend) { } 0 0 0
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: 2 branches
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
if $CPAN::DEBUG 0 0 0
128 0 return $better;
129 }
130  
131 29 1;
132  
133 __END__
« blib/lib/CPAN/Debug.pm ↑ Summary blib/lib/CPAN/InfoObj.pm »