From: Robert 'phaylon' Sedlacek Date: Thu, 3 May 2012 16:13:09 +0000 (+0000) Subject: Groups probe for /etc/group info X-Git-Tag: v0.001_001~133 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d4e5a3b26ef82dde69dcdfaab1a7bfc2555b28b9;p=scpubgit%2FSystem-Introspector.git Groups probe for /etc/group info --- diff --git a/lib/System/Introspector/Groups.pm b/lib/System/Introspector/Groups.pm new file mode 100644 index 0000000..b456a5f --- /dev/null +++ b/lib/System/Introspector/Groups.pm @@ -0,0 +1,30 @@ +package System::Introspector::Groups; +use Moo; + +sub gather { + my ($self) = @_; + my %group; + my $fh = $self->_open_group_file; + while (defined( my $line = <$fh> )) { + chomp $line; + my ($name, undef, $gid, $users) = split m{:}, $line; + $users = length($users) + ? [split m{,}, $users] + : []; + $group{ $gid } = { + name => $name, + gid => $gid, + users => $users, + }; + } + return \%group; +} + +sub _open_group_file { + my ($self) = @_; + open my $fh, '<', '/etc/group' + or die "Unable to read group file /etc/group: $!\n"; + return $fh; +} + +1;