source: trunk/essentials/dev-lang/perl/lib/User/pwent.pm

Last change on this file was 3181, checked in by bird, 19 years ago

perl 5.8.8

File size: 9.6 KB
Line 
1package User::pwent;
2
3use 5.006;
4our $VERSION = '1.00';
5
6use strict;
7use warnings;
8
9use Config;
10use Carp;
11
12our(@EXPORT, @EXPORT_OK, %EXPORT_TAGS);
13BEGIN {
14 use Exporter ();
15 @EXPORT = qw(getpwent getpwuid getpwnam getpw);
16 @EXPORT_OK = qw(
17 pw_has
18
19 $pw_name $pw_passwd $pw_uid $pw_gid
20 $pw_gecos $pw_dir $pw_shell
21 $pw_expire $pw_change $pw_class
22 $pw_age
23 $pw_quota $pw_comment
24 $pw_expire
25
26 );
27 %EXPORT_TAGS = (
28 FIELDS => [ grep(/^\$pw_/, @EXPORT_OK), @EXPORT ],
29 ALL => [ @EXPORT, @EXPORT_OK ],
30 );
31}
32use vars grep /^\$pw_/, @EXPORT_OK;
33
34#
35# XXX: these mean somebody hacked this module's source
36# without understanding the underlying assumptions.
37#
38my $IE = "[INTERNAL ERROR]";
39
40# Class::Struct forbids use of @ISA
41sub import { goto &Exporter::import }
42
43use Class::Struct qw(struct);
44struct 'User::pwent' => [
45 name => '$', # pwent[0]
46 passwd => '$', # pwent[1]
47 uid => '$', # pwent[2]
48 gid => '$', # pwent[3]
49
50 # you'll only have one/none of these three
51 change => '$', # pwent[4]
52 age => '$', # pwent[4]
53 quota => '$', # pwent[4]
54
55 # you'll only have one/none of these two
56 comment => '$', # pwent[5]
57 class => '$', # pwent[5]
58
59 # you might not have this one
60 gecos => '$', # pwent[6]
61
62 dir => '$', # pwent[7]
63 shell => '$', # pwent[8]
64
65 # you might not have this one
66 expire => '$', # pwent[9]
67
68];
69
70
71# init our groks hash to be true if the built platform knew how
72# to do each struct pwd field that perl can ever under any circumstances
73# know about. we do not use /^pw_?/, but just the tails.
74sub _feature_init {
75 our %Groks; # whether build system knew how to do this feature
76 for my $feep ( qw{
77 pwage pwchange pwclass pwcomment
78 pwexpire pwgecos pwpasswd pwquota
79 }
80 )
81 {
82 my $short = $feep =~ /^pw(.*)/
83 ? $1
84 : do {
85 # not cluck, as we know we called ourselves,
86 # and a confession is probably imminent anyway
87 warn("$IE $feep is a funny struct pwd field");
88 $feep;
89 };
90
91 exists $Config{ "d_" . $feep }
92 || confess("$IE Configure doesn't d_$feep");
93 $Groks{$short} = defined $Config{ "d_" . $feep };
94 }
95 # assume that any that are left are always there
96 for my $feep (grep /^\$pw_/s, @EXPORT_OK) {
97 $feep =~ /^\$pw_(.*)/;
98 $Groks{$1} = 1 unless defined $Groks{$1};
99 }
100}
101
102# With arguments, reports whether one or more fields are all implemented
103# in the build machine's struct pwd pw_*. May be whitespace separated.
104# We do not use /^pw_?/, just the tails.
105#
106# Without arguments, returns the list of fields implemented on build
107# machine, space separated in scalar context.
108#
109# Takes exception to being asked whether this machine's struct pwd has
110# a field that Perl never knows how to provide under any circumstances.
111# If the module does this idiocy to itself, the explosion is noisier.