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