| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$file =~ /\./ or $file =~ /~$/
MC/DC0%0/2
$file =~ /\./ or $file =~ /~$/
$file =~ /\./
$file =~ /~$/
Truth table33%1/3
A or B
A= $file =~ /\./B= $file =~ /~$/
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||