aboutsummaryrefslogtreecommitdiffstats
path: root/lib/SpamCat/Conf.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/SpamCat/Conf.pm')
-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;