Index: trunk/Nebulous/lib/Nebulous/Server.pm
===================================================================
--- trunk/Nebulous/lib/Nebulous/Server.pm	(revision 4638)
+++ trunk/Nebulous/lib/Nebulous/Server.pm	(revision 4874)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Server.pm,v 1.9 2005-06-30 02:35:06 jhoblitt Exp $
+# $Id: Server.pm,v 1.10 2005-08-25 01:44:32 jhoblitt Exp $
 
 package Nebulous::Server;
@@ -12,4 +12,5 @@
 use DBI;
 use Nebulous::Util qw( :standard );
+use Nebulous::Server::Config;
 use Nebulous::Server::Log;
 use Nebulous::Server::SQL;
@@ -25,18 +26,12 @@
 my $db;
 
-sub setup {
-    my $self = shift;
-
-    my ( $dsn, $user, $passwd ) = validate_pos( @_,
-        {
-            type        => SCALAR,
-        },
-        {
-            type        => SCALAR,
-        },
-        {
-            type        => SCALAR,
-        },
-    );
+sub init {
+    my $self = shift;
+
+    # let Nebulous::Server::Config validate our params
+    my $config = Nebulous::Server::Config->init( @_ );
+
+    # log4perl is not avaliable until we call init()
+    Nebulous::Server::Log->init;
 
     $log = Log::Log4perl::get_logger( "Nebulous::Server" );
@@ -47,7 +42,7 @@
     eval {
         $db = DBI->connect(
-            $dsn,
-            $user,
-            $passwd,
+            $config->dsn,
+            $config->dbuser,
+            $config->dbpasswd,
             {
                 RaiseError => 1,
Index: trunk/Nebulous/lib/Nebulous/Server/Config.pm
===================================================================
--- trunk/Nebulous/lib/Nebulous/Server/Config.pm	(revision 4874)
+++ trunk/Nebulous/lib/Nebulous/Server/Config.pm	(revision 4874)
@@ -0,0 +1,68 @@
+# Copyright (C) 2005  Joshua Hoblitt
+#
+# $Id: Config.pm,v 1.1 2005-08-25 01:44:32 jhoblitt Exp $
+
+package Nebulous::Server::Config;
+
+use strict;
+use warnings FATAL => qw( all );
+
+our $VERSION = 0.01;
+
+use base qw( Class::Accessor::Fast );
+
+use Nebulous::Util qw( %LEVELS );
+use Params::Validate qw( validate SCALAR );
+
+my $_instance;
+
+my $new_validate = {
+    dsn         => { type => SCALAR },
+    dbuser      => { type => SCALAR },
+    dbpasswd    => { type => SCALAR },
+    log_level   => {
+        type        => SCALAR,
+        optional    => 1,
+        default     => 'all',
+        callbacks   => {
+            'is valid level' => sub {
+                defined $LEVELS{ lc $_[0] };
+            },
+        },
+    },
+};
+
+__PACKAGE__->mk_ro_accessors( keys %$new_validate );
+
+sub init {
+    my $class = shift;
+
+    my %p = validate( @_, $new_validate );
+
+    # normalize log levels to lower-case
+    $p{ log_level } = lc $p{ log_level };
+
+    my $self = \%p;
+
+    bless $self, $class || ref $class;
+
+    $_instance = $self;
+
+    return $self;
+}
+
+# orginaly lifted from Class::Singleton and modified to return undef unless the
+# singleton has been initialized.
+
+sub instance {
+    my $class = shift;
+
+    die "not configured" unless defined $_instance;
+
+#return defined $_instance ? $_instance : undef;
+    return $_instance;
+}
+
+1;
+
+__END__
