[interchange] * Add routine that selects sha1_hex filter routine based on which

Mike Heins interchange-cvs at icdevgroup.org
Fri Jul 12 12:23:52 UTC 2013


commit 9d4d173654b505e6aa96f9cc3246f491e5a588c6
Author: Mike Heins <heins at icdevgroup.com>
Date:   Fri Jul 12 08:22:42 2013 -0400

    * Add routine that selects sha1_hex filter routine based on which
      module you have. Modify sha1 filter to use this.
    
      New globally available routine &Vend::Util::sha1_hex.

 code/Filter/sha1.filter |    6 +-----
 lib/Vend/Util.pm        |   22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 5 deletions(-)
---
diff --git a/code/Filter/sha1.filter b/code/Filter/sha1.filter
index acb5df6..c651575 100644
--- a/code/Filter/sha1.filter
+++ b/code/Filter/sha1.filter
@@ -5,15 +5,11 @@
 # the Free Software Foundation; either version 2 of the License, or
 # (at your option) any later version. See the LICENSE file for details.
 
-Require module Digest::SHA
-
 CodeDef sha1 Filter
 CodeDef sha1 Description sha1 sum
 CodeDef sha1 Routine <<EOR
 
-use Digest::SHA;
-
 sub {
-	return Digest::SHA::sha1_hex($_[0]);
+	return Vend::Util::sha1_hex($_[0]);
 }
 EOR
diff --git a/lib/Vend/Util.pm b/lib/Vend/Util.pm
index 78099a1..a69aeb4 100644
--- a/lib/Vend/Util.pm
+++ b/lib/Vend/Util.pm
@@ -577,6 +577,28 @@ sub random_string {
 my $Md;
 my $Keysub;
 
+use vars qw($SHA1);
+
+##  This block defines &Vend::Util::sha1_hex and $Vend::Util::SHA1
+BEGIN {
+
+	$SHA1 = 1;
+	  FINDSHA: {
+		eval {
+			require Digest::SHA;
+			*sha1_hex = \&Digest::SHA::sha1_hex;
+		};
+		last FINDSHA if defined &sha1_hex;
+		eval {
+			require Digest::SHA1;
+			*sha1_hex = \&Digest::SHA1::sha1_hex;
+		};
+		last FINDSHA if defined &sha1_hex;
+		$SHA1 = 0;
+		*sha1_hex = sub { ::logError("Unknown filter or key routine sha1, no SHA modules."); return $_[0] };
+	  }
+}
+
 eval {require Digest::MD5 };
 
 if(! $@) {



More information about the interchange-cvs mailing list