aboutsummaryrefslogtreecommitdiff
path: root/checkem
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-08-10 15:58:44 +1200
committerTom Ryder <tom@sanctum.geek.nz>2017-08-10 15:58:44 +1200
commit1c3f274ae8f030a7bd0eee0c453e4577d034e4bf (patch)
tree8dc4d64432002adc27412287c77b07524e4e0bca /checkem
parentRe-clarify module support (diff)
downloadcheckem-1c3f274ae8f030a7bd0eee0c453e4577d034e4bf.tar.gz
checkem-1c3f274ae8f030a7bd0eee0c453e4577d034e4bf.zip
Better approach to finding an algorithm
Diffstat (limited to 'checkem')
-rwxr-xr-xcheckem34
1 files changed, 18 insertions, 16 deletions
diff --git a/checkem b/checkem
index 7afcdbb..1df8fb6 100755
--- a/checkem
+++ b/checkem
@@ -42,23 +42,25 @@ my %STATS = (
size => 7,
);
-# 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';
+# We need to pick and create a Digest object
+my $dig;
+
+# We were told which algorithm to use
+if ( exists $ENV{CHECKEM_ALG} ) {
+ $dig = Digest->new( $ENV{CHECKEM_ALG} );
+}
+
+# Try worse and worse algorithms until we get a digest object
+else {
+ ALG: for my $alg (qw(SHA-256 SHA-1 MD5)) {
+ next ALG if not eval { $dig = Digest->new($alg); };
}
- Digest->new($alg);
-};
+}
+
+# Still no digest object, give up
+if ( !defined $dig ) {
+ croak 'Could not create a useable Digest object';
+}
# Start a hash of filesizes to file names/stats...
my %sizes;