Introspector/Probe/Sudoers.pm

filter: Statementstmt 94.8% 37 / 39 Branchbran 75.0% 6 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 1 totaltotal 82.2% 51 / 62 CC 8 SCAR 10.3
CC
8
Cov
88%
_gather_from_dir
4.2
__ANON__
4.0
_gather_files
2.0
CRAP 2.8
« Introspector/Probe/Repositories/Git.pm ↑ Summary Introspector/Probe/Nagios/CheckMkAgent.pm »
1 package System::Introspector::Probe::Sudoers;
2 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use System::Introspector::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
5 handle_from_command
6 files_from_dir
7 output_from_file
8 transform_exceptions
9 1 );
10  
11 has sudoers_file => (
12 is => 'ro',
13 0 ▶ default => sub { '/etc/sudoers' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
14 1 );
15  
16 has hostname => (
17 is => 'ro',
18 0 ▶ default => sub { scalar `hostname` },
Subroutine __ANON__: not called CC=1 SCAR=6.9
19 1 );
20  
21 1 ▶sub gather {
Subroutine gather: called CC=1 SCAR=0.0
Pod undocumented
22 1 my ($self) = @_;
23 1 my %file = $self->_gather_files($self->sudoers_file);
24 1 return \%file;
25 }
26  
27 3 ▶sub _gather_files {
Subroutine _gather_files: called CC=2 SCAR=6.9
28 3 my ($self, $file) = @_;
29 3 ▶ my $result = transform_exceptions {
Subroutine __ANON__: called CC=4 SCAR=13.9
30 3 my @lines = output_from_file $file;
31 3 my @result = ({ body => join '', @lines });
32 3 for my $line (@lines) {
33 6 chomp $line;
34 6 ▶ if ($line =~ m{^#include\s+(.+)$}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /^#include\s+(.+)$/) { } 1 5 6
elsif ($line =~ /^#includedir\s+(.+)$/) { } 1 4 5
35 1 my $inc_file = $self->_insert_hostname($1);
36 1 push @result, $self->_gather_files($inc_file);
37 }
38 elsif ($line =~ m{^#includedir\s+(.+)$}) {
39 1 my $inc_dir = $self->_insert_hostname($1);
40 1 push @result, $self->_gather_from_dir($inc_dir);
41 }
42 }
43 3 return \@result;
44 3 };
45 3 ▶ return $file => $result
Branch: 1 branch
BranchTrueFalseTotal
if ref $result eq "HASH" 0 3 3
46 if ref $result eq 'HASH';
47 3 return $file => @$result;
48 }
49  
50 1 ▶sub _gather_from_dir {
Subroutine _gather_from_dir: called CC=4 SCAR=14.5
51 1 my ($self, $dir) = @_;
52 1 my @files = files_from_dir $dir;
53 1 my %file;
54 1 for my $file (@files) {
55 1 ▶ next if $file =~ m{\.} or $file =~ m{~$};
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /\./ or $file =~ /~$/ 0 1 1
Condition33%1/3
$file =~ /\./ or $file =~ /~$/
l!l&&r!l&&!r
001
MC/DC0%0/2
$file =~ /\./ or $file =~ /~$/
$file =~ /\./ $file =~ /~$/
Truth table33%1/3
A or B
A= $file =~ /\./B= $file =~ /~$/
ABresult
1X1
011
000
56 1 %file = (%file, $self->_gather_files("$dir/$file"));
57 }
58 1 return %file;
59 }
60  
61 2 ▶sub _insert_hostname {
Subroutine _insert_hostname: called CC=1 SCAR=0.0
62 2 my ($self, $value) = @_;
63 2 my $hostname = $self->hostname;
64 2 $value =~ s{\%h}{$hostname}g;
65 2 return $value;
66 }
67  
68 1 1;
69  
70 __END__
« Introspector/Probe/Repositories/Git.pm ↑ Summary Introspector/Probe/Nagios/CheckMkAgent.pm »