map groups by name instead of gid
[scpubgit/System-Introspector.git] / lib / System / Introspector / Groups.pm
CommitLineData
d4e5a3b2 1package System::Introspector::Groups;
2use Moo;
3
416de713 4use System::Introspector::Util qw(
5 handle_from_file
6 transform_exceptions
7);
8
d4e5a3b2 9sub gather {
10 my ($self) = @_;
416de713 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 : [];
37a73739 20 $group{ $name } = {
416de713 21 name => $name,
22 gid => $gid,
23 users => $users,
24 };
25 }
26 return { groups => \%group };
27 };
d4e5a3b2 28}
29
30sub _open_group_file {
31 my ($self) = @_;
416de713 32 return handle_from_file '/etc/group';
d4e5a3b2 33}
34
351;
535e84b6 36
37__END__
38
39=head1 NAME
40
41System::Introspector::Groups - Gather group information
42
43=head1 DESCRIPTION
44
45Uses 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