--- /tmp/perl/lib/5.36.0/App/Cpan.pm.orig 2022-08-13 12:53:22.319462035 -0700 +++ /tmp/perl/lib/5.36.0/App/Cpan.pm 2022-08-13 21:57:29.958128351 -0700 @@ -1171,22 +1171,38 @@ local $CPAN::DEBUG = 1; + my $status = HEY_IT_WORKED; my %paths; foreach my $arg ( @$args ) { $logger->info( "Checking $arg" ); - my $module = _expand_module( $arg ) or next; - my $path = $module->cpan_file; + my $module = _expand_module( $arg ) or do { + $status = ITS_NOT_MY_FAULT; + next; + }; + ## Accommodate a pinned version, not just downloading the latest. + ## In that case, we get back a CPAN::Distribution object, not a + ## CPAN::Module object. Perhaps referring to its field directly + ## is not wonderful, but it seems to be the best we an do for now. + ## Handling a pinned version might not work for a call of _download() + ## from _gitify(), but addressing that awaits another day. + my $path = $arg =~ m{/} ? $module->{ID} : $module->cpan_file; $logger->debug( "Inst file would be $path\n" ); - $paths{$module} = _get_file( _make_path( $path ) ); - - $logger->info( "Downloaded [$arg] to [$paths{$arg}]" ); + my $file_path = _get_file( _make_path( $path ) ); + if (defined $file_path) { + $paths{$module} = $file_path; + $logger->info( "Downloaded [$arg] to [$paths{$module}]" ); + } + else { + $logger->error( "Could not download [$arg]" ); + $status = ITS_NOT_MY_FAULT; + } } - return \%paths; + return (wantarray ? ($status, \%paths) : $status); } sub _make_path { join "/", qw(authors id), $_[0] } @@ -1203,16 +1219,23 @@ my $store_path = catfile( cwd(), $file ); $logger->debug( "Store path is $store_path" ); + my $status = ITS_NOT_MY_FAULT; foreach my $site ( @{ $CPAN::Config->{urllist} } ) { my $fetch_path = join "/", $site, $path; $logger->debug( "Trying $fetch_path" ); my $status_code = LWP::Simple::getstore( $fetch_path, $store_path ); - last if( 200 <= $status_code and $status_code <= 300 ); + if( 200 <= $status_code and $status_code < 300 ) { + $status = HEY_IT_WORKED; + last; + } $logger->warn( "Could not get [$fetch_path]: Status code $status_code" ); + if ( $fetch_path =~ m{https:}i && ! _safe_load_module("LWP::Protocol::https") ) { + croak "You need LWP::Protocol::https to fetch files from CPAN.\n"; + } } - return $store_path; + return ($status == HEY_IT_WORKED ? $store_path : undef); } sub _gitify @@ -1228,7 +1251,10 @@ foreach my $arg ( @$args ) { $logger->info( "Checking $arg" ); - my $store_paths = _download( [ $arg ] ); + my ($status, $store_paths) = _download( [ $arg ] ); + if ($status != HEY_IT_WORKED) { + next; + } $logger->debug( "gitify Store path is $store_paths->{$arg}" ); my $dirname = dirname( $store_paths->{$arg} );