Introspector/Config.pm

filter: Statementstmt 100% 49 / 49 Branchbran 37.5% 3 / 8 Conditioncond 63.6% 7 / 11 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 6 totaltotal 79.3% 73 / 92 CC 10 SCAR 9.3
CC
10
Cov
87%
hosts
5.0
config_for_group
3.0
__ANON__
3.0
CRAP 2.5
« Introspector/Probe/Nagios/CheckMkAgent.pm ↑ Summary Introspector/Probe/Groups.pm »
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'} || {}
l!l
10
MC/DC0%0/1
$_[0]->config->{'group'} || {}
$_[0]->config->{'group'}
Truth table50%1/2
A
A= $_[0]->config->{'group'}
Aresult
11
00
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
BranchTrueFalseTotal
open my $fh, "<:utf8", $full_path or die "Unable to read host_file '${full_path}': $!\n" 1 0 1
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*#/
!ll&&!rl&&r
114
MC/DC100%2/2
/\S/ && !/^\s*#/
/\S/ !/^\s*#/
Truth table100%3/3
A && not(B)
A= /\S/B= !/^\s*#/
ABresult
0X0
100
111
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
BranchTrueFalseTotal
ref $host_spec ? : 1 0 1
defined $host_spec ? : 0 0 0
defined $host_file ? : 1 0 1
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 ||= {}
l!l
40
MC/DC0%0/1
$data ||= {}
$data
Truth table50%1/2
A
A= $data
Aresult
11
00
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'}{$_} || {}
l!l
30
MC/DC0%0/1
$group->{'introspect'}{$_} || {}
$group->{'introspect'}{$_}
Truth table50%1/2
A
A= $group->{'introspect'}{$_}
Aresult
11
00
71 });
72 2 ▶ } keys %{ $group->{introspect} || {} },
Condition50%1/2
$group->{'introspect'} || {}
l!l
20
MC/DC0%0/1
$group->{'introspect'} || {}
$group->{'introspect'}
Truth table50%1/2
A
A= $group->{'introspect'}
Aresult
11
00
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
« Introspector/Probe/Nagios/CheckMkAgent.pm ↑ Summary Introspector/Probe/Groups.pm »