6 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
8 @EXPORT = qw(getgrent getgrgid getgrnam getgr);
9 @EXPORT_OK = qw($gr_name $gr_gid $gr_passwd $gr_mem @gr_members);
10 %EXPORT_TAGS = ( FIELDS => [ @EXPORT_OK, @EXPORT ] );
14 use Class::Template qw(struct);
15 struct 'User::grent' => [
25 ($gr_name, $gr_passwd, $gr_gid) = @$gob[0,1,2] = @_[0,1,2];
26 @gr_members = @{$gob->[3]} = split ' ', $_[3];
30 sub getgrent ( ) { populate(CORE::getgrent()) }
31 sub getgrnam ($) { populate(CORE::getgrnam(shift)) }
32 sub getgrgid ($) { populate(CORE::getgrgid(shift)) }
33 sub getgr ($) { ($_[0] =~ /^\d+/) ? &getgrgid : &getgrnam }
40 User::grent - by-name interface to Perl's built-in getgr*() functions
45 $gr = getgrgid(0) or die "No group zero";
46 if ( $gr->name eq 'wheel' && @{$gr->members} > 1 ) {
47 print "gid zero name wheel, with other members";
50 use User::grent qw(:FIELDS;
51 getgrgid(0) or die "No group zero";
52 if ( $gr_name eq 'wheel' && @gr_members > 1 ) {
53 print "gid zero name wheel, with other members";
56 $gr = getgr($whoever);
60 This module's default exports override the core getgrent(), getgruid(),
61 and getgrnam() functions, replacing them with versions that return
62 "User::grent" objects. This object has methods that return the similarly
63 named structure field name from the C's passwd structure from F<grp.h>;
64 namely name, passwd, gid, and members (not mem). The first three
65 return scalars, the last an array reference.
67 You may also import all the structure fields directly into your namespace
68 as regular variables using the :FIELDS import tag. (Note that this still
69 overrides your core functions.) Access these fields as variables named
70 with a preceding C<gr_>. Thus, C<$group_obj-E<gt>gid()> corresponds
71 to $gr_gid if you import the fields. Array references are available as
72 regular array variables, so C<@{ $group_obj-E<gt>members() }> would be
75 The getpw() funtion is a simple front-end that forwards
76 a numeric argument to getpwuid() and the rest to getpwnam().
78 To access this functionality without the core overrides,
79 pass the C<use> an empty import list, and then access
80 function functions with their full qualified names.
81 On the other hand, the built-ins are still available
82 via the C<CORE::> pseudo-package.
86 While this class is currently implemented using the Class::Template
87 module to build a struct-like class, you shouldn't rely upon this.