+
+ 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 ];
+ }
+ }
+}
+
+my $already_parsed = 0;
+
+if (-e STATE_FILE) {
+ my $state = Storable::retrieve(STATE_FILE);
+ if ($state->[0] == $timestamp) {
+ printf "State retrieved from %s\n", STATE_FILE;
+ @not_on_cpan = @{ $state->[1] };
+ @unfindable = @{ $state->[2] };
+ @missing = @{ $state->[3] };
+ %name_mismatch = %{ $state->[4] };
+ %version = %{ $state->[5] };
+ $already_parsed = 1;
+ } else {
+ printf "Obsolete state file %s, regenerating\n", STATE_FILE;
+ 1 while unlink STATE_FILE;
+ }
+}
+
+unless ($already_parsed) {
+ if (-e DATA_FILE) {
+ my $data = Storable::retrieve(DATA_FILE);
+ if ($data->[0] == $timestamp) {
+ printf "Data retrieved from %s\n", DATA_FILE;
+ %fetched_uri = %{ $data->[1] };
+ } else {
+ printf "Obsolete data file %s, regenerating\n", DATA_FILE;
+ 1 while unlink DATA_FILE;