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