X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FCPANPLUS%2FDist%2FGentoo%2FAtom.pm;h=ebe6a4e64d8e393c58c5af2ae3c7d6608becf8d0;hb=9c0162fc729f9b0cc7bff16ef1c4aa07cf9c2ab9;hp=b017e6be25be43e6e26014ab7ac07dc04621ac63;hpb=00e09b5e966914ebedb5c08927cf5a66af177171;p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git diff --git a/lib/CPANPLUS/Dist/Gentoo/Atom.pm b/lib/CPANPLUS/Dist/Gentoo/Atom.pm index b017e6b..ebe6a4e 100644 --- a/lib/CPANPLUS/Dist/Gentoo/Atom.pm +++ b/lib/CPANPLUS/Dist/Gentoo/Atom.pm @@ -23,21 +23,21 @@ sub new { my %args = @_; - my ($name, $category, $version); + my ($category, $name, $version); if (defined $args{name}) { - ($name, $category, $version) = @args{qw/name category version/}; + ($category, $name, $version) = @args{qw/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)$} or Carp::confess('Invalid atom'); - ($name, $category, $version) = ($1, $2, $3); + ($category, $name, $version) = ($1, $2, $3); } elsif (defined $args{ebuild}) { my $ebuild = $args{ebuild}; - $ebuild =~ m{/([\w-]+)/([\w-]+)-v?($version_rx)\.ebuild$} + $ebuild =~ m{/([\w-]+)/([\w-]+)/\2-v?($version_rx)\.ebuild$} or Carp::confess('Invalid ebuild'); - ($name, $category, $version) = ($1, $2, $3); + ($category, $name, $version) = ($1, $2, $3); } else { Carp::confess('Not enough information for building an atom object'); } @@ -49,15 +49,20 @@ sub new { } } + Carp::confess('Minimum atoms require a valid version') if not defined $version + and $args{minimum}; + bless { category => $category, name => $name, - version => $name, + version => $version, + minimum => $args{minimum}, + ebuild => $args{ebuild}, }, $class; } BEGIN { - eval "sub $_ { \$_[0]->{$_} }" for qw/category name version/; + eval "sub $_ { \$_[0]->{$_} }" for qw/category name version minimum ebuild/; } sub cmp { @@ -82,7 +87,50 @@ sub cmp { sub as_string { my ($a) = @_; - $a->category . '/' . $a->name . '-' . $a->version; + my $atom = $a->category . '/' . $a->name; + + my $version = $a->version; + if (defined $version) { + $atom = "=$atom-$version"; + $atom = ">$atom" if $a->minimum; + } + + return $atom; +} + +sub fold { + shift unless length ref $_[0]; + + my %seen; + for my $atom (@_) { + my ($category, $name, $version) = map $atom->$_, qw/category name version/; + my $key = join '/', $category, $name; + my $cur = $seen{$key}; + + unless (defined $cur) { + $seen{$key} = $atom; + next; + } + + next unless defined $version; + + if (not defined $cur->version) { + $seen{$key} = $atom; + next; + } + + if ($atom->minimum) { + if ($cur->minimum) { + $seen{$key} = $atom < $cur ? $cur : $atom; + } else { + Carp::confess('Version mismatch') if $atom > $cur; + } + } elsif ($cur->minimum) { + Carp::confess('Version mismatch') if $cur > $atom; + } + } + + return values %seen; } 1;