File Coverage

blib/lib/System/Introspector/Probe/Groups.pm
Criterion Covered Total %
statement 19 19 100.0
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 27 29 93.1


line stmt bran cond sub pod time code
1             package System::Introspector::Probe::Groups;
2 1     1   25498 use Moo;
  1         22277  
  1         6  
3              
4 1         335 use System::Introspector::Util qw(
5             handle_from_file
6             transform_exceptions
7 1     1   2712 );
  1         5  
8              
9             sub gather {
10 1     1 0 68 my ($self) = @_;
11             return transform_exceptions {
12 1     1   2 my %group;
13 1         6 my $fh = $self->_open_group_file;
14 1         19 while (defined( my $line = <$fh> )) {
15 44         56 chomp $line;
16 44 50       91 next if !(length $line);
17 44         139 my ($name, undef, $gid, $users) = split m{:}, $line;
18 44 100       117 $users = length($users)
19             ? [split m{,}, $users]
20             : [];
21 44         272 $group{ $name } = {
22             name => $name,
23             gid => $gid,
24             users => $users,
25             };
26             }
27 1         17 return { groups => \%group };
28 1         13 };
29             }
30              
31             sub _open_group_file {
32 1     1   2 my ($self) = @_;
33 1         5 return handle_from_file '/etc/group';
34             }
35              
36             1;
37              
38             __END__