3 CPAN::Version - utility functions to compare CPAN versions
9 CPAN::Version->vgt("1.1","1.1.1"); # 1 bc. 1.1 > 1.001001
11 CPAN::Version->vlt("1.1","1.1"); # 0 bc. 1.1 not < 1.1
13 CPAN::Version->vcmp("1.1","1.1.1"); # 1 bc. first is larger
15 CPAN::Version->vcmp("1.1.1","1.1"); # -1 bc. first is smaller
17 CPAN::Version->readable(v1.2.3); # "v1.2.3"
19 CPAN::Version->vstring("v1.2.3"); # v1.2.3
21 CPAN::Version->float2vv(1.002003); # "v1.2.3"
25 This module mediates between some version that perl sees in a package
26 and the version that is published by the CPAN indexer.
28 It's only written as a helper module for both CPAN.pm and CPANPLUS.pm.
30 As it stands it predates version.pm but has the same goal: make
31 version strings visible and comparable.
35 package CPAN::Version;
38 use vars qw($VERSION);
39 $VERSION = sprintf "%.6f", substr(q$Rev: 561 $,4)/1000000 + 5.4;
41 # CPAN::Version::vcmp courtesy Jost Krieger
45 CPAN->debug("l[$l] r[$r]") if $CPAN::DEBUG;
47 return 0 if $l eq $r; # short circuit for quicker success
50 next unless tr/.// > 1;
52 1 while s/\.0+(\d)/.$1/;
54 if ($l=~/^v/ <=> $r=~/^v/) {
57 $_ = $self->float2vv($_);
62 ($l ne "undef") <=> ($r ne "undef") ||
67 $self->vstring($l) cmp $self->vstring($r)
76 $self->vcmp($l,$r) > 0;
81 0 + ($self->vcmp($l,$r) < 0);
86 $n =~ s/^v// or die "CPAN::Version::vstring() called with invalid arg [$n]";
87 pack "U*", split /\./, $n;
90 # vv => visible vstring
95 my($mantissa) = $n =~ /\.(\d{1,12})/; # limit to 12 digits to limit
96 # architecture influence
98 $mantissa .= "0" while length($mantissa)%3;
101 $mantissa =~ s/(\d{1,3})// or
102 die "Panic: length>0 but not a digit? mantissa[$mantissa]";
105 # warn "n[$n]ret[$ret]";
111 $n =~ /^([\w\-\+\.]+)/;
113 return $1 if defined $1 && length($1)>0;
114 # if the first user reaches version v43, he will be treated as "+".
115 # We'll have to decide about a new rule here then, depending on what
116 # will be the prevailing versioning behavior then.
118 if ($] < 5.006) { # or whenever v-strings were introduced
119 # we get them wrong anyway, whatever we do, because 5.005 will
120 # have already interpreted 0.2.4 to be "0.24". So even if he
121 # indexer sends us something like "v0.2.4" we compare wrongly.
123 # And if they say v1.2, then the old perl takes it as "v12"
125 if (defined $CPAN::Frontend) {
126 $CPAN::Frontend->mywarn("Suspicious version string seen [$n]\n");
128 warn("Suspicious version string seen [$n]\n");
132 my $better = sprintf "v%vd", $n;
133 CPAN->debug("n[$n] better[$better]") if $CPAN::DEBUG;
143 # cperl-indent-level: 2