]> git.vpit.fr Git - perl/modules/CPANPLUS-Dist-Gentoo.git/blobdiff - lib/CPANPLUS/Dist/Gentoo/Atom.pm
Strip duplicated entries in the RDEPEND list
[perl/modules/CPANPLUS-Dist-Gentoo.git] / lib / CPANPLUS / Dist / Gentoo / Atom.pm
index b017e6be25be43e6e26014ab7ac07dc04621ac63..45a68c5b90ff08b05c92b5c13d7da886e204cbb0 100644 (file)
@@ -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,
+  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->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;