Commit | Line | Data |
afd7c030 |
1 | package System::Introspector::Probe::Groups; |
d4e5a3b2 |
2 | use Moo; |
3 | |
416de713 |
4 | use System::Introspector::Util qw( |
5 | handle_from_file |
6 | transform_exceptions |
7 | ); |
8 | |
d4e5a3b2 |
9 | sub 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; |
86b38d95 |
16 | next if !(length $line); |
416de713 |
17 | my ($name, undef, $gid, $users) = split m{:}, $line; |
18 | $users = length($users) |
19 | ? [split m{,}, $users] |
20 | : []; |
37a73739 |
21 | $group{ $name } = { |
416de713 |
22 | name => $name, |
23 | gid => $gid, |
24 | users => $users, |
25 | }; |
26 | } |
27 | return { groups => \%group }; |
28 | }; |
d4e5a3b2 |
29 | } |
30 | |
31 | sub _open_group_file { |
32 | my ($self) = @_; |
416de713 |
33 | return handle_from_file '/etc/group'; |
d4e5a3b2 |
34 | } |
35 | |
36 | 1; |
535e84b6 |
37 | |
38 | __END__ |
39 | |
40 | =head1 NAME |
41 | |
42 | System::Introspector::Groups - Gather group information |
43 | |
44 | =head1 DESCRIPTION |
45 | |
46 | Uses C</etc/group> to gather information about groups. |
47 | |
48 | =head1 SEE ALSO |
49 | |
50 | =over |
51 | |
52 | =item L<System::Introspector> |
53 | |
54 | =back |
55 | |
56 | =cut |
57 | |