X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FCPANPLUS%2FDist%2FGentoo%2FAtom.pm;h=eef7cff2efc7d04c848985d2c199dc1113e4246f;hb=19eae8789c3ed2068bfde084ba9a8c711526c589;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..eef7cff 100644 --- a/lib/CPANPLUS/Dist/Gentoo/Atom.pm +++ b/lib/CPANPLUS/Dist/Gentoo/Atom.pm @@ -9,11 +9,11 @@ CPANPLUS::Dist::Gentoo::Atom - Gentoo atom object. =head1 VERSION -Version 0.10 +Version 0.12 =cut -our $VERSION = '0.10'; +our $VERSION = '0.12'; =head1 DESCRIPTION @@ -39,7 +39,24 @@ my $version_rx = $CPANPLUS::Dist::Gentoo::Version::version_rx; =head1 METHODS -=head2 C<< new category => $category, name => $name [, version => $version, range => $range, ebuild => $ebuild ] >> +=head2 C + + # Infer everything from $atom : + my $cdga = CPANPLUS::Dist::Gentoo::Atom->new( + atom => $atom, + # Optional : + ebuild => $ebuild, + ); + + # Or specify the attributes manually : + my $cdga = CPANPLUS::Dist::Gentoo::Atom->new( + category => $category, + name => $name, + version => $version, + range => $range, + # Optional : + ebuild => $ebuild, + ); Creates a new L object from the supplied C<$category>, C<$name>, C<$version>, C<$range> and C<$ebuild>. @@ -53,13 +70,13 @@ sub new { my ($range, $category, $name, $version); if (defined $args{name}) { - ($range, $category, $name, $version) = @args{qw/range category name version/}; + ($range, $category, $name, $version) = @args{qw}; Carp::confess('Category unspecified') unless defined $category; Carp::confess('Invalid category') unless $category =~ /^$category_rx$/o; 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 { @@ -68,7 +85,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); } } @@ -93,7 +110,9 @@ sub new { }, $class; } -=head2 C +=head2 C + + my $cdga = CPANPLUS::Dist::Gentoo::Atom->new_from_ebuild($ebuild); Creates a new L object by inferring the category, name and version from the given C<$ebuild> @@ -106,7 +125,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); @@ -119,7 +138,7 @@ sub new_from_ebuild { } BEGIN { - eval "sub $_ { \$_[0]->{$_} }" for qw/category name version range ebuild/; + eval "sub $_ { \$_[0]->{$_} }" for qw; } =head2 C @@ -192,20 +211,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 { @@ -227,7 +247,9 @@ my %order = ( '>' => 2, ); -=head2 C +=head2 C + + my $cdga = CPANPLUS::Dist::Gentoo::Atom->and(@atoms); Compute the ranged atom representing the logical AND between C<@atoms> with the same category and name. @@ -277,7 +299,9 @@ sub and { } } -=head2 C +=head2 C + + my @folded = CPANPLUS::Dist::Gentoo::Atom->fold(@atoms); Returns a list built from C<@atoms> but where there's only one atom for a given category and name. @@ -294,12 +318,12 @@ sub fold { $seen{$key} = defined $cur ? $cur->and($atom) : $atom; } - return values %seen; + return map $seen{$_}, sort keys %seen; } =pod -This class provides overloaded methods for numerical comparison, string comparison and strigification. +This class provides overloaded methods for numerical comparison, string comparison and stringification. =head1 SEE ALSO @@ -324,7 +348,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.