+ 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;