iiplc/II/Config.pm

50 lines
897 B
Perl
Raw Permalink Normal View History

2014-06-11 15:55:00 +04:00
package II::Config;
use Config::Tiny;
sub new {
my $class = shift;
2014-08-07 22:34:23 +04:00
my $self = { _file => 'config.ini', };
2014-06-11 15:55:00 +04:00
bless $self, $class;
return $self;
}
2014-08-07 22:21:16 +04:00
# Load configuration
2014-06-11 15:55:00 +04:00
sub load {
my ($self) = @_;
2014-08-07 22:34:23 +04:00
my $file = $self->{_file};
my $tiny = Config::Tiny->new();
$config = $tiny->read($file);
2014-06-11 15:55:00 +04:00
my $key = $config->{auth}->{key};
my $nick = $config->{auth}->{nick};
my $host = $config->{node}->{host};
my @echoareas = split /,/, $config->{node}->{echoareas};
2014-07-30 14:27:48 +04:00
my $name = $config->{node}->{name};
2014-06-11 15:55:00 +04:00
$c = {
nick => $nick,
key => $key,
host => $host,
echoareas => [@echoareas],
2014-07-30 14:27:48 +04:00
name => $name,
2014-06-11 15:55:00 +04:00
};
return $c;
}
2014-08-07 22:21:16 +04:00
# Reload configuration
sub reload {
my ($self) = @_;
2014-08-07 22:34:23 +04:00
my $c = II::Config->new();
my $config = $c->load();
return $config;
2014-08-07 22:21:16 +04:00
}
2014-06-11 15:55:00 +04:00
1;