1 package CPANPLUS::Dist::Gentoo::Atom;
16 use CPANPLUS::Dist::Gentoo::Version;
18 my $version_rx = $CPANPLUS::Dist::Gentoo::Version::version_rx;
22 $class = ref($class) || $class;
26 my ($name, $category, $version);
27 if (defined $args{name}) {
28 ($name, $category, $version) = @args{qw/name category version/};
29 Carp::confess('Category unspecified') unless defined $category;
30 /[^\w-]/ and Carp::confess('Invalid argument') for $name, $category;
31 } elsif (defined $args{atom}) {
32 my $atom = $args{atom};
33 $atom =~ m{^([\w-]+)/([\w-]+)-v?($version_rx)$}
34 or Carp::confess('Invalid atom');
35 ($name, $category, $version) = ($1, $2, $3);
36 } elsif (defined $args{ebuild}) {
37 my $ebuild = $args{ebuild};
38 $ebuild =~ m{/([\w-]+)/([\w-]+)-v?($version_rx)\.ebuild$}
39 or Carp::confess('Invalid ebuild');
40 ($name, $category, $version) = ($1, $2, $3);
42 Carp::confess('Not enough information for building an atom object');
45 if (defined $version) {
46 unless (Scalar::Util::blessed($version)
47 and $_->isa('CPANPLUS::Dist::Gentoo::Version')) {
48 $version = CPANPLUS::Dist::Gentoo::Version->new($version);
52 Carp::confess('Minimum atoms require a valid version') if not defined $version
56 category => $category,
59 minimum => $args{minimum},
60 ebuild => $args{ebuild},
65 eval "sub $_ { \$_[0]->{$_} }" for qw/category name version minimum ebuild/;
69 my ($a1, $a2, $r) = @_;
71 my $v1 = $a1->version;
74 if (Scalar::Util::blessed($a2) and $a2->isa(__PACKAGE__)) {
75 Carp::confess('Can\'t compare atoms of different packages')
76 if $a1->category ne $a2->category or $a1->name ne $a2->name;
82 ($v1, $v2) = ($v2, $v1) if $r;
90 my $atom = $a->category . '/' . $a->name;
92 my $version = $a->version;
93 if (defined $version) {
94 $atom = "=$atom-$version";
95 $atom = ">$atom" if $a->minimum;
102 shift unless length ref $_[0];
106 my ($category, $name, $version) = map $atom->$_, qw/category name version/;
107 my $key = join '/', $category, $name;
108 my $cur = $seen{$key};
110 unless (defined $cur) {
115 next unless defined $version;
117 if (not defined $cur->version) {
122 if ($atom->minimum) {
124 $seen{$key} = $atom < $cur ? $cur : $atom;
126 Carp::confess('Version mismatch') if $atom > $cur;
128 } elsif ($cur->minimum) {
129 Carp::confess('Version mismatch') if $cur > $atom;