X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FCPANPLUS%2FDist%2FGentoo%2FAtom.pm;h=59f1d6ac959c4430a8207ad493a95d70f87f0408;hb=3a6840c4ec1f85e05975608542b33a53eacbfac1;hp=fcfa685cae2495be626b37007c6c9e9474d14b78;hpb=a3d7c9d6304ce5516bdb44d28ec2eba9c57082f3;p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git diff --git a/lib/CPANPLUS/Dist/Gentoo/Atom.pm b/lib/CPANPLUS/Dist/Gentoo/Atom.pm index fcfa685..59f1d6a 100644 --- a/lib/CPANPLUS/Dist/Gentoo/Atom.pm +++ b/lib/CPANPLUS/Dist/Gentoo/Atom.pm @@ -59,7 +59,7 @@ sub new { Carp::confess('Invalid name') unless $name =~ /^$name_rx$/o; } elsif (defined $args{atom}) { my $atom = $args{atom}; - $atom =~ m{^($range_rx)?($category_rx)/($name_rx)(?:-v?($version_rx))?$}o + $atom =~ m{^($range_rx)?($category_rx)/($name_rx)(?:-($version_rx))?$}o or Carp::confess('Invalid atom'); ($range, $category, $name, $version) = ($1, $2, $3, $4); } else { @@ -106,7 +106,7 @@ sub new_from_ebuild { my $ebuild = shift; $ebuild = '' unless defined $ebuild; - $ebuild =~ m{/($category_rx)/($name_rx)/\2-v?($version_rx)\.ebuild$}o + $ebuild =~ m{/($category_rx)/($name_rx)/\2-($version_rx)\.ebuild$}o or Carp::confess('Invalid ebuild'); my ($category, $name, $version) = ($1, $2, $3); @@ -192,20 +192,21 @@ sub _spaceship { sub _cmp { my ($a1, $a2, $r) = @_; - my $s1 = $a1->qualified_name; - my $v1 = $a1->version; - $s1 .= "-$v1" if defined $v1; + if (defined $a2) { + my $p1 = $a1->qualified_name; - my $s2; - if (Scalar::Util::blessed($a2) and $a2->isa(__PACKAGE__)) { - $s2 = $a2->qualified_name; - my $v2 = $a2->version; - $s2 .= "-$v2" if defined $v2; - } else { - $s2 = $a2; + unless (Scalar::Util::blessed($a2) && $a2->isa(__PACKAGE__)) { + $a2 = eval { __PACKAGE__->new(atom => $a2) }; + Carp::confess("Can't compare an atom against something that's not an atom or an atom string ($@)") if $@; + } + my $p2 = $a2->qualified_name; + + if (my $c = $p1 cmp $p2) { + return $r ? -$c : $c; + } } - $s1 cmp $s2; + $a1 <=> $a2; } sub _stringify { @@ -294,7 +295,7 @@ sub fold { $seen{$key} = defined $cur ? $cur->and($atom) : $atom; } - return values %seen; + return map $seen{$_}, sort keys %seen; } =pod