sanity checking for the config file
[p5sagit/Promulger.git] / lib / Promulger / Config.pm
CommitLineData
21baaef0 1package Promulger::Config;
9bfd7b60 2use strict;
3use warnings;
4
5use Config::General;
21baaef0 6
7my $config;
9bfd7b60 8
0b07d53c 9my @NECESSARY = qw/aliases list_home/;
10
9bfd7b60 11sub load_config {
12 my ($class, $config_file) = @_;
13 $config = { Config::General->new($config_file)->getall };
14 $config->{config_file} = $config_file;
0b07d53c 15
16 $class->validate_config($config);
17
21baaef0 18 return $config;
19};
20
9bfd7b60 21sub config {
22 die "No configuration loaded" unless $config;
23 return $config;
24}
25
0b07d53c 26sub 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
21baaef0 39'http://reductivelabs.com/products/puppet/';