line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#============================================================================ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# AppConfig.pm |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Perl5 module for reading and parsing configuration files and command line |
6
|
|
|
|
|
|
|
# arguments. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# Written by Andy Wardley |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Copyright (C) 1997-2007 Andy Wardley. All Rights Reserved. |
11
|
|
|
|
|
|
|
# Copyright (C) 1997,1998 Canon Research Centre Europe Ltd. |
12
|
|
|
|
|
|
|
#========================================================================== |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package AppConfig; |
15
|
|
|
|
|
|
|
|
16
|
13
|
|
|
13
|
|
60654
|
use strict; |
|
13
|
|
|
|
|
27
|
|
|
13
|
|
|
|
|
500
|
|
17
|
13
|
|
|
13
|
|
57
|
use warnings; |
|
13
|
|
|
|
|
16
|
|
|
13
|
|
|
|
|
425
|
|
18
|
13
|
|
|
13
|
|
53
|
use base 'Exporter'; |
|
13
|
|
|
|
|
16
|
|
|
13
|
|
|
|
|
1591
|
|
19
|
|
|
|
|
|
|
our $VERSION = '1.69'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# variable expansion constants |
22
|
13
|
|
|
13
|
|
67
|
use constant EXPAND_NONE => 0; |
|
13
|
|
|
|
|
15
|
|
|
13
|
|
|
|
|
1033
|
|
23
|
13
|
|
|
13
|
|
58
|
use constant EXPAND_VAR => 1; |
|
13
|
|
|
|
|
17
|
|
|
13
|
|
|
|
|
607
|
|
24
|
13
|
|
|
13
|
|
54
|
use constant EXPAND_UID => 2; |
|
13
|
|
|
|
|
16
|
|
|
13
|
|
|
|
|
539
|
|
25
|
13
|
|
|
13
|
|
55
|
use constant EXPAND_ENV => 4; |
|
13
|
|
|
|
|
17
|
|
|
13
|
|
|
|
|
1256
|
|
26
|
13
|
|
|
13
|
|
62
|
use constant EXPAND_ALL => EXPAND_VAR | EXPAND_UID | EXPAND_ENV; |
|
13
|
|
|
|
|
16
|
|
|
13
|
|
|
|
|
760
|
|
27
|
13
|
|
|
13
|
|
59
|
use constant EXPAND_WARN => 8; |
|
13
|
|
|
|
|
18
|
|
|
13
|
|
|
|
|
633
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# argument count types |
30
|
13
|
|
|
13
|
|
168
|
use constant ARGCOUNT_NONE => 0; |
|
13
|
|
|
|
|
19
|
|
|
13
|
|
|
|
|
575
|
|
31
|
13
|
|
|
13
|
|
56
|
use constant ARGCOUNT_ONE => 1; |
|
13
|
|
|
|
|
16
|
|
|
13
|
|
|
|
|
514
|
|
32
|
13
|
|
|
13
|
|
63
|
use constant ARGCOUNT_LIST => 2; |
|
13
|
|
|
|
|
23
|
|
|
13
|
|
|
|
|
503
|
|
33
|
13
|
|
|
13
|
|
61
|
use constant ARGCOUNT_HASH => 3; |
|
13
|
|
|
|
|
20
|
|
|
13
|
|
|
|
|
7676
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Exporter tagsets |
36
|
|
|
|
|
|
|
our @EXPAND = qw( |
37
|
|
|
|
|
|
|
EXPAND_NONE |
38
|
|
|
|
|
|
|
EXPAND_VAR |
39
|
|
|
|
|
|
|
EXPAND_UID |
40
|
|
|
|
|
|
|
EXPAND_ENV |
41
|
|
|
|
|
|
|
EXPAND_ALL |
42
|
|
|
|
|
|
|
EXPAND_WARN |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
our @ARGCOUNT = qw( |
46
|
|
|
|
|
|
|
ARGCOUNT_NONE |
47
|
|
|
|
|
|
|
ARGCOUNT_ONE |
48
|
|
|
|
|
|
|
ARGCOUNT_LIST |
49
|
|
|
|
|
|
|
ARGCOUNT_HASH |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
our @EXPORT_OK = ( @EXPAND, @ARGCOUNT ); |
53
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
54
|
|
|
|
|
|
|
expand => [ @EXPAND ], |
55
|
|
|
|
|
|
|
argcount => [ @ARGCOUNT ], |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
our $AUTOLOAD; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
require AppConfig::State; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
62
|
|
|
|
|
|
|
# new(\%config, @vars) |
63
|
|
|
|
|
|
|
# |
64
|
|
|
|
|
|
|
# Module constructor. All parameters passed are forwarded onto the |
65
|
|
|
|
|
|
|
# AppConfig::State constructor. Returns a reference to a newly created |
66
|
|
|
|
|
|
|
# AppConfig object. |
67
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub new { |
70
|
5
|
|
|
5
|
0
|
1723
|
my $class = shift; |
71
|
5
|
|
|
|
|
54
|
bless { |
72
|
|
|
|
|
|
|
STATE => AppConfig::State->new(@_) |
73
|
|
|
|
|
|
|
}, $class; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
78
|
|
|
|
|
|
|
# file(@files) |
79
|
|
|
|
|
|
|
# |
80
|
|
|
|
|
|
|
# The file() method is called to parse configuration files. An |
81
|
|
|
|
|
|
|
# AppConfig::File object is instantiated and stored internally for |
82
|
|
|
|
|
|
|
# use in subsequent calls to file(). |
83
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub file { |
86
|
3
|
|
|
3
|
0
|
993
|
my $self = shift; |
87
|
3
|
|
|
|
|
15
|
my $state = $self->{ STATE }; |
88
|
3
|
|
|
|
|
6
|
my $file; |
89
|
|
|
|
|
|
|
|
90
|
3
|
|
|
|
|
1946
|
require AppConfig::File; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# create an AppConfig::File object if one isn't defined |
93
|
3
|
|
33
|
|
|
45
|
$file = $self->{ FILE } ||= AppConfig::File->new($state); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# call on the AppConfig::File object to process files. |
96
|
3
|
|
|
|
|
14
|
$file->parse(@_); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
101
|
|
|
|
|
|
|
# args(\@args) |
102
|
|
|
|
|
|
|
# |
103
|
|
|
|
|
|
|
# The args() method is called to parse command line arguments. An |
104
|
|
|
|
|
|
|
# AppConfig::Args object is instantiated and then stored internally for |
105
|
|
|
|
|
|
|
# use in subsequent calls to args(). |
106
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub args { |
109
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
110
|
0
|
|
|
|
|
0
|
my $state = $self->{ STATE }; |
111
|
0
|
|
|
|
|
0
|
my $args; |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
0
|
require AppConfig::Args; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# create an AppConfig::Args object if one isn't defined |
116
|
0
|
|
0
|
|
|
0
|
$args = $self->{ ARGS } ||= AppConfig::Args->new($state); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# call on the AppConfig::Args object to process arguments. |
119
|
0
|
|
|
|
|
0
|
$args->parse(shift); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
124
|
|
|
|
|
|
|
# getopt(@config, \@args) |
125
|
|
|
|
|
|
|
# |
126
|
|
|
|
|
|
|
# The getopt() method is called to parse command line arguments. The |
127
|
|
|
|
|
|
|
# AppConfig::Getopt module is require()'d and an AppConfig::Getopt object |
128
|
|
|
|
|
|
|
# is created to parse the arguments. |
129
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub getopt { |
132
|
4
|
|
|
4
|
0
|
369
|
my $self = shift; |
133
|
4
|
|
|
|
|
24
|
my $state = $self->{ STATE }; |
134
|
4
|
|
|
|
|
6
|
my $getopt; |
135
|
|
|
|
|
|
|
|
136
|
4
|
|
|
|
|
1223
|
require AppConfig::Getopt; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# create an AppConfig::Getopt object if one isn't defined |
139
|
4
|
|
66
|
|
|
40
|
$getopt = $self->{ GETOPT } ||= AppConfig::Getopt->new($state); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# call on the AppConfig::Getopt object to process arguments. |
142
|
4
|
|
|
|
|
20
|
$getopt->parse(@_); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
147
|
|
|
|
|
|
|
# cgi($query) |
148
|
|
|
|
|
|
|
# |
149
|
|
|
|
|
|
|
# The cgi() method is called to parse a CGI query string. An |
150
|
|
|
|
|
|
|
# AppConfig::CGI object is instantiated and then stored internally for |
151
|
|
|
|
|
|
|
# use in subsequent calls to args(). |
152
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub cgi { |
155
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
156
|
0
|
|
|
|
|
0
|
my $state = $self->{ STATE }; |
157
|
0
|
|
|
|
|
0
|
my $cgi; |
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
0
|
require AppConfig::CGI; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# create an AppConfig::CGI object if one isn't defined |
162
|
0
|
|
0
|
|
|
0
|
$cgi = $self->{ CGI } ||= AppConfig::CGI->new($state); |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
# call on the AppConfig::CGI object to process a query. |
165
|
0
|
|
|
|
|
0
|
$cgi->parse(shift); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
169
|
|
|
|
|
|
|
# AUTOLOAD |
170
|
|
|
|
|
|
|
# |
171
|
|
|
|
|
|
|
# Autoload function called whenever an unresolved object method is |
172
|
|
|
|
|
|
|
# called. All methods are delegated to the $self->{ STATE } |
173
|
|
|
|
|
|
|
# AppConfig::State object. |
174
|
|
|
|
|
|
|
# |
175
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub AUTOLOAD { |
178
|
29
|
|
|
29
|
|
1381
|
my $self = shift; |
179
|
29
|
|
|
|
|
29
|
my $method; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# splat the leading package name |
182
|
29
|
|
|
|
|
166
|
($method = $AUTOLOAD) =~ s/.*:://; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# ignore destructor |
185
|
29
|
50
|
|
|
|
84
|
$method eq 'DESTROY' && return; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
# delegate method call to AppConfig::State object in $self->{ STATE } |
188
|
29
|
|
|
|
|
205
|
$self->{ STATE }->$method(@_); |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
1; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
__END__ |