From 0274d5453d331aa7f887ff0407c03ddcb6f32b01 Mon Sep 17 00:00:00 2001
From: Gerhard Gonter <ggonter@gmail.com>
Date: Mon, 1 Aug 2016 11:54:45 +0200
Subject: [PATCH] use Util::MongoDB for better hdanling of configuration
 options

---
 textarchive/lib/TA/ObjReg.pm | 23 ++++++++++++++++++++++-
 textarchive/vlib001.pl       |  3 ++-
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/textarchive/lib/TA/ObjReg.pm b/textarchive/lib/TA/ObjReg.pm
index b74c4b5..49ac8f4 100644
--- a/textarchive/lib/TA/ObjReg.pm
+++ b/textarchive/lib/TA/ObjReg.pm
@@ -20,6 +20,7 @@ use strict;
 use File::Find;
 
 use TA::Util;
+use Util::MongoDB;
 
 my %plugins_loaded= ();
 
@@ -100,7 +101,7 @@ sub get_project
     elsif ($be eq 'MongoDB')
     {
       require MongoDB;
-      require MongoDB::MongoClient;
+      # will be included by module "MongoDB" : require MongoDB::MongoClient;
     }
     else
     {
@@ -131,6 +132,10 @@ sub get_project
       my $x= $obj->{'_maint'}->find_one ( { 'an' => 'seq' } );
       $obj->{'seq'}= $seq= $x->{'av'};
     }
+    else
+    {
+      return undef;
+    }
   }
 
   # print "seq: [$seq] ", main::Dumper ($seq);
@@ -732,6 +737,9 @@ sub connect_MongoDB
   my $cfg= shift;
 
   my $cmm= $cfg->{'MongoDB'};
+
+=begin comment
+
   my %cmm_c= map { $_ => $cmm->{$_} } qw(host username password db_name);
   # print "cmm_c: ", main::Dumper (\%cmm_c);
 
@@ -755,6 +763,19 @@ sub connect_MongoDB
     return undef;
   }
 
+=end comment
+=cut
+
+  my $db= Util::MongoDB::connect ($cmm);
+  return undef unless (defined ($db));
+  # print "db: ", main::Dumper($db); exit;
+
+  # TODO: streamline ...
+  my $col0= $db->get_collection($cmm->{'maint'});
+  my $col1= $db->get_collection($cmm->{'catalog'});
+  my $col2= $db->get_collection($cmm->{'keys'});
+  # print "col: [$col0] [$col1] [$col2]\n";
+
   $obj->{'_mongo'}= $db;
   $obj->{'_maint'}= $col0;
   $obj->{'_cat'}= $col1;
diff --git a/textarchive/vlib001.pl b/textarchive/vlib001.pl
index 286d445..9fb4d32 100755
--- a/textarchive/vlib001.pl
+++ b/textarchive/vlib001.pl
@@ -138,6 +138,7 @@ if ($op_mode eq 'edit')
 }
 
 my $objreg= new TA::ObjReg ('project' => $project, 'store' => $store, 'key' => 'md5');
+# print "objreg: ", Dumper ($objreg); exit;
 &usage ('no config found') unless (defined ($objreg));
 print "objreg: ", Dumper ($objreg) if ($DEBUG || $STOP);
 exit if ($STOP);
@@ -243,7 +244,7 @@ sub usage
   if ($msg)
   {
     print $msg, "\n";
-    sleep (10);
+    sleep (5);
   }
   system ('perldoc', $0);
   exit -1;
-- 
GitLab