+
+ unless (defined $path) {
+ p(2, "doesn't seem to be fetching its tarball from a CPAN mirror\n");
+ p(2, colored("$pkg_name is not a CPAN distribution", 'bright_red') . "\n");
+ push @not_on_cpan, "$category/$pkg_name";
+ next;
+ }
+ p(2, "fetches $path\n");
+
+ my $dist;
+ if (defined $fqn_dist) {
+ p(2, 'is indexed on the CPAN... ');
+ $dist = do {
+ local $@;
+ eval { $pcp->distribution($fqn_dist) }
+ };
+ print defined $dist ? "yes\n" : "no\n";
+ }
+
+ unless (defined $dist) {
+ p(2, 'can directly be found on a CPAN mirror... ');
+ if (cpan_http_test($path)) {
+ print "yes\n";
+ $dist = CPAN::DistnameInfo->new($path);
+ } else {
+ print "no\n";
+ }
+ }
+
+ my ($pseudo_dist, $latest_dist);
+
+ unless (defined $dist) {
+ p(2, 'has the same name as a distribution on the CPAN... ');
+ $path =~ m{([^/\s]+)$} or die 'Could not get the last part of the path';
+ my $archive = $1;
+ $pseudo_dist = CPAN::DistnameInfo->new($archive);
+ $latest_dist = do {
+ local $@;
+ eval { $pcp->latest_distribution($pseudo_dist->dist) };
+ };
+
+ unless (defined $latest_dist) {
+ print "no\n";
+ p(2, 'is similiar to a module indexed in another distribution of the CPAN... ');
+ (my $mod_name = $pkg_name) =~ s/-/::/g;
+ $latest_dist = do {
+ local $@;
+ eval {
+ my $module = $pcp->package($mod_name);
+ defined $module ? $module->distribution : undef;
+ };
+ };
+ if (defined $latest_dist) {
+ # Re-forge the pseudo dist so that it will pick up the correct dist
+ # name when looking for a mismatch.
+ $pseudo_dist = CPAN::DistnameInfo->new(
+ $latest_dist->dist . '-' . $pseudo_dist->version
+ . '.' . $pseudo_dist->extension
+ );
+ }
+ }
+
+ my ($latest_file, $latest_author);
+ if (defined $latest_dist) {
+ $latest_file = $latest_dist->filename;
+ $latest_author = $latest_dist->cpanid;
+ printf "yes, %s by %s\n",
+ $latest_file,
+ (defined $latest_author ? $latest_author : 'unknown');
+ } else {
+ print "no\n";
+ }
+
+ if (defined $latest_author) {
+ my ($au, $a) = $latest_author =~ /^((.).)/ or die 'Author name too short';
+ p(2, 'is in that author\'s CPAN directory... ');
+ my $alternate_path = "authors/id/$a/$au/$latest_author/$archive";
+ if ($alternate_path eq $path) {
+ print "already checked\n";
+ } elsif (cpan_http_test($alternate_path)) {
+ $dist = CPAN::DistnameInfo->new($alternate_path);
+ print "yes\n";
+ } else {
+ print "no\n";
+ }
+ unless (defined $dist) {
+ push @missing,
+ "$category/$pkg_name (latest is $latest_file by $latest_author)";
+ }
+ }
+ }
+
+ unless (defined $dist) {
+ if ($latest_dist or $is_on_cpan{$pkg_name}) {
+ $dist = $pseudo_dist;
+ unless ($latest_dist) {
+ push @unfindable, "$category/$pkg_name";
+ }
+ p(2, "seems to come from the CPAN anyway\n");
+ } else {
+ p(2, colored("$pkg_name is not a CPAN distribution", 'bright_red') . "\n");
+ push @not_on_cpan, "$category/$pkg_name";
+ next;
+ }
+ }
+
+ my $dist_name = $dist->dist;
+ if ($dist_name ne $pkg_name) {
+ p(2, colored("$dist_name => $pkg_name", 'bright_yellow') . "\n");
+ $name_mismatch{$dist_name} = $pkg_name;
+ }
+
+ my $pkg_version = $atom->version . '';
+ $pkg_version =~ s/-r\d+$//;
+ my $dist_version = $dist->version;
+ my $mapped_version = CPANPLUS::Dist::Gentoo::Maps::version_c2g(
+ undef, # default conversion
+ $dist_version,
+ );
+ if ($mapped_version ne $pkg_version) {
+ my $str = "$dist_version => $mapped_version != $pkg_version";
+ p(2, colored($str, 'bright_cyan') . "\n");
+ }
+ $version{$dist_name} = [ $dist_version => $pkg_version ];