X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FCPANPLUS%2FDist%2FGentoo%2FVersion.pm;h=cd2c3f3470fe0dc0e47dc330be49295ae2bf35cc;hb=f2de516209b993fa003e7534ee2b624f7c114481;hp=e1f76742748fd777436c47b9af84068a81e76366;hpb=7bee20385150f2ebb608178ecdce3851cdc4f54f;p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git diff --git a/lib/CPANPLUS/Dist/Gentoo/Version.pm b/lib/CPANPLUS/Dist/Gentoo/Version.pm index e1f7674..cd2c3f3 100644 --- a/lib/CPANPLUS/Dist/Gentoo/Version.pm +++ b/lib/CPANPLUS/Dist/Gentoo/Version.pm @@ -28,10 +28,9 @@ use overload ( '""' => \&_stringify, ); -my $int_rx = qr/[0-9]+/; -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 $int_rx = qr/[0-9]+/; +my $letter_rx = qr/[a-zA-Z]/; +my $dotted_num_rx = qr/$int_rx(?:\.$int_rx)*/o; my @suffixes = qw; my $suffix_rx = join '|', grep !/^normal$/, @suffixes; @@ -39,14 +38,14 @@ $suffix_rx = qr/(?:$suffix_rx)/o; our $version_rx = qr{ $dotted_num_rx $letter_rx? - (?:_$suffix_rx$positive_int_rx?)* - (?:-r$positive_int_rx)? + (?:_$suffix_rx$int_rx?)* + (?:-r$int_rx)? }xo; my $capturing_version_rx = qr{ ($dotted_num_rx) ($letter_rx)? - ((?:_$suffix_rx$positive_int_rx?)*) - (?:-r($positive_int_rx))? + ((?:_$suffix_rx$int_rx?)*) + (?:-r($int_rx))? }xo; =head1 METHODS @@ -71,7 +70,7 @@ sub new { string => $vstring, version => [ split /\.+/, $1 ], letter => $2, - suffixes => [ map /_($suffix_rx)($positive_int_rx)?/go, $3 ], + suffixes => [ map /_($suffix_rx)($int_rx)?/go, $3 ], revision => $4, }, $class; } @@ -126,13 +125,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; } @@ -216,7 +228,7 @@ You can find documentation for this module with the perldoc command. =head1 COPYRIGHT & LICENSE -Copyright 2009,2010 Vincent Pit, all rights reserved. +Copyright 2009,2010,2011,2012 Vincent Pit, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.