# -*- cperl -*-
# -----------------------------------------------------------------------------
# $Id: Config.pm,v 1.1.1.1 2004/09/27 14:01:00 admin Exp $
# -----------------------------------------------------------------------------
package Celaenito::Config;
use strict;
use warnings;
use Celaenito::DB;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(&config);

sub config {
    # $key: キー
    # $value: undefを明示的に指定すれば削除
    my ($key, $value) = @_;

    if (@_ >= 2) {
	if (!defined $value) {
	    DB->do(q{
DELETE FROM config
 WHERE confkey=?
}, undef, $key);
	}
	else {
	    DB->do(q{
REPLACE INTO config (confkey, confvalue)
 VALUES (?, ?)
}, undef, $key, $value);
	}
    }
    else {
	my $val = DB->selectrow_array(q{
SELECT confvalue
  FROM config
 WHERE confkey=?
}, undef, $key);
	$val;
    }
}

1;
