diff options
author | Brian Cully <bjc@kublai.com> | 2014-11-21 11:02:46 -0500 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2014-11-23 14:19:29 -0500 |
commit | cacbab512d4102e6db19c6487c4d291006dd0fda (patch) | |
tree | bc0e623db6b94384c9305529311148712786426c /lib/SpamCat | |
download | spamcat-cacbab512d4102e6db19c6487c4d291006dd0fda.tar.gz spamcat-cacbab512d4102e6db19c6487c4d291006dd0fda.zip |
Initial commit.
Diffstat (limited to 'lib/SpamCat')
-rw-r--r-- | lib/SpamCat/Conf.pm | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/SpamCat/Conf.pm b/lib/SpamCat/Conf.pm new file mode 100644 index 0000000..ab6a3ff --- /dev/null +++ b/lib/SpamCat/Conf.pm @@ -0,0 +1,45 @@ +package SpamCat::Conf; + +use IO::File; + +use strict; +use warnings; + +sub read { + my ($filen) = @_; + my %rc; + + my $fh = IO::File->new($filen) || + die "Couldn't open $filen for reading: $!\n"; + while (<$fh>) { + my ($key, $val) = parse_line($_); + if (defined $key && defined $val) { + $rc{$key} = $val; + } + } + $fh->close; + + %rc; +} + +sub parse_line { + my ($line) = @_; + + chomp $line; + $line =~ s/(.*)#.*/$1/; + $line =~ s/\s+$//; + + if ($line =~ /\s*([^\s]*)\s*=\s*(.*)$/) { + my $key = lc $1; + my $val = $2; + + if ($key eq 'domains') { + $val =~ s/,/ /g; + my @vals = split /\s+/, $val; + $val = \@vals; + } + return ($key, $val); + } +} + +1; |