From 475075a4615d48fab79fc23ded5e08f9735864ec Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sun, 5 Mar 2017 22:19:17 +1300 Subject: Initial dump --- sb_config.pm | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 sb_config.pm (limited to 'sb_config.pm') diff --git a/sb_config.pm b/sb_config.pm new file mode 100644 index 0000000..f4e851e --- /dev/null +++ b/sb_config.pm @@ -0,0 +1,30 @@ +#!/usr/bin/env perl + +package sb_config; + +use strict; +use warnings; +use Config::Tiny; + +sub parse_config +{ + my @scalar_configs = ('nick', 'username', 'ircname', 'server', 'password'); + my @list_configs = ('channels', 'ignore', 'admins'); + my $file = $_[0]; + my %built_config; + my $config = Config::Tiny->read($file); + + # FIXME catch undefined/missing config options + foreach my $option (@scalar_configs) { + $built_config{$option} = $config->{_}->{$option}; + } + + foreach my $option (@list_configs) { + my $vals = $config->{_}->{$option}; + $vals =~ s/^\s+|\s+$//g; + @built_config{$option} = [split /\s*,\s*/, $vals]; + } + + return %built_config; +} +1; -- cgit v1.1