]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/blobdiff - lib/CPANPLUS/Dist/Gentoo/Version.pm
Correctly handle leading zeros in version components
[perl/modules/CPANPLUS-Dist-Gentoo.git] / lib / CPANPLUS / Dist / Gentoo / Version.pm
index bce74eadd906bac4f472bf34817035d8a1016682..d76bcb47df96ef041db48f4deb8253c3dfbf60dc 100644 (file)
@@ -9,11 +9,11 @@ CPANPLUS::Dist::Gentoo::Version - Gentoo version object.
 
 =head1 VERSION
 
-Version 0.10
+Version 0.11
 
 =cut
 
-our $VERSION = '0.10';
+our $VERSION = '0.11';
 
 =head1 DESCRIPTION
 
@@ -33,7 +33,7 @@ my $positive_int_rx = qr/0*[1-9][0-9]*/;
 my $letter_rx       = qr/[a-zA-Z]/;
 my $dotted_num_rx   = qr/$int_rx(?:\.$int_rx)*/o;
 
-my @suffixes  = qw(alpha beta pre rc normal p);
+my @suffixes  = qw<alpha beta pre rc normal p>;
 my $suffix_rx = join '|', grep !/^normal$/, @suffixes;
 $suffix_rx    = qr/(?:$suffix_rx)/o;
 
@@ -86,7 +86,7 @@ sub new {
 
 my @parts;
 BEGIN {
- @parts = qw/version letter suffixes revision/;
+ @parts = qw<version letter suffixes revision>;
  eval "sub $_ { \$_[0]->{$_} }" for @parts;
 }
 
@@ -126,12 +126,28 @@ sub _spaceship {
   my @a = @{ $v1->version };
   my @b = @{ $v2->version };
 
-  while (@a or @b) {
-   my $x = shift(@a) || 0;
-   my $y = shift(@b) || 0;
+  {
+   my $x = shift @a;
+   my $y = shift @b;
    my $c = $x <=> $y;
    return $c if $c;
   }
+
+  while (@a and @b) {
+   my $x = shift @a;
+   my $y = shift @b;
+   my $c;
+   if ($x =~ /^0/ or $y =~ /^0/) {
+    s/0+\z// for $x, $y;
+    $c = $x cmp $y;
+   } else {
+    $c = $x <=> $y;
+   }
+   return $c if $c;
+  }
+
+  return  1 if @a;
+  return -1 if @b;
  }
 
  {
@@ -188,7 +204,7 @@ sub _stringify {
 
 =pod
 
-This class provides overloaded methods for numerical comparison and strigification.
+This class provides overloaded methods for numerical comparison and stringification.
 
 =head1 SEE ALSO