"$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,
+ );
}
}
$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');
}
}, $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/;
}