Index: /trunk/Nebulous-Server/Changes
===================================================================
--- /trunk/Nebulous-Server/Changes	(revision 20055)
+++ /trunk/Nebulous-Server/Changes	(revision 20056)
@@ -27,4 +27,7 @@
     - change neb-admin to properly cleanup it's semaphore file
     - retry system call failures
+    - change Nebulous::Server->new() to not setup the db handle on object
+      construction, modify Nebulous::Server->db() to be considtent with this
+      change
 
 0.15 Thu Sep 11 13:00:59 HST 2008
Index: /trunk/Nebulous-Server/lib/Nebulous/Server.pm
===================================================================
--- /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 20055)
+++ /trunk/Nebulous-Server/lib/Nebulous/Server.pm	(revision 20056)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004-2008  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.89 2008-10-10 21:42:59 jhoblitt Exp $
+# $Id: Server.pm,v 1.90 2008-10-11 01:16:50 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -45,7 +45,42 @@
     $log->debug( "entered - @_" );
 
+    my $self = bless {}, ref $class || $class;
+    $self->log($log);
+    $self->sql($sql);
+    $self->config($config);
+
+    $log->debug( "leaving" );
+    
+    return $self;
+}
+
+sub db {
+    my $self = shift;
+
+    if (@_) {
+        $self->{db} = $_[0];
+        return $self;
+    }
+
+    my $log     = $self->log;
+    my $sql     = $self->sql;
+    my $config  = $self->config;
+
+    # if the dbh is still alive, return it
+    if (defined $self->{db} and $self->{db}->ping) {
+        $log->debug("db handle is still alive");
+        return $self->{db};
+    }
+    # otherwise create a new connection
+    $log->debug("db handle is dead/unopened");
+
+    # if we're running under mod_perl & Apache::DBI is loaded we want to
+    # reconnect to the database everytime the dbh is requested.  The rational is
+    # that if we're running under mod_perl this is probably a log running
+    # processes and the database might have gone away on us.  Apache::DBI will
+    # take care of getting a valid dbh back.
     my $db;
     eval {
-        $db = DBI->connect(
+        $db = DBI->connect_cached(
             $config->dsn,
             $config->dbuser,
@@ -59,5 +94,5 @@
 
         $db->do( $sql->set_transaction_model );
-
+        $log->debug( "connected to database: ", sub { $db->data_sources; } );
         $db->commit;
         $log->debug("commit");
@@ -69,73 +104,7 @@
     }
 
-    $log->debug( "connected to database: ", sub { $db->data_sources; } );
-
-    my $self = bless {}, ref $class || $class;
-    $self->log($log);
-    $self->sql($sql);
-    $self->db($db);
-    $self->config($config);
-
-    $log->debug( "leaving" );
-    
-    return $self;
-}
-
-sub db {
-    my $self = shift;
-
-    if (@_) {
-        $self->{db} = $_[0];
-        return $self;
-    }
-
-    my $log     = $self->log;
-    my $sql     = $self->sql;
-    my $config  = $self->config;
-
-    # if the dbh is still alive, return it
-    if (defined $self->{db} and $self->{db}->ping) {
-        $log->debug("db handle is still alive");
-        return $self->{db};
-    }
-    # otherwise create a new connection
-    $log->debug("db handle is dead");
-
-    # if we're running under mod_perl & Apache::DBI is loaded we want to
-    # reconnect to the database everytime the dbh is requested.  The rational is
-    # that if we're running under mod_perl this is probably a log running
-    # processes and the database might have gone away on us.  Apache::DBI will
-    # take care of getting a valid dbh back.
-    if ($INC{'Apache/DBI.pm'} && $ENV{MOD_PERL}) {
-        my $db;
-        eval {
-            $db = DBI->connect(
-                $config->dsn,
-                $config->dbuser,
-                $config->dbpasswd,
-                {
-                    RaiseError => 1,
-                    PrintError => 0,
-                    AutoCommit => 0,
-                },
-            );
-
-            $db->do( $sql->set_transaction_model );
-
-            $db->commit;
-            $log->debug("commit");
-        };
-        if ( $@ ) {
-            $db->rollback if $db;
-            $log->debug("rollback");
-            $log->logdie( "database error: $@" );
-        }
-
-        $self->{db} = $db;
-
-        return $db;
-    }
-
-    return $self->{db};
+    $self->{db} = $db;
+
+    return $db;
 }
 
@@ -1181,5 +1150,5 @@
     my $log = $self->log;
     my $sql = $self->sql;
-    my $db  =$self->db;
+    my $db  = $self->db;
 
     no warnings qw( uninitialized );
