]> 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 e1f76742748fd777436c47b9af84068a81e76366..d76bcb47df96ef041db48f4deb8253c3dfbf60dc 100644 (file)
@@ -126,13 +126,26 @@ sub _spaceship {
   my @a = @{ $v1->version };
   my @b = @{ $v2->version };
 
-  while (@a and @b) {
+  {
    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;
  }