diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-08-10 15:41:56 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-08-10 15:41:56 +1200 |
commit | 54c39e710db43a46ef328119b6311004d2938aa3 (patch) | |
tree | a52d4aa4445299e263d07e33a9dbbaa366f961de /checkem | |
parent | Explain version support (diff) | |
download | checkem-54c39e710db43a46ef328119b6311004d2938aa3.tar.gz checkem-54c39e710db43a46ef328119b6311004d2938aa3.zip |
Try to gracefully handle absence of Digest::SHA
Diffstat (limited to 'checkem')
-rwxr-xr-x | checkem | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -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; |