X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git;a=blobdiff_plain;f=lib%2FCPANPLUS%2FDist%2FGentoo%2FAtom.pm;h=bbb6d882ff6df607c05fb28b4d1e04ad11bd11cf;hp=5cd01e3b3aa3f376a17f244079a1d3b8274ee46f;hb=35a371dbbbb9ba8cd3d67c4b1763a93ac0572006;hpb=5bb7f214348c0e45363adc5cf51d479a240a7c49 diff --git a/lib/CPANPLUS/Dist/Gentoo/Atom.pm b/lib/CPANPLUS/Dist/Gentoo/Atom.pm index 5cd01e3..bbb6d88 100644 --- a/lib/CPANPLUS/Dist/Gentoo/Atom.pm +++ b/lib/CPANPLUS/Dist/Gentoo/Atom.pm @@ -5,15 +5,15 @@ use warnings; =head1 NAME -CPANPLUS::Dist::Gentoo::Version - Gentoo atom object. +CPANPLUS::Dist::Gentoo::Atom - Gentoo atom object. =head1 VERSION -Version 0.08 +Version 0.10 =cut -our $VERSION = '0.08'; +our $VERSION = '0.10'; =head1 DESCRIPTION @@ -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,13 +69,12 @@ sub new { } } - my $range = $args{range}; if (defined $version) { if (defined $range) { Carp::confess("Invalid range $range") unless grep $range eq $_, qw|< <= = >= >|; } else { - $range = '='; + $range = '>='; } } else { Carp::confess('Range atoms require a valid version') @@ -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; } @@ -291,7 +310,8 @@ You can contact me by mail or on C (vincent). =head1 BUGS -Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. +Please report any bugs or feature requests to C, or through the web interface at L. +I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT @@ -301,7 +321,7 @@ You can find documentation for this module with the perldoc command. =head1 COPYRIGHT & LICENSE -Copyright 2009 Vincent Pit, all rights reserved. +Copyright 2009,2010 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.