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; |
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 | |
30 | sub _open_group_file { |
31 | my ($self) = @_; |
416de713 |
32 | return handle_from_file '/etc/group'; |
d4e5a3b2 |
33 | } |
34 | |
35 | 1; |
535e84b6 |
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 | |