1 package Debbugs::Versions::Dpkg;
7 Debbugs::Versions::Dpkg - pure-Perl dpkg-style version comparison
11 The Debbugs::Versions::Dpkg module provides pure-Perl routines to compare
12 dpkg-style version numbers, as used in Debian packages. If you have the
13 libapt-pkg Perl bindings available (Debian package libapt-pkg-perl), they
14 may offer better performance.
28 $ver =~ /^(\d+):(.+)/ or die "bad version number '$ver'";
36 if ($ver =~ /(.+)-(.+)$/)
38 $verhash{version} = $1;
39 $verhash{revision} = $2;
43 $verhash{version} = $ver;
44 $verhash{revision} = 0;
58 if (length $alphaval or length $alpharef)
60 my @avsplit = split //, $alphaval;
61 my @arsplit = split //, $alpharef;
62 my ($av, $ar) = (0, 0);
63 while ($av < @avsplit and $ar < @arsplit)
65 my ($v, $r) = (ord $avsplit[$av], ord $arsplit[$ar]);
66 $v += 256 unless chr($v) =~ /[A-Za-z]/;
67 $r += 256 unless chr($r) =~ /[A-Za-z]/;
68 return $v <=> $r if $v != $r;
72 return 1 if $av < @avsplit;
73 return -1 if $ar < @arsplit;
76 return 0 unless length $val and length $ref;
82 return $numval <=> $numref if $numval != $numref;
88 Compare the two arguments as dpkg-style version numbers. Returns -1 if the
89 first argument represents a lower version number than the second, 1 if the
90 first argument represents a higher version number than the second, and 0 if
91 the two arguments represent equal version numbers.
97 my %version = parseversion $_[0];
98 my %refversion = parseversion $_[1];
99 return 1 if $version{epoch} > $refversion{epoch};
100 return -1 if $version{epoch} < $refversion{epoch};
101 my $r = verrevcmp $version{version}, $refversion{version};
103 return verrevcmp $version{revision}, $refversion{revision};
110 Version numbers containing the C<~> character, used for pre-releases of
111 packages, are not yet supported.
115 Colin Watson E<lt>cjwatson@debian.orgE<gt>, based on the implementation in
116 C<dpkg/lib/vercmp.c> by Ian Jackson and others.