aboutsummaryrefslogtreecommitdiffstats
path: root/lib/SpamCat
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2014-11-21 11:02:46 -0500
committerBrian Cully <bjc@kublai.com>2014-11-23 14:19:29 -0500
commitcacbab512d4102e6db19c6487c4d291006dd0fda (patch)
treebc0e623db6b94384c9305529311148712786426c /lib/SpamCat
downloadspamcat-cacbab512d4102e6db19c6487c4d291006dd0fda.tar.gz
spamcat-cacbab512d4102e6db19c6487c4d291006dd0fda.zip
Initial commit.
Diffstat (limited to 'lib/SpamCat')
-rw-r--r--lib/SpamCat/Conf.pm45
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;