diff options
-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; |