From cacbab512d4102e6db19c6487c4d291006dd0fda Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Fri, 21 Nov 2014 11:02:46 -0500 Subject: Initial commit. --- lib/SpamCat/Conf.pm | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 lib/SpamCat/Conf.pm (limited to 'lib/SpamCat') 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; -- cgit v1.2.3