line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Getopt::Simple; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Name: |
4
|
|
|
|
|
|
|
# Getopt::Simple. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Documentation: |
7
|
|
|
|
|
|
|
# POD-style documentation is at the end. Extract it with pod2html.*. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Tabs: |
10
|
|
|
|
|
|
|
# 4 spaces || die. |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# Author: |
13
|
|
|
|
|
|
|
# Ron Savage |
14
|
|
|
|
|
|
|
# Home page: http://savage.net.au/index.html |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# Licence: |
17
|
|
|
|
|
|
|
# Australian copyright (c) 1999-2002 Ron Savage. |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
# All Programs of mine are 'OSI Certified Open Source Software'; |
20
|
|
|
|
|
|
|
# you can redistribute them and/or modify them under the terms of |
21
|
|
|
|
|
|
|
# The Artistic License, a copy of which is available at: |
22
|
|
|
|
|
|
|
# http://www.opensource.org/licenses/index.html |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
|
23075
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
25
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
26
|
1
|
|
|
1
|
|
5
|
use vars qw($fieldWidth $switch @ISA @EXPORT @EXPORT_OK); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
101
|
|
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
1
|
|
1317
|
use Getopt::Long; |
|
1
|
|
|
|
|
14825
|
|
|
1
|
|
|
|
|
6
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
require Exporter; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
35
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
36
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
@EXPORT = qw(); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
@EXPORT_OK = qw($switch); # An alias for $$self{'switch'}. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$fieldWidth = 25; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
our $VERSION = '1.52'; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Preloaded methods go here. |
47
|
|
|
|
|
|
|
# -------------------------------------------------------------------------- |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub byOrder |
50
|
|
|
|
|
|
|
{ |
51
|
0
|
|
|
0
|
0
|
|
my($self) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$$self{'default'}{$a}{'order'} <=> $$self{'default'}{$b}{'order'}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# -------------------------------------------------------------------------- |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub dumpOptions |
59
|
|
|
|
|
|
|
{ |
60
|
0
|
|
|
0
|
0
|
|
my($self) = @_; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
print $self -> pad('Option'), "Value\n"; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
for (sort byOrder keys(%{$$self{'switch'} }) ) |
|
0
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
{ |
66
|
0
|
0
|
|
|
|
|
if (ref($$self{'switch'}{$_}) eq 'ARRAY') |
67
|
|
|
|
|
|
|
{ |
68
|
0
|
|
|
|
|
|
print $self -> pad("-$_"), '(', join(', ', @{$$self{'switch'}{$_} }), ")\n"; |
|
0
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
else |
71
|
|
|
|
|
|
|
{ |
72
|
0
|
|
|
|
|
|
print $self -> pad("-$_"), "$$self{'switch'}{$_}\n"; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
print "\n"; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
} # End of dumpOptions. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# -------------------------------------------------------------------------- |
81
|
|
|
|
|
|
|
# Return: |
82
|
|
|
|
|
|
|
# 0 -> Error. |
83
|
|
|
|
|
|
|
# 1 -> Ok. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub getOptions |
86
|
|
|
|
|
|
|
{ |
87
|
0
|
0
|
|
0
|
0
|
|
push(@_, 0) if ($#_ == 2); # Default for $ignoreCase is 0. |
88
|
0
|
0
|
|
|
|
|
push(@_, 1) if ($#_ == 3); # Default for $helpThenExit is 1. |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my($self, $default, $helpText, $ignoreCase, $helpThenExit) = @_; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$$self{'default'} = $default; |
93
|
0
|
|
|
|
|
|
$$self{'helpText'} = $helpText; |
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
Getopt::Long::Configure($ignoreCase ? 'ignore_case' : 'no_ignore_case'); |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
for (keys(%{$$self{'default'} }) ) |
|
0
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
{ |
99
|
0
|
|
|
|
|
|
push(@{$$self{'type'} }, "$_$$self{'default'}{$_}{'type'}"); |
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my($result) = GetOptions($$self{'switch'}, @{$$self{'type'} }); |
|
0
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
|
if ($$self{'switch'}{'help'}) |
105
|
|
|
|
|
|
|
{ |
106
|
0
|
|
|
|
|
|
$self -> helpOptions(); |
107
|
0
|
0
|
|
|
|
|
exit(0) if ($helpThenExit); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
for (keys(%{$$self{'default'} }) ) |
|
0
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
{ |
112
|
0
|
0
|
|
|
|
|
if (ref($$self{'switch'}{$_}) eq 'ARRAY') |
113
|
|
|
|
|
|
|
{ |
114
|
0
|
0
|
|
|
|
|
$$self{'switch'}{$_} = [split(/\s+/, $$self{'default'}{$_}{'default'})] if (! defined $$self{'switch'}{$_}); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
else |
117
|
|
|
|
|
|
|
{ |
118
|
0
|
0
|
|
|
|
|
$$self{'switch'}{$_} = $$self{'default'}{$_}{'default'} if (! defined $$self{'switch'}{$_}); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
$result; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
} # End of getOptions. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# -------------------------------------------------------------------------- |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub helpOptions |
129
|
|
|
|
|
|
|
{ |
130
|
0
|
|
|
0
|
0
|
|
my($self) = @_; |
131
|
|
|
|
|
|
|
|
132
|
0
|
0
|
|
|
|
|
print "$$self{'helpText'}\n" if ($$self{'helpText'}); |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
print $self -> pad('Option'), $self -> pad('Environment var'), "Default\n"; |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
for (sort byOrder keys(%{$$self{'default'} }) ) |
|
0
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
{ |
138
|
0
|
|
|
|
|
|
print $self -> pad("-$_"), $self -> pad("$$self{'default'}{$_}{'env'}"); |
139
|
|
|
|
|
|
|
|
140
|
0
|
0
|
|
|
|
|
if (ref($$self{'default'}{$_}{'default'}) eq 'ARRAY') |
141
|
|
|
|
|
|
|
{ |
142
|
0
|
|
|
|
|
|
print '(', join(', ', @{$$self{'default'}{$_}{'default'} }), ")\n"; |
|
0
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
else |
145
|
|
|
|
|
|
|
{ |
146
|
0
|
|
|
|
|
|
print "$$self{'default'}{$_}{'default'}\n"; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
0
|
0
|
0
|
|
|
|
print "\t$$self{'default'}{$_}{'verbose'}\n" |
150
|
|
|
|
|
|
|
if (defined($$self{'default'}{$_}{'verbose'}) && |
151
|
|
|
|
|
|
|
$$self {'default'}{$_}{'verbose'} ne ''); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
print "\n"; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
} # End of helpOptions. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
#------------------------------------------------------------------- |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub new |
161
|
|
|
|
|
|
|
{ |
162
|
0
|
|
|
0
|
0
|
|
my($class) = @_; |
163
|
0
|
|
0
|
|
|
|
$class = ref($class) || $class; |
164
|
0
|
|
|
|
|
|
my($self) = {}; |
165
|
0
|
|
|
|
|
|
$$self{'default'} = {}; |
166
|
0
|
|
|
|
|
|
$$self{'helpText'} = ''; |
167
|
0
|
|
|
|
|
|
$$self{'switch'} = {}; |
168
|
0
|
|
|
|
|
|
$switch = $$self{'switch'}; # An alias for $$self{'switch'}. |
169
|
0
|
|
|
|
|
|
$$self{'type'} = []; |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
return bless $self, $class; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
} # End of new. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# -------------------------------------------------------------------------- |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub pad |
178
|
|
|
|
|
|
|
{ |
179
|
0
|
|
|
0
|
0
|
|
my($self, $field) = @_; |
180
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
|
sprintf "%-${fieldWidth}s", $field; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
} # End of pad. |
184
|
|
|
|
|
|
|
# -------------------------------------------------------------------------- |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
1; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
__END__ |