line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#============================================================================ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# AppConfig::Sys.pm |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Perl5 module providing platform-specific information and operations as |
6
|
|
|
|
|
|
|
# required by other AppConfig::* modules. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# Written by Andy Wardley |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Copyright (C) 1997-2003 Andy Wardley. All Rights Reserved. |
11
|
|
|
|
|
|
|
# Copyright (C) 1997,1998 Canon Research Centre Europe Ltd. |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# $Id: Sys.pm,v 1.61 2004/02/04 10:11:23 abw Exp $ |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
#============================================================================ |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package AppConfig::Sys; |
18
|
3
|
|
|
3
|
|
502
|
use 5.006; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
96
|
|
19
|
3
|
|
|
3
|
|
11
|
use strict; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
86
|
|
20
|
3
|
|
|
3
|
|
10
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
85
|
|
21
|
3
|
|
|
3
|
|
1481
|
use POSIX qw( getpwnam getpwuid ); |
|
3
|
|
|
|
|
13771
|
|
|
3
|
|
|
|
|
13
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '1.71'; |
24
|
|
|
|
|
|
|
our ($AUTOLOAD, $OS, %CAN, %METHOD); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
BEGIN { |
28
|
|
|
|
|
|
|
# define the methods that may be available |
29
|
3
|
50
|
|
3
|
|
2923
|
if($^O =~ m/win32/i) { |
30
|
|
|
|
|
|
|
$METHOD{ getpwuid } = sub { |
31
|
|
|
|
|
|
|
return wantarray() |
32
|
0
|
0
|
|
|
|
0
|
? ( (undef) x 7, getlogin() ) |
33
|
|
|
|
|
|
|
: getlogin(); |
34
|
0
|
|
|
|
|
0
|
}; |
35
|
|
|
|
|
|
|
$METHOD{ getpwnam } = sub { |
36
|
0
|
|
|
|
|
0
|
die("Can't getpwnam on win32"); |
37
|
0
|
|
|
|
|
0
|
}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else |
40
|
|
|
|
|
|
|
{ |
41
|
|
|
|
|
|
|
$METHOD{ getpwuid } = sub { |
42
|
3
|
50
|
|
|
|
19
|
getpwuid( defined $_[0] ? shift : $< ); |
43
|
3
|
|
|
|
|
12
|
}; |
44
|
|
|
|
|
|
|
$METHOD{ getpwnam } = sub { |
45
|
3
|
50
|
|
|
|
21
|
getpwnam( defined $_[0] ? shift : '' ); |
46
|
3
|
|
|
|
|
7
|
}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# try out each METHOD to see if it's supported on this platform; |
50
|
|
|
|
|
|
|
# it's important we do this before defining AUTOLOAD which would |
51
|
|
|
|
|
|
|
# otherwise catch the unresolved call |
52
|
3
|
|
|
|
|
7
|
foreach my $method (keys %METHOD) { |
53
|
6
|
|
|
|
|
9
|
eval { &{ $METHOD{ $method } }() }; |
|
6
|
|
|
|
|
5
|
|
|
6
|
|
|
|
|
18
|
|
54
|
6
|
|
|
|
|
4098
|
$CAN{ $method } = ! $@; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
61
|
|
|
|
|
|
|
# new($os) |
62
|
|
|
|
|
|
|
# |
63
|
|
|
|
|
|
|
# Module constructor. An optional operating system string may be passed |
64
|
|
|
|
|
|
|
# to explicitly define the platform type. |
65
|
|
|
|
|
|
|
# |
66
|
|
|
|
|
|
|
# Returns a reference to a newly created AppConfig::Sys object. |
67
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub new { |
70
|
4
|
|
|
4
|
0
|
23
|
my $class = shift; |
71
|
|
|
|
|
|
|
|
72
|
4
|
|
|
|
|
14
|
my $self = { |
73
|
|
|
|
|
|
|
METHOD => \%METHOD, |
74
|
|
|
|
|
|
|
CAN => \%CAN, |
75
|
|
|
|
|
|
|
}; |
76
|
|
|
|
|
|
|
|
77
|
4
|
|
|
|
|
9
|
bless $self, $class; |
78
|
|
|
|
|
|
|
|
79
|
4
|
|
|
|
|
11
|
$self->_configure(@_); |
80
|
|
|
|
|
|
|
|
81
|
4
|
|
|
|
|
11
|
return $self; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
86
|
|
|
|
|
|
|
# AUTOLOAD |
87
|
|
|
|
|
|
|
# |
88
|
|
|
|
|
|
|
# Autoload function called whenever an unresolved object method is |
89
|
|
|
|
|
|
|
# called. If the method name relates to a METHODS entry, then it is |
90
|
|
|
|
|
|
|
# called iff the corresponding CAN_$method is set true. If the |
91
|
|
|
|
|
|
|
# method name relates to a CAN_$method value then that is returned. |
92
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub AUTOLOAD { |
95
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
96
|
0
|
|
|
|
|
0
|
my $method; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# splat the leading package name |
100
|
0
|
|
|
|
|
0
|
($method = $AUTOLOAD) =~ s/.*:://; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# ignore destructor |
103
|
0
|
0
|
|
|
|
0
|
$method eq 'DESTROY' && return; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# can_method() |
106
|
0
|
0
|
0
|
|
|
0
|
if ($method =~ s/^can_//i && exists $self->{ CAN }->{ $method }) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
107
|
0
|
|
|
|
|
0
|
return $self->{ CAN }->{ $method }; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
# method() |
110
|
|
|
|
|
|
|
elsif (exists $self->{ METHOD }->{ $method }) { |
111
|
0
|
0
|
|
|
|
0
|
if ($self->{ CAN }->{ $method }) { |
112
|
0
|
|
|
|
|
0
|
return &{ $self->{ METHOD }->{ $method } }(@_); |
|
0
|
|
|
|
|
0
|
|
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
else { |
115
|
0
|
|
|
|
|
0
|
return undef; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
# variable |
119
|
|
|
|
|
|
|
elsif (exists $self->{ uc $method }) { |
120
|
0
|
|
|
|
|
0
|
return $self->{ uc $method }; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
else { |
123
|
0
|
|
|
|
|
0
|
warn("AppConfig::Sys->", $method, "(): no such method or variable\n"); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
0
|
return undef; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
131
|
|
|
|
|
|
|
# _configure($os) |
132
|
|
|
|
|
|
|
# |
133
|
|
|
|
|
|
|
# Uses the first parameter, $os, the package variable $AppConfig::Sys::OS, |
134
|
|
|
|
|
|
|
# the value of $^O, or as a last resort, the value of |
135
|
|
|
|
|
|
|
# $Config::Config('osname') to determine the current operating |
136
|
|
|
|
|
|
|
# system/platform. Sets internal variables accordingly. |
137
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub _configure { |
140
|
4
|
|
|
4
|
|
7
|
my $self = shift; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# operating system may be defined as a parameter or in $OS |
143
|
4
|
|
66
|
|
|
18
|
my $os = shift || $OS; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
147
|
|
|
|
|
|
|
# The following was lifted (and adapated slightly) from Lincoln Stein's |
148
|
|
|
|
|
|
|
# CGI.pm module, version 2.36... |
149
|
|
|
|
|
|
|
# |
150
|
|
|
|
|
|
|
# FIGURE OUT THE OS WE'RE RUNNING UNDER |
151
|
|
|
|
|
|
|
# Some systems support the $^O variable. If not |
152
|
|
|
|
|
|
|
# available then require() the Config library |
153
|
4
|
100
|
|
|
|
9
|
unless ($os) { |
154
|
3
|
50
|
|
|
|
18
|
unless ($os = $^O) { |
155
|
0
|
|
|
|
|
0
|
require Config; |
156
|
0
|
|
|
|
|
0
|
$os = $Config::Config{'osname'}; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
4
|
100
|
|
|
|
37
|
if ($os =~ /win32/i) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
160
|
1
|
|
|
|
|
2
|
$os = 'WINDOWS'; |
161
|
|
|
|
|
|
|
} elsif ($os =~ /vms/i) { |
162
|
0
|
|
|
|
|
0
|
$os = 'VMS'; |
163
|
|
|
|
|
|
|
} elsif ($os =~ /mac/i) { |
164
|
0
|
|
|
|
|
0
|
$os = 'MACINTOSH'; |
165
|
|
|
|
|
|
|
} elsif ($os =~ /os2/i) { |
166
|
0
|
|
|
|
|
0
|
$os = 'OS2'; |
167
|
|
|
|
|
|
|
} else { |
168
|
3
|
|
|
|
|
5
|
$os = 'UNIX'; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
# The path separator is a slash, backslash or semicolon, depending |
173
|
|
|
|
|
|
|
# on the platform. |
174
|
4
|
|
|
|
|
20
|
my $ps = { |
175
|
|
|
|
|
|
|
UNIX => '/', |
176
|
|
|
|
|
|
|
OS2 => '\\', |
177
|
|
|
|
|
|
|
WINDOWS => '\\', |
178
|
|
|
|
|
|
|
MACINTOSH => ':', |
179
|
|
|
|
|
|
|
VMS => '\\' |
180
|
|
|
|
|
|
|
}->{ $os }; |
181
|
|
|
|
|
|
|
# |
182
|
|
|
|
|
|
|
# Thanks Lincoln! |
183
|
|
|
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
186
|
4
|
|
|
|
|
24
|
$self->{ OS } = $os; |
187
|
4
|
|
|
|
|
9
|
$self->{ PATHSEP } = $ps; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
192
|
|
|
|
|
|
|
# _dump() |
193
|
|
|
|
|
|
|
# |
194
|
|
|
|
|
|
|
# Dump internals for debugging. |
195
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub _dump { |
198
|
0
|
|
|
0
|
|
|
my $self = shift; |
199
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
print "=" x 71, "\n"; |
201
|
0
|
|
|
|
|
|
print "Status of AppConfig::Sys (Version $VERSION) object: $self\n"; |
202
|
0
|
|
|
|
|
|
print " Operating System : ", $self->{ OS }, "\n"; |
203
|
0
|
|
|
|
|
|
print " Path Separator : ", $self->{ PATHSEP }, "\n"; |
204
|
0
|
|
|
|
|
|
print " Available methods :\n"; |
205
|
0
|
|
|
|
|
|
foreach my $can (keys %{ $self->{ CAN } }) { |
|
0
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
|
printf "%20s : ", $can; |
207
|
0
|
0
|
|
|
|
|
print $self->{ CAN }->{ $can } ? "yes" : "no", "\n"; |
208
|
|
|
|
|
|
|
} |
209
|
0
|
|
|
|
|
|
print "=" x 71, "\n"; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
1; |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
__END__ |