# Copyright (C) 2005  Joshua Hoblitt
#
# $Id: Config.pm,v 1.2 2006-12-12 00:06:27 jhoblitt Exp $

package Nebulous::Server::Config;

use strict;
use warnings FATAL => qw( all );

our $VERSION = 0.02;

use base qw( Class::Accessor::Fast );

use Nebulous::Util qw( %LEVELS );
use Params::Validate qw( validate SCALAR );

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;

    return $self;
}

1;

__END__
