Index: gs2-extensions/tdb/trunk/perllib/DBDrivers/BaseDBDriver.pm
===================================================================
--- gs2-extensions/tdb/trunk/perllib/DBDrivers/BaseDBDriver.pm	(revision 30335)
+++ gs2-extensions/tdb/trunk/perllib/DBDrivers/BaseDBDriver.pm	(revision 30336)
@@ -23,61 +23,90 @@
 ###############################################################################
 
-package BaseDBDriver;
+package DBDrivers::BaseDBDriver;
 
 # Pragma
 use strict;
+no strict 'subs';
+no strict 'refs'; # allow filehandles to be variables and viceversa
 
 # Libaries
+use Time::HiRes qw( gettimeofday );
 use gsprintf 'gsprintf';
 
-###############################################################################
-## Private Functions
-###############################################################################
-
-
-## @function _convert_infodb_hash_to_string(hashmap)
-#
-sub _convert_infodb_hash_to_string
-{
-    my $infodb_map = shift(@_);
-    my $infodb_entry_value = "";
-    foreach my $infodb_value_key (keys(%$infodb_map)) {
-        foreach my $infodb_value (@{$infodb_map->{$infodb_value_key}}) {
-            $infodb_entry_value .= "<$infodb_value_key>" . $infodb_value . "\n";
-        }
+
+## @function constructor
+#
+sub new
+{
+    my $class = shift(@_);
+    my $debug = shift(@_);
+    my $self = {};
+    # Debug messages for this driver
+    $self->{'debug'} = $debug; # 1 to enable
+    # Default file extension - in this case it is an error to create a DB from
+    # BaseDBDriver
+    $self->{'default_file_extension'} = 'err';
+    bless($self, $class);
+    return $self;
+}
+## new(void) => BaseDBDriver ##
+
+
+###############################################################################
+## Protected Functions
+###############################################################################
+
+
+## @function debugPrint(string) => void
+#
+sub debugPrint
+{
+    my $self = shift(@_);
+    my $message = shift(@_);
+    if ($self->{'debug'}) {
+	my ($seconds, $microseconds) = gettimeofday();
+	print STDERR '[DEBUG:' . $seconds . '.' . $microseconds . '] ' . (caller 1)[3] . $message . "\n";
     }
-    return $infodb_entry_value;
-}
-## _convert_infodb_hash_to_string(hashmap) => string ##
-
-
-## @function _convert_infodb_string_to_hash(string)
-#
-sub _convert_infodb_string_to_hash
-{
-    my $infodb_entry_value = shift(@_);
-    my $infodb_map = ();
-
-    if (!defined $infodb_entry_value) {
-	print STDERR "Warning: No value to convert into a infodb hashtable\n";
+}
+## debugPrint(string) => void ##
+
+
+## @function debugPrintFunctionHeader(*) => void
+#
+sub debugPrintFunctionHeader
+{
+    my $self = shift(@_);
+    if ($self->{'debug'}) {
+	my @arguments;
+	foreach my $argument (@_) {
+	    if ($argument !~ /^-?\d+(\.?\d+)?$/) {
+		push(@arguments, '"' . $argument . '"');
+	    }
+	    else {
+		push(@arguments, $argument);
+	    }
+	}
+	my $message = '(' . join(', ', @arguments) . ')';
+	# Would love to just call debugPrint() here, but then caller would be wrong
+	my ($seconds, $microseconds) = gettimeofday();
+	print STDERR '[DEBUG:' . $seconds . '.' . $microseconds . '] ' . (caller 1)[3] . $message . "\n";
     }
-    else {
-        while ($infodb_entry_value =~ /^<(.*?)>(.*)$/mg) {
-            my $infodb_value_key = $1;
-            my $infodb_value = $2;
-
-            if (!defined($infodb_map->{$infodb_value_key})) {
-                $infodb_map->{$infodb_value_key} = [ $infodb_value ];
-            }
-            else {
-                push(@{$infodb_map->{$infodb_value_key}}, $infodb_value);
-            }
-	}
+}
+## debugPrintFunctionHeader(*) => void
+
+
+## @function errorPrint(string, integer) => void
+#
+sub errorPrint
+{
+    my $self = shift(@_);
+    my $message = shift(@_);
+    my $is_fatal = shift(@_);
+    print STDERR 'Error in ' . (caller 1)[3] . '! ' . $message . "\n";
+    if ($is_fatal) {
+	exit();
     }
-
-    return $infodb_map;
-}
-## _convert_infodb_string_to_hash(string) => hashmap ##
-
+}
+## errorPrint(string, integer) => void ##
 
 ###############################################################################
@@ -86,29 +115,60 @@
 
 
-## @function supports_datestamp()
-#
-sub supports_datestamp
-{
-    return 0;
-}
-## supports_datestamp() => integer ##
-
-
-## @function supports_merge()
-#
-sub supports_merge
-{
-    return 0;
-}
-## supports_merge() => integer ##
-
-
-## @function supports_rss()
-#
-sub supports_rss
-{
-    return 0;
-}
-## supports_rss() => integer ##
+## @function canInstantiate(void) => integer
+#
+#  Called to determine if this driver implementation can actually be created
+#  given its purpose and the current system (i.e. Windows only drivers on
+#  Linux systems can't be instantiated...)
+#
+sub canInstantiate
+{
+    # Can't ever instantiate the base driver
+    return 0;
+}
+## canInstantiate(void) => integer  ##
+
+
+## @function get_infodb_file_path(string, string) => string
+#
+sub get_infodb_file_path
+{
+    my $self = shift(@_);
+    my $collection_name = shift(@_);
+    my $infodb_directory_path = shift(@_);
+    my $infodb_file_name = &util::get_dirsep_tail($collection_name) . '.' . $self->{'default_file_extension'};
+    my $infodb_file_path = &FileUtils::filenameConcatenate($infodb_directory_path, $infodb_file_name);
+    return $infodb_file_path;
+}
+## get_infodb_file_path(string, string) => string ##
+
+
+## @function supportsDatestamp(void) => boolean
+#
+sub supportsDatestamp
+{
+    my $self = shift(@_);
+    return 0;
+}
+## supportsDatestamp(void) => boolean ##
+
+
+## @function supportsMerge(void) => boolean
+#
+sub supportsMerge
+{
+    my $self = shift(@_);
+    return 0;
+}
+## supportsMerge(void) => boolean ##
+
+
+## @function supportsRSS(void) => boolean
+#
+sub supportsRSS
+{
+    my $self = shift(@_);
+    return 0;
+}
+## supportsRSS(void) => boolean ##
 
 
@@ -118,102 +178,113 @@
 
 
-## @function close_infodb_write_handle
+## @function close_infodb_write_handle(*) => void
 #
 sub close_infodb_write_handle
 {
-    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
-    die("\n");
-}
-## close_infodb_write_handle ##
-
-
-## @function delete_infodb_entry
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## close_infodb_write_handle(*) => void ##
+
+
+## @function delete_infodb_entry(*) => void
 #
 sub delete_infodb_entry
 {
-    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
-    die("\n");
-}
-## delete_infodb_entry ##
-
-
-## @function get_infodb_file_path
-#
-sub get_infodb_file_path
-{
-    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
-    die("\n");
-}
-## get_infodb_file_path ##
-
-
-## @function merge_databases
-#
-sub merge_databases
-{
-    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
-    die("\n");
-}
-## merge_databases ##
-
-
-## @function open_infodb_write_handle
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## delete_infodb_entry(*) => void ##
+
+
+## @function mergeDatabases(*) => void
+#
+sub mergeDatabases
+{
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## mergeDatabases(*) => void ##
+
+
+## @function open_infodb_write_handle(*) => void
 #
 sub open_infodb_write_handle
 {
-    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
-    die("\n");
-}
-## open_infodb_write_handle ##
-
-
-## @function set_infodb_entry()
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## open_infodb_write_handle(*) => void ##
+
+
+## @function set_infodb_entry(*) => void
 #
 sub set_infodb_entry
 {
-    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
-    die("\n");
-}
-## set_infodb_entry() => void ##
-
-
-## @function read_infodb_file
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## set_infodb_entry(*) => void ##
+
+
+## @function read_infodb_rawentry(*) => string
+#
+sub read_infodb_rawentry
+{
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## read_infodb_rawentry(*) => string ##
+
+
+## @function read_infodb_file(*) => void
 #
 sub read_infodb_file
 {
-    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
-    die("\n");
-}
-## read_infodb_file ##
-
-
-## @function read_infodb_keys
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## read_infodb_file(*) => void ##
+
+
+## @function read_infodb_keys(*) => void
 #
 sub read_infodb_keys
 {
-    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
-    die("\n");
-}
-## read_infodb_keys ##
-
-
-## @function write_infodb_entry
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## read_infodb_keys(*) => void ##
+
+
+## @function write_infodb_entry(*) => void
 #
 sub write_infodb_entry
 {
-    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
-    die("\n");
-}
-## write_infodb_entry ##
-
-
-## @function write_infodb_rawentry
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## write_infodb_entry(*) => void ##
+
+
+## @function write_infodb_rawentry(*) => void
 #
 sub write_infodb_rawentry
 {
-    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
-    die("\n");
-}
-## write_infodb_rawentry ##
+    my $self = shift(@_);
+    gsprintf(STDERR, (caller(0))[3] . " {common.must_be_implemented}\n");
+    die("\n");
+}
+## write_infodb_rawentry(*) => void ##
+
 
 1;
