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

Mike Heins <[email protected]>
Newsgroups gmane.comp.web.interchange.cvs
Message-ID <[email protected]>
commit 9d4d173654b505e6aa96f9cc3246f491e5a588c6
Author: Mike Heins <[email protected]>
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(! $@) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.