You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jm...@apache.org on 2004/01/31 05:00:19 UTC

svn commit: rev 6374 - incubator/spamassassin/trunk/lib/Mail/SpamAssassin

Author: jm
Date: Fri Jan 30 20:00:18 2004
New Revision: 6374

Modified:
   incubator/spamassassin/trunk/lib/Mail/SpamAssassin/DBBasedAddrList.pm
   incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm
Log:
bug 1642: remove use of AnyDBM_File, since it pollutes the global namespace

Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin/DBBasedAddrList.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin/DBBasedAddrList.pm	(original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin/DBBasedAddrList.pm	Fri Jan 30 20:00:18 2004
@@ -20,12 +20,6 @@
 use bytes;
 use Fcntl;
 
-# tell AnyDBM_File to prefer DB_File, if possible.
-# BEGIN { @AnyDBM_File::ISA = qw(DB_File GDBM_File NDBM_File SDBM_File); }
-# off until 3.0; there's lots of existing AWLs out there this breaks.
-
-use AnyDBM_File;
-
 use Mail::SpamAssassin::PersistentAddrList;
 use Mail::SpamAssassin::Util;
 
@@ -61,6 +55,9 @@
 
   my $path;
 
+  my $dbm_module = Mail::SpamAssassin::Util::first_available_module
+			(qw(DB_File GDBM_File NDBM_File SDBM_File));
+
   my $umask = umask 0;
   if(defined($main->{conf}->{auto_whitelist_path})) # if undef then don't worry -- empty hash!
   {
@@ -72,7 +69,7 @@
       $self->{locked_file} = $path;
       $self->{is_locked} = 1;
       dbg("Tie-ing to DB file R/W in $path");
-      tie %{$self->{accum}},"AnyDBM_File",$path,
+      tie %{$self->{accum}},$dbm_module,$path,
 		  O_RDWR|O_CREAT,   #open rw w/lock
 		  (oct ($main->{conf}->{auto_whitelist_file_mode}) & 0666)
 	 or goto failed_to_tie;
@@ -80,7 +77,7 @@
     } else {
       $self->{is_locked} = 0;
       dbg("Tie-ing to DB file R/O in $path");
-      tie %{$self->{accum}},"AnyDBM_File",$path,
+      tie %{$self->{accum}},$dbm_module,$path,
 		  O_RDONLY,         #open ro w/o lock
 		  (oct ($main->{conf}->{auto_whitelist_file_mode}) & 0666)
 	 or goto failed_to_tie;

Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm	(original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm	Fri Jan 30 20:00:18 2004
@@ -628,6 +628,34 @@
 
 ###########################################################################
 
+=item $module = first_available_module (@module_list)
+
+Return the first module that can be successfully loaded with C<require>
+from the list.  Returns C<undef> if none are available.
+
+Used to replace C<AnyDBM_File>, like so:
+
+  my $module = Mail::SpamAssassin::Util::first_available_module
+                        (qw(DB_File GDBM_File NDBM_File SDBM_File));
+  tie %hash, $module, $path, [... args];
+
+Note that C<SDBM_File> is guaranteed to be present, since it comes
+with Perl.
+
+=cut
+
+sub first_available_module {
+  my (@packages) = @_;
+  foreach my $mod (@packages) {
+    if (eval 'require '.$mod.'; 1; ') {
+      return $mod;
+    }
+  }
+  undef;
+}
+
+###########################################################################
+
 # thanks to http://www2.picante.com:81/~gtaylor/autobuse/ for this
 # code.
 sub secure_tmpfile {