| 1 | package System::Introspector::Config; | ||||||||||||||||||||
| 2 | 1 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 1 | ▶ | use Config::General; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use File::Basename; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 1 | has config => (is => 'lazy'); | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 1 | has config_file => (is => 'ro', required => 1); | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 1 | ▶ | sub _build_config { | ||||||||||||||||||
|
Subroutine
_build_config: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | my ($self) = @_; | |||||||||||||||||||
| 12 | 1 | my $reader = Config::General->new($self->config_file); | |||||||||||||||||||
| 13 | 1 | my %config = $reader->getall; | |||||||||||||||||||
| 14 | 1 | return \%config; | |||||||||||||||||||
| 15 | } | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 1 | ▶ | sub sudo_user { $_[0]->config->{sudo_user} } | ||||||||||||||||||
|
Subroutine
sudo_user: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 1 | ▶ | sub groups { sort keys %{ $_[0]->config->{group} || {} } } | ||||||||||||||||||
|
Subroutine
groups: called CC=2 SCAR=7.2
Pod
undocumented
Condition50%1/2
$_[0]->config->{'group'} || {}
MC/DC0%0/1
$_[0]->config->{'group'} || {}
$_[0]->config->{'group'}
Truth table50%1/2
A
A= $_[0]->config->{'group'}
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 2 | ▶ | sub has_group { exists $_[0]->config->{group}{ $_[1] } } | ||||||||||||||||||
|
Subroutine
has_group: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 1 | ▶ | my $_load_host_file = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 24 | 1 | my ($self, $path) = @_; | |||||||||||||||||||
| 25 | 1 | my $full_path = join '/', dirname($self->config_file), $path; | |||||||||||||||||||
| 26 | 1 | ▶ | open my $fh, '<:utf8', $full_path | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | or die "Unable to read host_file '$full_path': $!\n"; | ||||||||||||||||||||
| 28 | 1 | my @hosts = <$fh>; | |||||||||||||||||||
| 29 | 1 | chomp @hosts; | |||||||||||||||||||
| 30 | 1 | ▶ | return grep { m{\S} and not m{^\s*#} } @hosts; | ||||||||||||||||||
|
Condition100%3/3
/\S/ && !/^\s*#/
MC/DC100%2/2
/\S/ && !/^\s*#/
/\S/
!/^\s*#/
Truth table100%3/3
A && not(B)
A= /\S/B= !/^\s*#/
| |||||||||||||||||||||
| 31 | 1 | }; | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 1 | ▶ | sub hosts { | ||||||||||||||||||
|
Subroutine
hosts: called CC=4 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||
| 34 | 1 | my ($self) = @_; | |||||||||||||||||||
| 35 | 1 | my $host_spec = $self->config->{host}; | |||||||||||||||||||
| 36 | 1 | my $host_file = $self->config->{host_file}; | |||||||||||||||||||
| 37 | return( | ||||||||||||||||||||
| 38 | 1 | ▶ | ref($host_spec) | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 39 | ? @$host_spec | ||||||||||||||||||||
| 40 | : defined($host_spec) ? $host_spec : (), | ||||||||||||||||||||
| 41 | defined($host_file) | ||||||||||||||||||||
| 42 | ? $self->$_load_host_file($host_file) | ||||||||||||||||||||
| 43 | : (), | ||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 1 | ▶ | sub user { $_[0]->config->{user} } | ||||||||||||||||||
|
Subroutine
user: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 4 | ▶ | my $_get_inherited = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 50 | 4 | my $data = shift; | |||||||||||||||||||
| 51 | 4 | ▶ | $data ||= {}; | ||||||||||||||||||
|
Condition50%1/2
$data ||= {}
MC/DC0%0/1
$data ||= {}
$data
Truth table50%1/2
A
A= $data
| |||||||||||||||||||||
| 52 | return | ||||||||||||||||||||
| 53 | 1 | map { ($_ => $data->{$_}) } | |||||||||||||||||||
| 54 | 4 | grep { exists $data->{$_} } | |||||||||||||||||||
| 55 | qw( sudo ); | ||||||||||||||||||||
| 56 | 1 | }; | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 2 | ▶ | sub config_for_group { | ||||||||||||||||||
|
Subroutine
config_for_group: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||
| 59 | 2 | my ($self, $name) = @_; | |||||||||||||||||||
| 60 | 2 | my %common; | |||||||||||||||||||
| 61 | 2 | my $config = $self->config; | |||||||||||||||||||
| 62 | 2 | %common = (%common, $config->$_get_inherited); | |||||||||||||||||||
| 63 | 2 | my $group = $config->{group}{ $name }; | |||||||||||||||||||
| 64 | 2 | %common = (%common, $group->$_get_inherited); | |||||||||||||||||||
| 65 | return { | ||||||||||||||||||||
| 66 | introspect => { | ||||||||||||||||||||
| 67 | map { | ||||||||||||||||||||
| 68 | ($_ => { | ||||||||||||||||||||
| 69 | %common, | ||||||||||||||||||||
| 70 | 3 | ▶ | %{ $group->{introspect}{ $_ } || {} }, | ||||||||||||||||||
|
Condition50%1/2
$group->{'introspect'}{$_} || {}
MC/DC0%0/1
$group->{'introspect'}{$_} || {}
$group->{'introspect'}{$_}
Truth table50%1/2
A
A= $group->{'introspect'}{$_}
| |||||||||||||||||||||
| 71 | }); | ||||||||||||||||||||
| 72 | 2 | ▶ | } keys %{ $group->{introspect} || {} }, | ||||||||||||||||||
|
Condition50%1/2
$group->{'introspect'} || {}
MC/DC0%0/1
$group->{'introspect'} || {}
$group->{'introspect'}
Truth table50%1/2
A
A= $group->{'introspect'}
| |||||||||||||||||||||
| 73 | }, | ||||||||||||||||||||
| 74 | }; | ||||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 1 | 1; | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | =head1 NAME | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | System::Introspector::Config - Configuration file access | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | =head1 SEE ALSO | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | =over | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | =item L<System::Introspector> | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | =back | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | =head1 COPYRIGHT | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 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>. | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | =head1 LICENSE | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | This library is free software and may be distributed under the same terms | ||||||||||||||||||||
| 101 | as perl itself. | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | =cut | ||||||||||||||||||||