1N/Apackage User::grent;
1N/Ause strict;
1N/A
1N/Ause 5.006_001;
1N/Aour $VERSION = '1.00';
1N/Aour(@EXPORT, @EXPORT_OK, %EXPORT_TAGS);
1N/ABEGIN {
1N/A use Exporter ();
1N/A @EXPORT = qw(getgrent getgrgid getgrnam getgr);
1N/A @EXPORT_OK = qw($gr_name $gr_gid $gr_passwd $gr_mem @gr_members);
1N/A %EXPORT_TAGS = ( FIELDS => [ @EXPORT_OK, @EXPORT ] );
1N/A}
1N/Ause vars @EXPORT_OK;
1N/A
1N/A# Class::Struct forbids use of @ISA
1N/Asub import { goto &Exporter::import }
1N/A
1N/Ause Class::Struct qw(struct);
1N/Astruct 'User::grent' => [
1N/A name => '$',
1N/A passwd => '$',
1N/A gid => '$',
1N/A members => '@',
1N/A];
1N/A
1N/Asub populate (@) {
1N/A return unless @_;
1N/A my $gob = new();
1N/A ($gr_name, $gr_passwd, $gr_gid) = @$gob[0,1,2] = @_[0,1,2];
1N/A @gr_members = @{$gob->[3]} = split ' ', $_[3];
1N/A return $gob;
1N/A}
1N/A
1N/Asub getgrent ( ) { populate(CORE::getgrent()) }
1N/Asub getgrnam ($) { populate(CORE::getgrnam(shift)) }
1N/Asub getgrgid ($) { populate(CORE::getgrgid(shift)) }
1N/Asub getgr ($) { ($_[0] =~ /^\d+/) ? &getgrgid : &getgrnam }
1N/A
1N/A1;
1N/A__END__
1N/A
1N/A=head1 NAME
1N/A
1N/AUser::grent - by-name interface to Perl's built-in getgr*() functions
1N/A
1N/A=head1 SYNOPSIS
1N/A
1N/A use User::grent;
1N/A $gr = getgrgid(0) or die "No group zero";
1N/A if ( $gr->name eq 'wheel' && @{$gr->members} > 1 ) {
1N/A print "gid zero name wheel, with other members";
1N/A }
1N/A
1N/A use User::grent qw(:FIELDS;
1N/A getgrgid(0) or die "No group zero";
1N/A if ( $gr_name eq 'wheel' && @gr_members > 1 ) {
1N/A print "gid zero name wheel, with other members";
1N/A }
1N/A
1N/A $gr = getgr($whoever);
1N/A
1N/A=head1 DESCRIPTION
1N/A
1N/AThis module's default exports override the core getgrent(), getgruid(),
1N/Aand getgrnam() functions, replacing them with versions that return
1N/A"User::grent" objects. This object has methods that return the similarly
1N/Anamed structure field name from the C's passwd structure from F<grp.h>;
1N/Anamely name, passwd, gid, and members (not mem). The first three
1N/Areturn scalars, the last an array reference.
1N/A
1N/AYou may also import all the structure fields directly into your namespace
1N/Aas regular variables using the :FIELDS import tag. (Note that this still
1N/Aoverrides your core functions.) Access these fields as variables named
1N/Awith a preceding C<gr_>. Thus, C<$group_obj-E<gt>gid()> corresponds
1N/Ato $gr_gid if you import the fields. Array references are available as
1N/Aregular array variables, so C<@{ $group_obj-E<gt>members() }> would be
1N/Asimply @gr_members.
1N/A
1N/AThe getpw() function is a simple front-end that forwards
1N/Aa numeric argument to getpwuid() and the rest to getpwnam().
1N/A
1N/ATo access this functionality without the core overrides,
1N/Apass the C<use> an empty import list, and then access
1N/Afunction functions with their full qualified names.
1N/AOn the other hand, the built-ins are still available
1N/Avia the C<CORE::> pseudo-package.
1N/A
1N/A=head1 NOTE
1N/A
1N/AWhile this class is currently implemented using the Class::Struct
1N/Amodule to build a struct-like class, you shouldn't rely upon this.
1N/A
1N/A=head1 AUTHOR
1N/A
1N/ATom Christiansen