t/12-maps-version.t
t/13-maps-license.t
t/20-version.t
+t/31-atom-and.t
t/91-pod.t
t/92-pod-coverage.t
t/95-portability-files.t
sub _cpan2portage {
my ($self, $name, $version) = @_;
- $name = CPANPLUS::Dist::Gentoo::Maps::name_c2g($name);
- my $ver;
- $ver = CPANPLUS::Dist::Gentoo::Maps::version_c2g($version) if defined $version;
+ $name = CPANPLUS::Dist::Gentoo::Maps::name_c2g($name);
+ $version = CPANPLUS::Dist::Gentoo::Maps::version_c2g($version);
my @portdirs = ($main_portdir, @{$self->status->portdir_overlay});
for my $category (qw/virtual perl-core dev-perl perl-gcpan/, CATEGORY) {
- my $atom = ($category eq 'virtual' ? 'perl-' : '') . $name;
+ my $name = ($category eq 'virtual' ? 'perl-' : '') . $name;
for my $portdir (@portdirs) {
my @ebuilds = glob File::Spec->catfile(
$portdir,
$category,
- $atom,
- "$atom-*.ebuild",
+ $name,
+ "$name-*.ebuild",
) or next;
- 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;
+ 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;
}
}
}
- Carp::confess('Minimum atoms require a valid version') if not defined $version
- and $args{minimum};
+ my $range = $args{range};
+ if (defined $version) {
+ if (defined $range) {
+ Carp::confess("Invalid range $range")
+ unless grep $range eq $_, qw|< <= = >= >|;
+ } else {
+ $range = '=';
+ }
+ } else {
+ Carp::confess('Range atoms require a valid version')
+ if defined $range and length $range;
+ }
bless {
category => $category,
name => $name,
version => $version,
- minimum => $args{minimum},
+ range => $range,
ebuild => $args{ebuild},
}, $class;
}
BEGIN {
- eval "sub $_ { \$_[0]->{$_} }" for qw/category name version minimum ebuild/;
+ eval "sub $_ { \$_[0]->{$_} }" for qw/category name version range ebuild/;
}
sub cmp {
my $atom = $a->category . '/' . $a->name;
my $version = $a->version;
- if (defined $version) {
- $atom = "=$atom-$version";
- $atom = ">$atom" if $a->minimum;
- }
+ $atom = $a->range . $atom . '-' . $version if defined $version;
return $atom;
}
-sub fold {
+my %order = (
+ '<' => -2,
+ '<=' => -1,
+ '=' => 0,
+ '>=' => 1,
+ '>' => 2,
+);
+
+sub and {
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};
+ my $a1 = shift;
+ my $a2 = shift;
+ $a2 = $a2->and(@_) if @_;
- unless (defined $cur) {
- $seen{$key} = $atom;
- next;
- }
+ my $p1 = join '/', $a1->category, $a1->name;
+ my $p2 = join '/', $a2->category, $a2->name;
+ Carp::confess("Atoms for different packages $p1 and $p2") unless $p1 eq $p2;
- next unless defined $version;
+ my $v1 = $a1->version;
+ return $a2 unless defined $v1;
+ my $r1 = $a1->range; # Defined if $v1 is defined
- if (not defined $cur->version) {
- $seen{$key} = $atom;
- next;
- }
+ my $v2 = $a2->version;
+ return $a1 unless defined $v2;
+ my $r2 = $a2->range; # defined if $v2 is defined
- 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;
- }
+ my $o1 = $order{$r1};
+ my $o2 = $order{$r2};
+
+ Carp::confess("Incompatible ranges $r1$p1 and $r2$p2") if $o1 * $o2 < 0;
+
+ if ($r2 eq '=') {
+ ($a1, $a2) = ($a2, $a1);
+ ($v1, $v2) = ($v2, $v1);
+ ($r1, $r2) = ($r2, $r1);
+ ($o1, $o2) = ($o2, $o1);
+ }
+
+ if ($r1 eq '=') {
+ my $r = $r2 eq '=' ? '==' : $r2;
+ Carp::confess("Version mismatch $v1 $r $v2") unless eval "\$a1 $r \$a2";
+ return $a1;
+ } elsif ($o1 > 0) {
+ return $a1 < $a2 ? $a2 : $a1;
+ } else {
+ return $a1 < $a2 ? $a1 : $a2;
+ }
+}
+
+sub fold {
+ shift unless length ref $_[0];
+
+ my %seen;
+ for my $atom (@_) {
+ my $key = join '/', $atom->category, $atom->name;
+
+ my $cur = $seen{$key};
+ $seen{$key} = defined $cur ? $cur->and($atom) : $atom;
}
return values %seen;
--- /dev/null
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 2 * ((8 * 7) / 2 + 2);
+
+use CPANPLUS::Dist::Gentoo::Atom;
+
+sub A () { 'CPANPLUS::Dist::Gentoo::Atom' }
+
+my $a0 = A->new(
+ category => 'test',
+ name => 'a',
+);
+
+my $a1 = A->new(
+ category => 'test',
+ name => 'a',
+ version => '1.0',
+ range => '=',
+);
+
+my $a2 = A->new(
+ category => 'test',
+ name => 'a',
+ version => '1.0',
+ range => '<',
+);
+
+my $a3 = A->new(
+ category => 'test',
+ name => 'a',
+ version => '1.0',
+ range => '<=',
+);
+
+my $a4 = A->new(
+ category => 'test',
+ name => 'a',
+ version => '2.0',
+ range => '=',
+);
+
+my $a5 = A->new(
+ category => 'test',
+ name => 'a',
+ version => '2.0',
+ range => '>=',
+);
+
+my $a6 = A->new(
+ category => 'test',
+ name => 'a',
+ version => '2.0',
+ range => '>',
+);
+
+my $x_ver = qr/Version mismatch/;
+my $x_range = qr/Incompatible ranges/;
+
+my @tests = (
+ [ [ $a0, $a0 ] => $a0 ],
+ [ [ $a0, $a1 ] => $a1 ],
+ [ [ $a0, $a2 ] => $a2 ],
+ [ [ $a0, $a3 ] => $a3 ],
+ [ [ $a0, $a4 ] => $a4 ],
+ [ [ $a0, $a5 ] => $a5 ],
+ [ [ $a0, $a6 ] => $a6 ],
+
+ [ [ $a1, $a1 ] => $a1 ],
+ [ [ $a1, $a2 ] => $x_ver ],
+ [ [ $a1, $a3 ] => $a1 ],
+ [ [ $a1, $a4 ] => $x_ver ],
+ [ [ $a1, $a5 ] => $x_ver ],
+ [ [ $a1, $a6 ] => $x_ver ],
+
+ [ [ $a2, $a2 ] => $a2 ],
+ [ [ $a2, $a3 ] => $a2 ],
+ [ [ $a2, $a4 ] => $x_ver ],
+ [ [ $a2, $a5 ] => $x_range ],
+ [ [ $a2, $a5 ] => $x_range ],
+
+ [ [ $a3, $a3 ] => $a3 ],
+ [ [ $a3, $a4 ] => $a4 ],
+ [ [ $a3, $a5 ] => $x_range ],
+ [ [ $a3, $a6 ] => $x_range ],
+
+ [ [ $a4, $a4 ] => $a4 ],
+ [ [ $a4, $a5 ] => $a4 ],
+ [ [ $a4, $a6 ] => $x_ver ],
+
+ [ [ $a5, $a5 ] => $a5 ],
+ [ [ $a5, $a6 ] => $a6 ],
+
+ [ [ $a6, $a6 ] => $a6 ],
+
+ [ [ ($a1) x 3 ] => $a1 ],
+ [ [ ($a2) x 4 ] => $a2 ],
+);
+
+for my $t (@tests) {
+ my ($args, $exp) = @$t;
+
+ for my $r (0 .. 1) {
+ my @a = @$args;
+ @a = reverse @a if $r;
+
+ my $desc = join ' AND ', map "'$_'", @a;
+
+ my $a = eval { A->and(@a) };
+ my $err = $@;
+
+ if (ref $exp eq 'Regexp') {
+ like $err, $exp, "$desc should fail";
+ } else {
+ cmp_ok $a, '==', $exp, "$desc == '$exp'";
+ }
+ }
+}