| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # treat undef as zero | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 192 | ▶ | $l = 0 if $l eq 'undef'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 192 | ▶ | $r = 0 if $r eq 'undef'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 192 | ▶ | return 0 if $l eq $r; # short circuit for quicker success | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 185 | for ($l,$r) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 370 | ▶ | next unless tr/.// > 1 || /^v/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
tr/.// > 1 or /^v/
MC/DC100%2/2
tr/.// > 1 or /^v/
tr/.// > 1
/^v/
Truth table100%3/3
A or B
A= tr/.// > 1B= /^v/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 106 | s/^v?/v/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 106 | ▶ | 1 while s/\.0+(\d)/.$1/; # remove leading zeroes per group | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 185 | ▶ | CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 185 | ▶ | if ($l=~/^v/ <=> $r=~/^v/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 76 | for ($l,$r) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 152 | ▶ | next if /^v/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 76 | $_ = $self->float2vv($_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 185 | ▶ | CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 185 | my $lvstring = "v0"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 185 | my $rvstring = "v0"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 185 | ▶ | if ($] >= 5.006 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$] >= "5.006" and $l =~ /^v/ and $r =~ /^v/
$] >= "5.006" and $l =~ /^v/
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 ne "undef") <=> ($r ne "undef") or $lvstring cmp $rvstring or $l <=> $r
($l ne "undef") <=> ($r ne "undef") or $lvstring cmp $rvstring
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC100%1/1
$rev ||= 0
$rev
Truth table100%2/2
A
A= $rev
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC100%1/1
$mantissa ||= 0
$mantissa
Truth table100%2/2
A
A= $mantissa
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 76 | ▶ | $mantissa .= "0" while length($mantissa)%3; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 76 | my $ret = "v" . $rev; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 76 | ▶ | while ($mantissa) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 120 | ▶ | $mantissa =~ s/(\d{1,3})// or | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $1 and 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | return $better; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 27 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||