7 # CPAN::Version::vcmp courtesy Jost Krieger
11 CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG;
13 return 0 if $l eq $r; # short circuit for quicker success
18 CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG;
20 next unless tr/.// > 1 || /^v/;
22 1 while s/\.0+(\d)/.$1/; # remove leading zeroes per group
24 CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG;
25 if ($l=~/^v/ <=> $r=~/^v/) {
28 $_ = $self->float2vv($_);
31 CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG;
37 $lvstring = $self->vstring($l);
38 $rvstring = $self->vstring($r);
39 CPAN->debug(sprintf "lv[%vd] rv[%vd]", $lvstring, $rvstring) if $CPAN::DEBUG;
43 ($l ne "undef") <=> ($r ne "undef")
45 $lvstring cmp $rvstring
55 $self->vcmp($l,$r) > 0;
60 0 + ($self->vcmp($l,$r) < 0);
65 $self->vcmp($l,$r) >= 0;
70 0 + ($self->vcmp($l,$r) <= 0);
75 $n =~ s/^v// or die "CPAN::Version::vstring() called with invalid arg [$n]";
76 pack "U*", split /\./, $n;
79 # vv => visible vstring
84 my($mantissa) = $n =~ /\.(\d{1,12})/; # limit to 12 digits to limit
85 # architecture influence
87 $mantissa .= "0" while length($mantissa)%3;
90 $mantissa =~ s/(\d{1,3})// or
91 die "Panic: length>0 but not a digit? mantissa[$mantissa]";
94 # warn "n[$n]ret[$ret]";
95 $ret =~ s/(\.0)+/.0/; # v1.0.0 => v1.0
101 $n =~ /^([\w\-\+\.]+)/;
103 return $1 if defined $1 && length($1)>0;
104 # if the first user reaches version v43, he will be treated as "+".
105 # We'll have to decide about a new rule here then, depending on what
106 # will be the prevailing versioning behavior then.
108 if ($] < 5.006) { # or whenever v-strings were introduced
109 # we get them wrong anyway, whatever we do, because 5.005 will
110 # have already interpreted 0.2.4 to be "0.24". So even if he
111 # indexer sends us something like "v0.2.4" we compare wrongly.
113 # And if they say v1.2, then the old perl takes it as "v12"
115 if (defined $CPAN::Frontend) {
116 $CPAN::Frontend->mywarn("Suspicious version string seen [$n]\n");
118 warn("Suspicious version string seen [$n]\n");
122 my $better = sprintf "v%vd", $n;
123 CPAN->debug("n[$n] better[$better]") if $CPAN::DEBUG;
133 CPAN::Version - utility functions to compare CPAN versions
139 CPAN::Version->vgt("1.1","1.1.1"); # 1 bc. 1.1 > 1.001001
141 CPAN::Version->vlt("1.1","1.1"); # 0 bc. 1.1 not < 1.1
143 CPAN::Version->vcmp("1.1","1.1.1"); # 1 bc. first is larger
145 CPAN::Version->vcmp("1.1.1","1.1"); # -1 bc. first is smaller
147 CPAN::Version->readable(v1.2.3); # "v1.2.3"
149 CPAN::Version->vstring("v1.2.3"); # v1.2.3
151 CPAN::Version->float2vv(1.002003); # "v1.2.3"
155 This module mediates between some version that perl sees in a package
156 and the version that is published by the CPAN indexer.
158 It's only written as a helper module for both CPAN.pm and CPANPLUS.pm.
160 As it stands it predates version.pm but has the same goal: make
161 version strings visible and comparable.
165 This program is free software; you can redistribute it and/or
166 modify it under the same terms as Perl itself.
172 # cperl-indent-level: 4