1 while unlink $file;
}
} else {
- if (my @match = $self->_cpan2portage($name, $version)) {
- $stat->dist($match[1]);
+ if (my $atom = $self->_cpan2portage($name, $version)) {
+ $stat->dist($atom->ebuild);
return $SKIP->('Ebuild already generated for', $stat->distribution);
}
}
# dist.
my @requires;
for (@{$stat->requires}) {
- my $dep = $self->_cpan2portage(@$_);
- unless (defined $dep) {
+ my $atom = $self->_cpan2portage(@$_);
+ unless (defined $atom) {
$self->_abort(
"Couldn't find an appropriate ebuild for $_->[0] in the portage tree"
);
return;
}
- push @requires, $dep;
+ push @requires, $atom;
}
- @requires = do { my %seen; sort grep !$seen{$_}++, 'dev-lang/perl',@requires };
+ my $perl = CPANPLUS::Dist::Gentoo::Atom->new(
+ category => 'dev-lang',
+ name => 'perl',
+ );
+ @requires = CPANPLUS::Dist::Gentoo::Atom->fold($perl, @requires);
my $d = $stat->header;
$d .= "# Generated by CPANPLUS::Dist::Gentoo version $VERSION\n\n";
$d .= "SLOT=\"0\"\n";
$d .= 'LICENSE="|| ( ' . join(' ', sort @{$stat->license}) . " )\"\n";
$d .= 'KEYWORDS="' . join(' ', sort @{$stat->keywords}) . "\"\n";
- $d .= 'RDEPEND="' . join("\n", @requires) . "\"\n";
+ $d .= 'RDEPEND="' . join("\n", sort @requires) . "\"\n";
$d .= "DEPEND=\"\${RDEPEND}\"\n";
$d .= "SRC_TEST=\"do\"\n";
$d .= $stat->footer;
"$atom-*.ebuild",
) or next;
- my $last = reduce { $a->[1] < $b->[1] ? $b : $a }
- map [ $_, CPANPLUS::Dist::Gentoo::Atom->new(ebuild => $_) ],
- @ebuilds;
-
- my $dep;
- if (defined $ver) { # implies that $version is defined
- next if $last < $ver;
- $dep = ">=$category/$atom-$ver";
- } else {
- $dep = "$category/$atom";
- }
+ my $atom = reduce { $a < $b ? $b : $a } # handles overloading
+ map CPANPLUS::Dist::Gentoo::Atom->new(
+ ebuild => $_,
+ minimum => 1,
+ ), @ebuilds;
+ next if defined $ver and $atom < $ver;
- return wantarray ? ($dep, $last->[0]) : $dep;
+ return $atom;
}
}
}
}
+ Carp::confess('Minimum atoms require a valid version') if not defined $version
+ and $args{minimum};
+
bless {
category => $category,
name => $name,
version => $name,
+ 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 {
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->minmium) {
+ $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;