X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FCPANPLUS%2FDist%2FGentoo%2FVersion.pm;h=cc21274bdab6f9a8339e45257745bf470e9de952;hb=19eae8789c3ed2068bfde084ba9a8c711526c589;hp=1586fe2ae05a84e2c4266f19a900e8117ddfe649;hpb=39780a6e003df06b2cc73bfbb80b6c2e16b12574;p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git diff --git a/lib/CPANPLUS/Dist/Gentoo/Version.pm b/lib/CPANPLUS/Dist/Gentoo/Version.pm index 1586fe2..cc21274 100644 --- a/lib/CPANPLUS/Dist/Gentoo/Version.pm +++ b/lib/CPANPLUS/Dist/Gentoo/Version.pm @@ -9,11 +9,11 @@ CPANPLUS::Dist::Gentoo::Version - Gentoo version object. =head1 VERSION -Version 0.11 +Version 0.12 =cut -our $VERSION = '0.11'; +our $VERSION = '0.12'; =head1 DESCRIPTION @@ -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,19 +38,21 @@ $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 -=head2 C +=head2 C + + my $cdgv = CPANPLUS::Dist::Gentoo::Version->new($vstring); Creates a new L object from the version string C<$vstring>. @@ -71,7 +72,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,12 +127,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 +205,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 @@ -213,7 +230,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.