aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-08-10 15:41:56 +1200
committerTom Ryder <tom@sanctum.geek.nz>2017-08-10 15:41:56 +1200
commit54c39e710db43a46ef328119b6311004d2938aa3 (patch)
treea52d4aa4445299e263d07e33a9dbbaa366f961de
parentExplain version support (diff)
downloadcheckem-54c39e710db43a46ef328119b6311004d2938aa3.tar.gz
checkem-54c39e710db43a46ef328119b6311004d2938aa3.zip
Try to gracefully handle absence of Digest::SHA
-rwxr-xr-xcheckem24
1 files changed, 17 insertions, 7 deletions
diff --git a/checkem b/checkem
index f64044a..8b0d7f4 100755
--- a/checkem
+++ b/checkem
@@ -42,13 +42,23 @@ my %STATS = (
size => 7,
);
-# Create a digest object; defaults to SHA-256, but can be overriden by setting
-# CHECKEM_ALG in the environment
-my $dig = Digest->new(
- exists $ENV{CHECKEM_ALG}
- ? $ENV{CHECKEM_ALG}
- : 'SHA-256',
-);
+# Create a digest object, trying to safely detect ancient Perl (5.6)
+# installations, or others that are bereft of Digest::SHA, in order
+# to pick the algorithm. It can be foced with the CHECKEM_ALG environment
+# variable.
+my $dig = do {
+ my $alg;
+ if ( exists $ENV{CHECKEM_ALG} ) {
+ $alg = $ENV{CHECKEM_ALG};
+ }
+ elsif ( eval { require Digest::SHA; } ) {
+ $alg = 'SHA-1';
+ }
+ else {
+ $alg = 'MD5';
+ }
+ Digest->new($alg);
+};
# Start a hash of filesizes to file names/stats...
my %sizes;