added base pod to all probes
[scpubgit/System-Introspector.git] / lib / System / Introspector / Groups.pm
1 package System::Introspector::Groups;
2 use Moo;
3
4 sub gather {
5     my ($self) = @_;
6     my %group;
7     my $fh = $self->_open_group_file;
8     while (defined( my $line = <$fh> )) {
9         chomp $line;
10         my ($name, undef, $gid, $users) = split m{:}, $line;
11         $users = length($users)
12             ? [split m{,}, $users]
13             : [];
14         $group{ $gid } = {
15             name    => $name,
16             gid     => $gid,
17             users   => $users,
18         };
19     }
20     return \%group;
21 }
22
23 sub _open_group_file {
24     my ($self) = @_;
25     open my $fh, '<', '/etc/group'
26         or die "Unable to read group file /etc/group: $!\n";
27     return $fh;
28 }
29
30 1;
31
32 __END__
33
34 =head1 NAME
35
36 System::Introspector::Groups - Gather group information
37
38 =head1 DESCRIPTION
39
40 Uses C</etc/group> to gather information about groups.
41
42 =head1 SEE ALSO
43
44 =over
45
46 =item L<System::Introspector>
47
48 =back
49
50 =cut
51