1 package System::Introspector::Config;
6 has config => (is => 'lazy');
8 has config_file => (is => 'ro', required => 1);
12 my $reader = Config::General->new($self->config_file);
13 my %config = $reader->getall;
17 sub sudo_user { $_[0]->config->{sudo_user} }
19 sub groups { sort keys %{ $_[0]->config->{group} || {} } }
21 sub has_group { exists $_[0]->config->{group}{ $_[1] } }
23 my $_load_host_file = sub {
24 my ($self, $path) = @_;
25 my $full_path = join '/', dirname($self->config_file), $path;
26 open my $fh, '<:utf8', $full_path
27 or die "Unable to read host_file '$full_path': $!\n";
30 return grep { m{\S} and not m{^\s*#} } @hosts;
35 my $host_spec = $self->config->{host};
36 my $host_file = $self->config->{host_file};
40 : defined($host_spec) ? $host_spec : (),
42 ? $self->$_load_host_file($host_file)
47 sub user { $_[0]->config->{user} }
49 my $_get_inherited = sub {
53 map { ($_ => $data->{$_}) }
54 grep { exists $data->{$_} }
58 sub config_for_group {
59 my ($self, $name) = @_;
61 my $config = $self->config;
62 %common = (%common, $config->$_get_inherited);
63 my $group = $config->{group}{ $name };
64 %common = (%common, $group->$_get_inherited);
70 %{ $group->{introspect}{ $_ } || {} },
72 } keys %{ $group->{introspect} || {} },
81 System::Introspector::Config - Configuration file access
87 =item L<System::Introspector>
93 Copyright (c) 2012 the L<System::Introspector>
94 L<AUTHOR|System::Introspector/AUTHOR>,
95 L<CONTRIBUTORS|System::Introspector/CONTRIBUTORS> and
96 L<SPONSORS|System::Introspector/SPONSORS>.
100 This library is free software and may be distributed under the same terms