From: Vincent Pit Date: Sun, 29 Nov 2009 00:49:41 +0000 (+0100) Subject: Make 'ebuild' a normal accessor for C::D::G::Atom objects X-Git-Tag: v0.09~10 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git;a=commitdiff_plain;h=4e0c9cad73c65d6c469d35afebbef746ab15ce89 Make 'ebuild' a normal accessor for C::D::G::Atom objects Only infer the others components when C::D::G::Atom->new_from_ebuild is called. --- diff --git a/lib/CPANPLUS/Dist/Gentoo.pm b/lib/CPANPLUS/Dist/Gentoo.pm index f44b124..307d802 100644 --- a/lib/CPANPLUS/Dist/Gentoo.pm +++ b/lib/CPANPLUS/Dist/Gentoo.pm @@ -566,20 +566,17 @@ sub _cpan2portage { "$name-*.ebuild", ) or next; - my @atoms = map CPANPLUS::Dist::Gentoo::Atom->new( - defined $version ? ( - ebuild => $_, - range => '>=', - ) : ( - category => $category, - name => $name, - ), - ), @ebuilds; - - my $atom = reduce { $a < $b ? $b : $a } @atoms; # handles overloading - next if defined $version and $atom < $version; - - return $atom; + my $last = reduce { $a < $b ? $b : $a } # handles overloading + map CPANPLUS::Dist::Gentoo::Atom->new_from_ebuild($_), + @ebuilds; + next if defined $version and $last < $version; + + return CPANPLUS::Dist::Gentoo::Atom->new( + category => $last->category, + name => $last->name, + (defined $version ? (version => $version, range => '>=') : ()), + ebuild => $last->ebuild, + ); } } diff --git a/lib/CPANPLUS/Dist/Gentoo/Atom.pm b/lib/CPANPLUS/Dist/Gentoo/Atom.pm index 002b349..543693e 100644 --- a/lib/CPANPLUS/Dist/Gentoo/Atom.pm +++ b/lib/CPANPLUS/Dist/Gentoo/Atom.pm @@ -34,11 +34,6 @@ sub new { $atom =~ m{^([\w-]+)/([\w-]+)-v?($version_rx)$} or Carp::confess('Invalid atom'); ($category, $name, $version) = ($1, $2, $3); - } elsif (defined $args{ebuild}) { - my $ebuild = $args{ebuild}; - $ebuild =~ m{/([\w-]+)/([\w-]+)/\2-v?($version_rx)\.ebuild$} - or Carp::confess('Invalid ebuild'); - ($category, $name, $version) = ($1, $2, $3); } else { Carp::confess('Not enough information for building an atom object'); } @@ -72,6 +67,25 @@ sub new { }, $class; } +sub new_from_ebuild { + my $class = shift; + $class = ref($class) || $class; + + my $ebuild = shift; + $ebuild = '' unless defined $ebuild; + + $ebuild =~ m{/([\w-]+)/([\w-]+)/\2-v?($version_rx)\.ebuild$} + or Carp::confess('Invalid ebuild'); + my ($category, $name, $version) = ($1, $2, $3); + + return $class->new( + category => $category, + name => $name, + version => $version, + ebuild => $ebuild, + ); +} + BEGIN { eval "sub $_ { \$_[0]->{$_} }" for qw/category name version range ebuild/; }