X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FCPANPLUS%2FDist%2FGentoo%2FAtom.pm;h=dfddd4254c407b04bed9735b223d47d02a508d3e;hb=f1e11349a9e94499b1025601c2f7e4c73e18810e;hp=33c622c1622e54b3f3641ebe24cbee44d2b63154;hpb=c915539acae3c42715a7587868c8165f9bb7137f;p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git diff --git a/lib/CPANPLUS/Dist/Gentoo/Atom.pm b/lib/CPANPLUS/Dist/Gentoo/Atom.pm index 33c622c..dfddd42 100644 --- a/lib/CPANPLUS/Dist/Gentoo/Atom.pm +++ b/lib/CPANPLUS/Dist/Gentoo/Atom.pm @@ -68,7 +68,7 @@ sub new { if (defined $version) { unless (Scalar::Util::blessed($version) - and $_->isa('CPANPLUS::Dist::Gentoo::Version')) { + and $version->isa('CPANPLUS::Dist::Gentoo::Version')) { $version = CPANPLUS::Dist::Gentoo::Version->new($version); } } @@ -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 {