From 4b98cdfb1e5e71593daed29f54d9238afab26080 Mon Sep 17 00:00:00 2001 From: purofle Date: Wed, 13 May 2026 20:33:52 +0800 Subject: [PATCH 1/2] refactor: replace external sha256sum with Digest::SHA Signed-off-by: purofle --- README.md | 1 + cpan2spec | 17 ++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6233c55..35f221a 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,4 @@ Please install these modules first (You can use `cpanm`): - YAML - LWP::UserAgent - Parse::CPAN::Packages + - Digest::SHA \ No newline at end of file diff --git a/cpan2spec b/cpan2spec index 017d00e..6d508c4 100755 --- a/cpan2spec +++ b/cpan2spec @@ -217,6 +217,7 @@ use File::Basename; use LWP::UserAgent; use Parse::CPAN::Packages; use Pod::Simple::TextContent; +use Digest::SHA; # Apparently gets pulled in by another module. #use Cwd; @@ -568,18 +569,16 @@ sub get_sha256($) { return "0" x 64 if (!-f $file); - my @output=`sha256sum "$file" 2>/dev/null`; + open my $fh, '<', $file + or die "Can't open $file: $!\n"; - if ($? != 0) { - warn "Failed to calculate SHA256 for $file: $!\n"; - return "0" x 64; - } + binmode $fh; - if (@output && $output[0] =~ /^([a-f0-9]{64})\s+/) { - return $1; - } + my $sha256 = Digest::SHA->new(256) + ->addfile($fh) + ->hexdigest; - return "0" x 64; + return $sha256 || ("0" x 64); } From ebf303dfc20342db4c4dd9f51f8535a57e1bb415 Mon Sep 17 00:00:00 2001 From: purofle Date: Wed, 13 May 2026 20:36:09 +0800 Subject: [PATCH 2/2] refactor: Use HTTPS instead of HTTP Signed-off-by: purofle --- README.md | 1 + cpan2spec | 2 +- cpanget | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 35f221a..77d38fd 100644 --- a/README.md +++ b/README.md @@ -6,5 +6,6 @@ Please install these modules first (You can use `cpanm`): - Text::Autoformat - YAML - LWP::UserAgent + - LWP::Protocol::https - Parse::CPAN::Packages - Digest::SHA \ No newline at end of file diff --git a/cpan2spec b/cpan2spec index 6d508c4..12399e8 100755 --- a/cpan2spec +++ b/cpan2spec @@ -241,7 +241,7 @@ our $outdir='library-perl'; # default output dir our $cleanup_source=1; # default: remove downloaded source archives our $skip_postprocess=0; # default: enable spec post-processing our $source; -our $cpan=$ENV{'CPAN'} || "http://www.cpan.org"; +our $cpan=$ENV{'CPAN'} || "https://www.cpan.org"; our $home=$ENV{'HOME'} || (getpwuid($<))[7]; die "Can't locate home directory. Please define \$HOME.\n" diff --git a/cpanget b/cpanget index 936643f..ce8b24e 100755 --- a/cpanget +++ b/cpanget @@ -2,7 +2,7 @@ set -e -CPAN=${CPAN:-"http://www.cpan.org"} +CPAN=${CPAN:-"https://www.cpan.org"} packages=$HOME/.cpan/sources/modules/02packages.details.txt.gz quiet=''