X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FCPANPLUS%2FDist%2FGentoo%2FAtom.pm;h=dd35ad6d8f3cfc67efdbf0e324acc6de1b08187a;hb=1c1a8d6482b5d4baac0e7aa58c6bf1ceb380c8b9;hp=e285b0ce32a28b8220f4a4a36739e9bcbe1461c9;hpb=93eb049958520c8b4980d76e5654e5cdd3774d2f;p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git diff --git a/lib/CPANPLUS/Dist/Gentoo/Atom.pm b/lib/CPANPLUS/Dist/Gentoo/Atom.pm index e285b0c..dd35ad6 100644 --- a/lib/CPANPLUS/Dist/Gentoo/Atom.pm +++ b/lib/CPANPLUS/Dist/Gentoo/Atom.pm @@ -48,16 +48,16 @@ sub new { my %args = @_; - my ($category, $name, $version); + my ($range, $category, $name, $version); if (defined $args{name}) { - ($category, $name, $version) = @args{qw/category name version/}; + ($range, $category, $name, $version) = @args{qw/range category name version/}; Carp::confess('Category unspecified') unless defined $category; /[^\w-]/ and Carp::confess('Invalid argument') for $name, $category; } elsif (defined $args{atom}) { my $atom = $args{atom}; - $atom =~ m{^([\w-]+)/([\w-]+)-v?($version_rx)$} + $atom =~ m{^(<|<=|=|>=|>)?([\w-]+)/([\w-]+)(?-v?($version_rx))?$} or Carp::confess('Invalid atom'); - ($category, $name, $version) = ($1, $2, $3); + ($range, $category, $name, $version) = ($1, $2, $3, $4); } else { Carp::confess('Not enough information for building an atom object'); } @@ -69,7 +69,6 @@ sub new { } } - my $range = $args{range}; if (defined $version) { if (defined $range) { Carp::confess("Invalid range $range") @@ -154,16 +153,36 @@ sub _spaceship { my $v1 = $a1->version; my $v2; - if (Scalar::Util::blessed($a2) and $a2->isa(__PACKAGE__)) { - Carp::confess('Can\'t compare atoms of different packages') - if $a1->category ne $a2->category or $a1->name ne $a2->name; + my $blessed = Scalar::Util::blessed($a2); + unless ($blessed and $a2->isa(__PACKAGE__)) { + if ($blessed and $a2->isa('CPANPLUS::Dist::Gentoo::Version')) { + $v2 = $a2; + $a2 = undef; + } else { + my $maybe_atom = eval { __PACKAGE__->new(atom => $a2) }; + if (my $err = $@) { + $v2 = eval { CPANPLUS::Dist::Gentoo::Version->new($a2) }; + Carp::confess("Can't compare an atom against something that's not an atom, an atom string ($err), a version or a version string ($@)") if $@; + $a2 = undef; + } else { + $a2 = $maybe_atom; + } + } + } + + if (defined $a2) { $v2 = $a2->version; - } else { - $v2 = $a2; + + my $p1 = $a1->qualified_name; + my $p2 = $a2->qualified_name; + Carp::confess("Atoms for different packages $p1 and $p2") unless $p1 eq $p2; } ($v1, $v2) = ($v2, $v1) if $r; + return (defined $v1 or 0) <=> (defined $v2 or 0) unless defined $v1 + and defined $v2; + return $v1 <=> $v2; } @@ -215,6 +234,8 @@ sub and { shift unless length ref $_[0]; my $a1 = shift; + return $a1 unless @_; + my $a2 = shift; $a2 = $a2->and(@_) if @_;