# Copyright (C) 2005  Joshua Hoblitt
#
# $Id: Config.pm,v 1.5 2008-12-14 22:54:25 eugene Exp $

package Nebulous::Server::Config;

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

our $VERSION = 0.02;

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

use Log::Log4perl qw( :levels );
use Params::Validate qw( validate SCALAR );

our %LEVELS = (
    off     => $OFF,
    fatal   => $FATAL,
    error   => $ERROR,
    warn    => $WARN,
    info    => $INFO,
    debug   => $DEBUG,
    all     => $ALL,
);

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__
