CVS: brutus/elaine find.pl,1.1,1.2

elaine at lunar-linux.org elaine at lunar-linux.org
Thu Aug 21 20:53:35 GMT 2003


Update of /var/cvs/lunar/brutus/elaine
In directory dbguin.lunar-linux.org:/tmp/cvs-serv7378

Modified Files:
	find.pl 
Log Message:
added SQL (mysql, but changing backends is trivial), backend, kludgy, but 
demos a simple backend design


Index: find.pl
===================================================================
RCS file: /var/cvs/lunar/brutus/elaine/find.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- find.pl	21 Aug 2003 03:05:45 -0000	1.1
+++ find.pl	21 Aug 2003 20:53:33 -0000	1.2
@@ -2,9 +2,10 @@
 
 #######################################################################################
 # 
-#  v0.1
+#  v0.2
 # Very crude required-dependency finder in perl 
-# Works with Berkely DB file created by 'makedeps.pl'
+# Works with Berkely DB file created by 'makedeps.pl' and with mysql or other RDBMS
+# 
 # 
 # Caveats:
 # Full recursive search, no pruning and returns (many) duplicate deps.
@@ -20,17 +21,30 @@
 # 
 # "depends.db" data file hardcoded in src
 #
-# Usage:  find.pl all|module
+# Usage:  find.pl -s|b all|module
 # 
+# -b Berkeley DB
+# -s Sql backend
 # 
 # Todo: optimize-out duplicates while remembering the deepest-found instance
 #       Add optional-depends handling, probably managed in a separate bdb file
+# 
+#       Tie::DBI interface is not zero-code change inside the subroutine, but
+#       can probably be made to be. 
 #
+# Notes: Tie::DBI takes a considerable performance hit, e.g. working out depends
+# for Gnome2 on mysql backend takes 8 seconds elapsed vs 0.5 seconds w/ Berkeley
+# 
+# 
 #######################################################################################
 
 
-use strict;
+#use strict;
 use DB_File;
+use DBI;
+use DBD::mysql;
+use Tie::DBI;
+use Getopt::Std;
 
 
 my $level=0;
@@ -44,18 +58,19 @@
     my $item; 
     my $found;
     my $try;
+    
 
     for $infind ($get) {
-        if ($main'database{$infind} ne "") {
-            for $try ($get) { 
-                for $item (split " ", $main'database{$try}) {
+        if ( ($opt_b && $main'database{$infind} || $opt_s && $main'database{$infind}->{value}) ne "") {
+            for $try ($get) {
+                for $item (split " ",  ($opt_s && $main'database{$try}->{value} || $opt_b && $main'database{$try})  ) {
                     unshift (@main'list, $item);
                     find ($item);
                 }
             }
 
         $main'level--;
-        return  $main'database{$found};
+        return  ($opt_b && $main'database{$try} || $opt_s && $main'database{$found}->{value});
         }
         else{
             $main'level--;
@@ -65,10 +80,33 @@
 }
 
 
+our($opt_b, $opt_s);
+getopts('bs');
+
 my %data;
-my $db= tie ( %data , 'DB_File', 'depends.db',O_RDWR, 0666 ) or die "Can't open";
-my $fd = $db->fd();
-open DATAFILE, "+<&=$fd";
+
+if ( ! ($opt_b || $opt_s) ) {
+    die "Must select BDB or SQL method"
+}
+
+if ($opt_s) {
+    my $db = tie %data,Tie::DBI,{db       => 'mysql:testdb',
+                                 table    => 'depends',
+                                 key      => 'id',
+                                 user     => 'luser',
+                                 password => '',
+                                 CLOBBER  => 0};
+}
+
+
+if ($opt_b) {
+    my $db= tie ( %data , 'DB_File', 'depends.db',O_RDWR, 0666 ) or die "Can't open";
+    my $fd = $db->fd();
+    open DATAFILE, "+<&=$fd";
+}
+
+
+
 
 %main'database = %data;
 my $tofind=shift;
@@ -90,4 +128,4 @@
 print "found @main'list\n";
 my $used=times();
 print "User: $used\n";
-
+close DATAFILE;




More information about the Lunar-commits mailing list