sanity checking for the config file
[p5sagit/Promulger.git] / lib / Promulger / Config.pm
1 package Promulger::Config;
2 use strict;
3 use warnings;
4
5 use Config::General;
6
7 my $config;
8
9 my @NECESSARY = qw/aliases list_home/;
10
11 sub load_config {
12   my ($class, $config_file) = @_;
13   $config = { Config::General->new($config_file)->getall };
14   $config->{config_file} = $config_file;
15
16   $class->validate_config($config);
17
18   return $config;
19 };
20
21 sub config {
22   die "No configuration loaded" unless $config;
23   return $config;
24 }
25
26 sub validate_config {
27   my ($class, $config) = @_;
28   for my $nec (@NECESSARY) {
29     die "Required key '${nec}' missing in " . $config->{config_file}
30       unless $config->{$nec};
31   }
32
33   die "cannot read aliases file " . $config->{aliases}
34     unless -r $config->{aliases};
35   die "cannot write to list home " . $config->{list_home}
36     unless -w $config->{list_home};
37 }
38
39 'http://reductivelabs.com/products/puppet/';