Filename | /usr/lib/x86_64-linux-gnu/perl-base/Getopt/Long.pm |
Statements | Executed 694 statements in 5.72ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 77µs | 272µs | GetOptionsFromArray | Getopt::Long::
5 | 1 | 1 | 60µs | 86µs | ParseOptionSpec | Getopt::Long::
6 | 1 | 1 | 54µs | 74µs | FindOption | Getopt::Long::
34 | 10 | 1 | 45µs | 45µs | CORE:match (opcode) | Getopt::Long::
16 | 3 | 1 | 33µs | 33µs | CORE:regcomp (opcode) | Getopt::Long::
2 | 2 | 1 | 16µs | 18µs | Configure | Getopt::Long::
1 | 1 | 1 | 13µs | 13µs | BEGIN@13 | main::
1 | 1 | 1 | 11µs | 88µs | import | Getopt::Long::
1 | 1 | 1 | 8µs | 30µs | BEGIN@1573 | Getopt::Long::CallBack::
1 | 1 | 1 | 6µs | 36µs | BEGIN@220 | Getopt::Long::
1 | 1 | 1 | 5µs | 7µs | BEGIN@15.7 | main::
1 | 1 | 1 | 5µs | 41µs | BEGIN@46 | Getopt::Long::
1 | 1 | 1 | 4µs | 19µs | BEGIN@20 | Getopt::Long::
1 | 1 | 1 | 4µs | 20µs | BEGIN@230 | Getopt::Long::
1 | 1 | 1 | 4µs | 23µs | BEGIN@16.8 | main::
1 | 1 | 1 | 4µs | 4µs | ConfigDefaults | Getopt::Long::
1 | 1 | 1 | 4µs | 4µs | GetOptions | Getopt::Long::
1 | 1 | 1 | 4µs | 10µs | BEGIN@26 | Getopt::Long::
1 | 1 | 1 | 3µs | 20µs | BEGIN@234 | Getopt::Long::
1 | 1 | 1 | 3µs | 10µs | BEGIN@23 | Getopt::Long::
1 | 1 | 1 | 3µs | 15µs | BEGIN@248 | Getopt::Long::
1 | 1 | 1 | 3µs | 29µs | BEGIN@49 | Getopt::Long::
1 | 1 | 1 | 3µs | 17µs | BEGIN@232 | Getopt::Long::
1 | 1 | 1 | 3µs | 16µs | BEGIN@249 | Getopt::Long::
1 | 1 | 1 | 3µs | 3µs | BEGIN@38 | Getopt::Long::
1 | 1 | 1 | 3µs | 15µs | BEGIN@237 | Getopt::Long::
1 | 1 | 1 | 3µs | 16µs | BEGIN@259 | Getopt::Long::
1 | 1 | 1 | 3µs | 18µs | BEGIN@47 | Getopt::Long::
1 | 1 | 1 | 3µs | 14µs | BEGIN@235 | Getopt::Long::
1 | 1 | 1 | 3µs | 14µs | BEGIN@236 | Getopt::Long::
1 | 1 | 1 | 3µs | 14µs | BEGIN@241 | Getopt::Long::
1 | 1 | 1 | 3µs | 15µs | BEGIN@238 | Getopt::Long::
1 | 1 | 1 | 3µs | 15µs | BEGIN@240 | Getopt::Long::
1 | 1 | 1 | 3µs | 18µs | BEGIN@27 | Getopt::Long::
1 | 1 | 1 | 2µs | 24µs | BEGIN@52 | Getopt::Long::
0 | 0 | 0 | 0s | 0s | given | Getopt::Long::CallBack::
0 | 0 | 0 | 0s | 0s | name | Getopt::Long::CallBack::
0 | 0 | 0 | 0s | 0s | new | Getopt::Long::CallBack::
0 | 0 | 0 | 0s | 0s | GetOptionsFromString | Getopt::Long::
0 | 0 | 0 | 0s | 0s | HelpMessage | Getopt::Long::
0 | 0 | 0 | 0s | 0s | OptCtl | Getopt::Long::
0 | 0 | 0 | 0s | 0s | configure | Getopt::Long::Parser::
0 | 0 | 0 | 0s | 0s | getoptions | Getopt::Long::Parser::
0 | 0 | 0 | 0s | 0s | getoptionsfromarray | Getopt::Long::Parser::
0 | 0 | 0 | 0s | 0s | new | Getopt::Long::Parser::
0 | 0 | 0 | 0s | 0s | VERSION | Getopt::Long::
0 | 0 | 0 | 0s | 0s | ValidValue | Getopt::Long::
0 | 0 | 0 | 0s | 0s | VersionMessage | Getopt::Long::
0 | 0 | 0 | 0s | 0s | config | Getopt::Long::
0 | 0 | 0 | 0s | 0s | setup_pa_args | Getopt::Long::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | #! perl | ||||
2 | |||||
3 | # Getopt::Long.pm -- Universal options parsing | ||||
4 | # Author : Johan Vromans | ||||
5 | # Created On : Tue Sep 11 15:00:12 1990 | ||||
6 | # Last Modified By: Johan Vromans | ||||
7 | # Last Modified On: Tue Aug 18 14:48:05 2020 | ||||
8 | # Update Count : 1739 | ||||
9 | # Status : Released | ||||
10 | |||||
11 | ################ Module Preamble ################ | ||||
12 | |||||
13 | 2 | 30µs | 1 | 13µs | # spent 13µs within main::BEGIN@13 which was called:
# once (13µs+0s) by main::BEGIN@32 at line 13 # spent 13µs making 1 call to main::BEGIN@13 |
14 | |||||
15 | 2 | 16µs | 2 | 9µs | # spent 7µs (5+2) within main::BEGIN@15.7 which was called:
# once (5µs+2µs) by main::BEGIN@32 at line 15 # spent 7µs making 1 call to main::BEGIN@15.7
# spent 2µs making 1 call to strict::import |
16 | 2 | 22µs | 2 | 41µs | # spent 23µs (4+19) within main::BEGIN@16.8 which was called:
# once (4µs+19µs) by main::BEGIN@32 at line 16 # spent 23µs making 1 call to main::BEGIN@16.8
# spent 19µs making 1 call to warnings::import |
17 | |||||
18 | package Getopt::Long; | ||||
19 | |||||
20 | 2 | 22µs | 2 | 33µs | # spent 19µs (4+14) within Getopt::Long::BEGIN@20 which was called:
# once (4µs+14µs) by main::BEGIN@32 at line 20 # spent 19µs making 1 call to Getopt::Long::BEGIN@20
# spent 14µs making 1 call to vars::import |
21 | 1 | 200ns | $VERSION = 2.52; | ||
22 | # For testing versions only. | ||||
23 | 2 | 15µs | 2 | 18µs | # spent 10µs (3+7) within Getopt::Long::BEGIN@23 which was called:
# once (3µs+7µs) by main::BEGIN@32 at line 23 # spent 10µs making 1 call to Getopt::Long::BEGIN@23
# spent 7µs making 1 call to vars::import |
24 | 1 | 300ns | $VERSION_STRING = "2.52"; | ||
25 | |||||
26 | 2 | 14µs | 2 | 16µs | # spent 10µs (4+6) within Getopt::Long::BEGIN@26 which was called:
# once (4µs+6µs) by main::BEGIN@32 at line 26 # spent 10µs making 1 call to Getopt::Long::BEGIN@26
# spent 6µs making 1 call to Exporter::import |
27 | 2 | 54µs | 2 | 34µs | # spent 18µs (3+16) within Getopt::Long::BEGIN@27 which was called:
# once (3µs+16µs) by main::BEGIN@32 at line 27 # spent 18µs making 1 call to Getopt::Long::BEGIN@27
# spent 16µs making 1 call to vars::import |
28 | 1 | 7µs | @ISA = qw(Exporter); | ||
29 | |||||
30 | # Exported subroutines. | ||||
31 | sub GetOptions(@); # always | ||||
32 | sub GetOptionsFromArray(@); # on demand | ||||
33 | sub GetOptionsFromString(@); # on demand | ||||
34 | sub Configure(@); # on demand | ||||
35 | sub HelpMessage(@); # on demand | ||||
36 | sub VersionMessage(@); # in demand | ||||
37 | |||||
38 | # spent 3µs within Getopt::Long::BEGIN@38 which was called:
# once (3µs+0s) by main::BEGIN@32 at line 43 | ||||
39 | # Init immediately so their contents can be used in the 'use vars' below. | ||||
40 | 1 | 700ns | @EXPORT = qw(&GetOptions $REQUIRE_ORDER $PERMUTE $RETURN_IN_ORDER); | ||
41 | 1 | 2µs | @EXPORT_OK = qw(&HelpMessage &VersionMessage &Configure | ||
42 | &GetOptionsFromArray &GetOptionsFromString); | ||||
43 | 1 | 18µs | 1 | 3µs | } # spent 3µs making 1 call to Getopt::Long::BEGIN@38 |
44 | |||||
45 | # User visible variables. | ||||
46 | 2 | 16µs | 2 | 78µs | # spent 41µs (5+36) within Getopt::Long::BEGIN@46 which was called:
# once (5µs+36µs) by main::BEGIN@32 at line 46 # spent 41µs making 1 call to Getopt::Long::BEGIN@46
# spent 36µs making 1 call to vars::import |
47 | 2 | 19µs | 2 | 34µs | # spent 18µs (3+16) within Getopt::Long::BEGIN@47 which was called:
# once (3µs+16µs) by main::BEGIN@32 at line 47 # spent 18µs making 1 call to Getopt::Long::BEGIN@47
# spent 16µs making 1 call to vars::import |
48 | # Deprecated visible variables. | ||||
49 | 1 | 2µs | 1 | 26µs | # spent 29µs (3+26) within Getopt::Long::BEGIN@49 which was called:
# once (3µs+26µs) by main::BEGIN@32 at line 50 # spent 26µs making 1 call to vars::import |
50 | 1 | 13µs | 1 | 29µs | $passthrough); # spent 29µs making 1 call to Getopt::Long::BEGIN@49 |
51 | # Official invisible variables. | ||||
52 | 2 | 431µs | 2 | 46µs | # spent 24µs (2+22) within Getopt::Long::BEGIN@52 which was called:
# once (2µs+22µs) by main::BEGIN@32 at line 52 # spent 24µs making 1 call to Getopt::Long::BEGIN@52
# spent 22µs making 1 call to vars::import |
53 | |||||
54 | # Really invisible variables. | ||||
55 | 1 | 100ns | my $bundling_values; | ||
56 | |||||
57 | # Public subroutines. | ||||
58 | sub config(@); # deprecated name | ||||
59 | |||||
60 | # Private subroutines. | ||||
61 | sub ConfigDefaults(); | ||||
62 | sub ParseOptionSpec($$); | ||||
63 | sub OptCtl($); | ||||
64 | sub FindOption($$$$$); | ||||
65 | sub ValidValue ($$$$$); | ||||
66 | |||||
67 | ################ Local Variables ################ | ||||
68 | |||||
69 | # $requested_version holds the version that was mentioned in the 'use' | ||||
70 | # or 'require', if any. It can be used to enable or disable specific | ||||
71 | # features. | ||||
72 | 1 | 100ns | my $requested_version = 0; | ||
73 | |||||
74 | ################ Resident subroutines ################ | ||||
75 | |||||
76 | # spent 4µs within Getopt::Long::ConfigDefaults which was called:
# once (4µs+0s) by main::BEGIN@32 at line 131 | ||||
77 | # Handle POSIX compliancy. | ||||
78 | 1 | 1µs | if ( defined $ENV{"POSIXLY_CORRECT"} ) { | ||
79 | $genprefix = "(--|-)"; | ||||
80 | $autoabbrev = 0; # no automatic abbrev of options | ||||
81 | $bundling = 0; # no bundling of single letter switches | ||||
82 | $getopt_compat = 0; # disallow '+' to start options | ||||
83 | $order = $REQUIRE_ORDER; | ||||
84 | } | ||||
85 | else { | ||||
86 | 1 | 200ns | $genprefix = "(--|-|\\+)"; | ||
87 | 1 | 200ns | $autoabbrev = 1; # automatic abbrev of options | ||
88 | 1 | 200ns | $bundling = 0; # bundling off by default | ||
89 | 1 | 100ns | $getopt_compat = 1; # allow '+' to start options | ||
90 | 1 | 200ns | $order = $PERMUTE; | ||
91 | } | ||||
92 | # Other configurable settings. | ||||
93 | 1 | 200ns | $debug = 0; # for debugging | ||
94 | 1 | 200ns | $error = 0; # error tally | ||
95 | 1 | 200ns | $ignorecase = 1; # ignore case when matching options | ||
96 | 1 | 100ns | $passthrough = 0; # leave unrecognized options alone | ||
97 | 1 | 100ns | $gnu_compat = 0; # require --opt=val if value is optional | ||
98 | 1 | 200ns | $longprefix = "(--)"; # what does a long prefix look like | ||
99 | 1 | 2µs | $bundling_values = 0; # no bundling of values | ||
100 | } | ||||
101 | |||||
102 | # Override import. | ||||
103 | # spent 88µs (11+77) within Getopt::Long::import which was called:
# once (11µs+77µs) by main::BEGIN@32 at line 32 of /home/hejohns/documentsNoSync/22f/490/gradescope-utils/bin/split.pl | ||||
104 | 1 | 400ns | my $pkg = shift; # package | ||
105 | 1 | 300ns | my @syms = (); # symbols to import | ||
106 | 1 | 200ns | my @config = (); # configuration | ||
107 | 1 | 200ns | my $dest = \@syms; # symbols first | ||
108 | 1 | 600ns | for ( @_ ) { | ||
109 | 3 | 700ns | if ( $_ eq ':config' ) { | ||
110 | 1 | 200ns | $dest = \@config; # config next | ||
111 | 1 | 200ns | next; | ||
112 | } | ||||
113 | 2 | 600ns | push(@$dest, $_); # push | ||
114 | } | ||||
115 | # Hide one level and call super. | ||||
116 | 1 | 400ns | local $Exporter::ExportLevel = 1; | ||
117 | 1 | 100ns | push(@syms, qw(&GetOptions)) if @syms; # always export GetOptions | ||
118 | 1 | 100ns | $requested_version = 0; | ||
119 | 1 | 3µs | 1 | 64µs | $pkg->SUPER::import(@syms); # spent 64µs making 1 call to Exporter::import |
120 | # And configure. | ||||
121 | 1 | 3µs | 1 | 13µs | Configure(@config) if @config; # spent 13µs making 1 call to Getopt::Long::Configure |
122 | } | ||||
123 | |||||
124 | ################ Initialization ################ | ||||
125 | |||||
126 | # Values for $order. See GNU getopt.c for details. | ||||
127 | 1 | 400ns | ($REQUIRE_ORDER, $PERMUTE, $RETURN_IN_ORDER) = (0..2); | ||
128 | # Version major/minor numbers. | ||||
129 | 1 | 13µs | 1 | 9µs | ($major_version, $minor_version) = $VERSION =~ /^(\d+)\.(\d+)/; # spent 9µs making 1 call to Getopt::Long::CORE:match |
130 | |||||
131 | 1 | 800ns | 1 | 4µs | ConfigDefaults(); # spent 4µs making 1 call to Getopt::Long::ConfigDefaults |
132 | |||||
133 | ################ OO Interface ################ | ||||
134 | |||||
135 | package Getopt::Long::Parser; | ||||
136 | |||||
137 | # Store a copy of the default configuration. Since ConfigDefaults has | ||||
138 | # just been called, what we get from Configure is the default. | ||||
139 | 1 | 700ns | 1 | 5µs | my $default_config = do { # spent 5µs making 1 call to Getopt::Long::Configure |
140 | Getopt::Long::Configure () | ||||
141 | }; | ||||
142 | |||||
143 | sub new { | ||||
144 | my $that = shift; | ||||
145 | my $class = ref($that) || $that; | ||||
146 | my %atts = @_; | ||||
147 | |||||
148 | # Register the callers package. | ||||
149 | my $self = { caller_pkg => (caller)[0] }; | ||||
150 | |||||
151 | bless ($self, $class); | ||||
152 | |||||
153 | # Process config attributes. | ||||
154 | if ( defined $atts{config} ) { | ||||
155 | my $save = Getopt::Long::Configure ($default_config, @{$atts{config}}); | ||||
156 | $self->{settings} = Getopt::Long::Configure ($save); | ||||
157 | delete ($atts{config}); | ||||
158 | } | ||||
159 | # Else use default config. | ||||
160 | else { | ||||
161 | $self->{settings} = $default_config; | ||||
162 | } | ||||
163 | |||||
164 | if ( %atts ) { # Oops | ||||
165 | die(__PACKAGE__.": unhandled attributes: ". | ||||
166 | join(" ", sort(keys(%atts)))."\n"); | ||||
167 | } | ||||
168 | |||||
169 | $self; | ||||
170 | } | ||||
171 | |||||
172 | sub configure { | ||||
173 | my ($self) = shift; | ||||
174 | |||||
175 | # Restore settings, merge new settings in. | ||||
176 | my $save = Getopt::Long::Configure ($self->{settings}, @_); | ||||
177 | |||||
178 | # Restore orig config and save the new config. | ||||
179 | $self->{settings} = Getopt::Long::Configure ($save); | ||||
180 | } | ||||
181 | |||||
182 | sub getoptions { | ||||
183 | my ($self) = shift; | ||||
184 | |||||
185 | return $self->getoptionsfromarray(\@ARGV, @_); | ||||
186 | } | ||||
187 | |||||
188 | sub getoptionsfromarray { | ||||
189 | my ($self) = shift; | ||||
190 | |||||
191 | # Restore config settings. | ||||
192 | my $save = Getopt::Long::Configure ($self->{settings}); | ||||
193 | |||||
194 | # Call main routine. | ||||
195 | my $ret = 0; | ||||
196 | $Getopt::Long::caller = $self->{caller_pkg}; | ||||
197 | |||||
198 | eval { | ||||
199 | # Locally set exception handler to default, otherwise it will | ||||
200 | # be called implicitly here, and again explicitly when we try | ||||
201 | # to deliver the messages. | ||||
202 | local ($SIG{__DIE__}) = 'DEFAULT'; | ||||
203 | $ret = Getopt::Long::GetOptionsFromArray (@_); | ||||
204 | }; | ||||
205 | |||||
206 | # Restore saved settings. | ||||
207 | Getopt::Long::Configure ($save); | ||||
208 | |||||
209 | # Handle errors and return value. | ||||
210 | die ($@) if $@; | ||||
211 | return $ret; | ||||
212 | } | ||||
213 | |||||
214 | package Getopt::Long; | ||||
215 | |||||
216 | ################ Back to Normal ################ | ||||
217 | |||||
218 | # Indices in option control info. | ||||
219 | # Note that ParseOptions uses the fields directly. Search for 'hard-wired'. | ||||
220 | 2 | 21µs | 2 | 67µs | # spent 36µs (6+31) within Getopt::Long::BEGIN@220 which was called:
# once (6µs+31µs) by main::BEGIN@32 at line 220 # spent 36µs making 1 call to Getopt::Long::BEGIN@220
# spent 31µs making 1 call to constant::import |
221 | #use constant CTL_TYPE_FLAG => ''; | ||||
222 | #use constant CTL_TYPE_NEG => '!'; | ||||
223 | #use constant CTL_TYPE_INCR => '+'; | ||||
224 | #use constant CTL_TYPE_INT => 'i'; | ||||
225 | #use constant CTL_TYPE_INTINC => 'I'; | ||||
226 | #use constant CTL_TYPE_XINT => 'o'; | ||||
227 | #use constant CTL_TYPE_FLOAT => 'f'; | ||||
228 | #use constant CTL_TYPE_STRING => 's'; | ||||
229 | |||||
230 | 2 | 18µs | 2 | 36µs | # spent 20µs (4+16) within Getopt::Long::BEGIN@230 which was called:
# once (4µs+16µs) by main::BEGIN@32 at line 230 # spent 20µs making 1 call to Getopt::Long::BEGIN@230
# spent 16µs making 1 call to constant::import |
231 | |||||
232 | 2 | 14µs | 2 | 31µs | # spent 17µs (3+14) within Getopt::Long::BEGIN@232 which was called:
# once (3µs+14µs) by main::BEGIN@32 at line 232 # spent 17µs making 1 call to Getopt::Long::BEGIN@232
# spent 14µs making 1 call to constant::import |
233 | |||||
234 | 2 | 13µs | 2 | 37µs | # spent 20µs (3+17) within Getopt::Long::BEGIN@234 which was called:
# once (3µs+17µs) by main::BEGIN@32 at line 234 # spent 20µs making 1 call to Getopt::Long::BEGIN@234
# spent 17µs making 1 call to constant::import |
235 | 2 | 12µs | 2 | 26µs | # spent 14µs (3+12) within Getopt::Long::BEGIN@235 which was called:
# once (3µs+12µs) by main::BEGIN@32 at line 235 # spent 14µs making 1 call to Getopt::Long::BEGIN@235
# spent 12µs making 1 call to constant::import |
236 | 2 | 12µs | 2 | 26µs | # spent 14µs (3+12) within Getopt::Long::BEGIN@236 which was called:
# once (3µs+12µs) by main::BEGIN@32 at line 236 # spent 14µs making 1 call to Getopt::Long::BEGIN@236
# spent 12µs making 1 call to constant::import |
237 | 2 | 19µs | 2 | 26µs | # spent 15µs (3+12) within Getopt::Long::BEGIN@237 which was called:
# once (3µs+12µs) by main::BEGIN@32 at line 237 # spent 15µs making 1 call to Getopt::Long::BEGIN@237
# spent 12µs making 1 call to constant::import |
238 | 2 | 12µs | 2 | 27µs | # spent 15µs (3+12) within Getopt::Long::BEGIN@238 which was called:
# once (3µs+12µs) by main::BEGIN@32 at line 238 # spent 15µs making 1 call to Getopt::Long::BEGIN@238
# spent 12µs making 1 call to constant::import |
239 | |||||
240 | 2 | 11µs | 2 | 27µs | # spent 15µs (3+12) within Getopt::Long::BEGIN@240 which was called:
# once (3µs+12µs) by main::BEGIN@32 at line 240 # spent 15µs making 1 call to Getopt::Long::BEGIN@240
# spent 12µs making 1 call to constant::import |
241 | 2 | 17µs | 2 | 26µs | # spent 14µs (3+12) within Getopt::Long::BEGIN@241 which was called:
# once (3µs+12µs) by main::BEGIN@32 at line 241 # spent 14µs making 1 call to Getopt::Long::BEGIN@241
# spent 12µs making 1 call to constant::import |
242 | |||||
243 | # FFU. | ||||
244 | #use constant CTL_RANGE => ; | ||||
245 | #use constant CTL_REPEAT => ; | ||||
246 | |||||
247 | # Rather liberal patterns to match numbers. | ||||
248 | 2 | 28µs | 2 | 28µs | # spent 15µs (3+12) within Getopt::Long::BEGIN@248 which was called:
# once (3µs+12µs) by main::BEGIN@32 at line 248 # spent 15µs making 1 call to Getopt::Long::BEGIN@248
# spent 12µs making 1 call to constant::import |
249 | 1 | 2µs | 1 | 13µs | # spent 16µs (3+13) within Getopt::Long::BEGIN@249 which was called:
# once (3µs+13µs) by main::BEGIN@32 at line 258 # spent 13µs making 1 call to constant::import |
250 | "(?:". | ||||
251 | "[-+]?_*[1-9][0-9_]*". | ||||
252 | "|". | ||||
253 | "0x_*[0-9a-f][0-9a-f_]*". | ||||
254 | "|". | ||||
255 | "0b_*[01][01_]*". | ||||
256 | "|". | ||||
257 | "0[0-7_]*". | ||||
258 | 1 | 22µs | 1 | 16µs | ")"; # spent 16µs making 1 call to Getopt::Long::BEGIN@249 |
259 | 1 | 2µs | 1 | 13µs | # spent 16µs (3+13) within Getopt::Long::BEGIN@259 which was called:
# once (3µs+13µs) by main::BEGIN@32 at line 264 # spent 13µs making 1 call to constant::import |
260 | "[-+]?". # optional sign | ||||
261 | "(?=[0-9.])". # must start with digit or dec.point | ||||
262 | "[0-9_]*". # digits before the dec.point | ||||
263 | "(\.[0-9_]+)?". # optional fraction | ||||
264 | 1 | 4.46ms | 1 | 16µs | "([eE][-+]?[0-9_]+)?"; # optional exponent # spent 16µs making 1 call to Getopt::Long::BEGIN@259 |
265 | |||||
266 | # spent 4µs within Getopt::Long::GetOptions which was called:
# once (4µs+0s) by main::RUNTIME at line 54 of /home/hejohns/documentsNoSync/22f/490/gradescope-utils/bin/split.pl | ||||
267 | # Shift in default array. | ||||
268 | 1 | 1µs | unshift(@_, \@ARGV); | ||
269 | # Try to keep caller() and Carp consistent. | ||||
270 | 1 | 4µs | 1 | 272µs | goto &GetOptionsFromArray; # spent 272µs making 1 call to Getopt::Long::GetOptionsFromArray |
271 | } | ||||
272 | |||||
273 | sub GetOptionsFromString(@) { | ||||
274 | my ($string) = shift; | ||||
275 | require Text::ParseWords; | ||||
276 | my $args = [ Text::ParseWords::shellwords($string) ]; | ||||
277 | $caller ||= (caller)[0]; # current context | ||||
278 | my $ret = GetOptionsFromArray($args, @_); | ||||
279 | return ( $ret, $args ) if wantarray; | ||||
280 | if ( @$args ) { | ||||
281 | $ret = 0; | ||||
282 | warn("GetOptionsFromString: Excess data \"@$args\" in string \"$string\"\n"); | ||||
283 | } | ||||
284 | $ret; | ||||
285 | } | ||||
286 | |||||
287 | # spent 272µs (77+195) within Getopt::Long::GetOptionsFromArray which was called:
# once (77µs+195µs) by main::RUNTIME at line 270 | ||||
288 | |||||
289 | 1 | 2µs | my ($argv, @optionlist) = @_; # local copy of the option descriptions | ||
290 | 1 | 300ns | my $argend = '--'; # option list terminator | ||
291 | 1 | 300ns | my %opctl = (); # table of option specs | ||
292 | 1 | 2µs | 1 | 13µs | my $pkg = $caller || (caller)[0]; # current context # spent 13µs making 1 call to Contextual::Return::__ANON__[Contextual/Return.pm:30] |
293 | # Needed if linkage is omitted. | ||||
294 | 1 | 300ns | my @ret = (); # accum for non-options | ||
295 | 1 | 300ns | my %linkage; # linkage | ||
296 | my $userlinkage; # user supplied HASH | ||||
297 | my $opt; # current option | ||||
298 | 1 | 300ns | my $prefix = $genprefix; # current prefix | ||
299 | |||||
300 | 1 | 500ns | $error = ''; | ||
301 | |||||
302 | 1 | 200ns | if ( $debug ) { | ||
303 | # Avoid some warnings if debugging. | ||||
304 | local ($^W) = 0; | ||||
305 | print STDERR | ||||
306 | ("Getopt::Long $Getopt::Long::VERSION_STRING ", | ||||
307 | "called from package \"$pkg\".", | ||||
308 | "\n ", | ||||
309 | "argv: ", | ||||
310 | defined($argv) | ||||
311 | ? UNIVERSAL::isa( $argv, 'ARRAY' ) ? "(@$argv)" : $argv | ||||
312 | : "<undef>", | ||||
313 | "\n ", | ||||
314 | "autoabbrev=$autoabbrev,". | ||||
315 | "bundling=$bundling,", | ||||
316 | "bundling_values=$bundling_values,", | ||||
317 | "getopt_compat=$getopt_compat,", | ||||
318 | "gnu_compat=$gnu_compat,", | ||||
319 | "order=$order,", | ||||
320 | "\n ", | ||||
321 | "ignorecase=$ignorecase,", | ||||
322 | "requested_version=$requested_version,", | ||||
323 | "passthrough=$passthrough,", | ||||
324 | "genprefix=\"$genprefix\",", | ||||
325 | "longprefix=\"$longprefix\".", | ||||
326 | "\n"); | ||||
327 | } | ||||
328 | |||||
329 | # Check for ref HASH as first argument. | ||||
330 | # First argument may be an object. It's OK to use this as long | ||||
331 | # as it is really a hash underneath. | ||||
332 | 1 | 300ns | $userlinkage = undef; | ||
333 | 1 | 4µs | 1 | 700ns | if ( @optionlist && ref($optionlist[0]) and # spent 700ns making 1 call to UNIVERSAL::isa |
334 | UNIVERSAL::isa($optionlist[0],'HASH') ) { | ||||
335 | 1 | 300ns | $userlinkage = shift (@optionlist); | ||
336 | 1 | 300ns | print STDERR ("=> user linkage: $userlinkage\n") if $debug; | ||
337 | } | ||||
338 | |||||
339 | # See if the first element of the optionlist contains option | ||||
340 | # starter characters. | ||||
341 | # Be careful not to interpret '<>' as option starters. | ||||
342 | 1 | 4µs | 1 | 3µs | if ( @optionlist && $optionlist[0] =~ /^\W+$/ # spent 3µs making 1 call to Getopt::Long::CORE:match |
343 | && !($optionlist[0] eq '<>' | ||||
344 | && @optionlist > 0 | ||||
345 | && ref($optionlist[1])) ) { | ||||
346 | $prefix = shift (@optionlist); | ||||
347 | # Turn into regexp. Needs to be parenthesized! | ||||
348 | $prefix =~ s/(\W)/\\$1/g; | ||||
349 | $prefix = "([" . $prefix . "])"; | ||||
350 | print STDERR ("=> prefix=\"$prefix\"\n") if $debug; | ||||
351 | } | ||||
352 | |||||
353 | # Verify correctness of optionlist. | ||||
354 | 1 | 300ns | %opctl = (); | ||
355 | 1 | 800ns | while ( @optionlist ) { | ||
356 | 5 | 700ns | my $opt = shift (@optionlist); | ||
357 | |||||
358 | 5 | 600ns | unless ( defined($opt) ) { | ||
359 | $error .= "Undefined argument in option spec\n"; | ||||
360 | next; | ||||
361 | } | ||||
362 | |||||
363 | # Strip leading prefix so people can specify "--foo=i" if they like. | ||||
364 | 5 | 27µs | 10 | 19µs | $opt = $+ if $opt =~ /^$prefix+(.*)$/s; # spent 16µs making 5 calls to Getopt::Long::CORE:regcomp, avg 3µs/call
# spent 3µs making 5 calls to Getopt::Long::CORE:match, avg 580ns/call |
365 | |||||
366 | 5 | 600ns | if ( $opt eq '<>' ) { | ||
367 | if ( (defined $userlinkage) | ||||
368 | && !(@optionlist > 0 && ref($optionlist[0])) | ||||
369 | && (exists $userlinkage->{$opt}) | ||||
370 | && ref($userlinkage->{$opt}) ) { | ||||
371 | unshift (@optionlist, $userlinkage->{$opt}); | ||||
372 | } | ||||
373 | unless ( @optionlist > 0 | ||||
374 | && ref($optionlist[0]) && ref($optionlist[0]) eq 'CODE' ) { | ||||
375 | $error .= "Option spec <> requires a reference to a subroutine\n"; | ||||
376 | # Kill the linkage (to avoid another error). | ||||
377 | shift (@optionlist) | ||||
378 | if @optionlist && ref($optionlist[0]); | ||||
379 | next; | ||||
380 | } | ||||
381 | $linkage{'<>'} = shift (@optionlist); | ||||
382 | next; | ||||
383 | } | ||||
384 | |||||
385 | # Parse option spec. | ||||
386 | 5 | 5µs | 5 | 86µs | my ($name, $orig) = ParseOptionSpec ($opt, \%opctl); # spent 86µs making 5 calls to Getopt::Long::ParseOptionSpec, avg 17µs/call |
387 | 5 | 600ns | unless ( defined $name ) { | ||
388 | # Failed. $orig contains the error message. Sorry for the abuse. | ||||
389 | $error .= $orig; | ||||
390 | # Kill the linkage (to avoid another error). | ||||
391 | shift (@optionlist) | ||||
392 | if @optionlist && ref($optionlist[0]); | ||||
393 | next; | ||||
394 | } | ||||
395 | |||||
396 | # If no linkage is supplied in the @optionlist, copy it from | ||||
397 | # the userlinkage if available. | ||||
398 | 5 | 400ns | if ( defined $userlinkage ) { | ||
399 | 5 | 1µs | unless ( @optionlist > 0 && ref($optionlist[0]) ) { | ||
400 | 5 | 800ns | if ( exists $userlinkage->{$orig} && | ||
401 | ref($userlinkage->{$orig}) ) { | ||||
402 | print STDERR ("=> found userlinkage for \"$orig\": ", | ||||
403 | "$userlinkage->{$orig}\n") | ||||
404 | if $debug; | ||||
405 | unshift (@optionlist, $userlinkage->{$orig}); | ||||
406 | } | ||||
407 | else { | ||||
408 | # Do nothing. Being undefined will be handled later. | ||||
409 | 5 | 3µs | next; | ||
410 | } | ||||
411 | } | ||||
412 | } | ||||
413 | |||||
414 | # Copy the linkage. If omitted, link to global variable. | ||||
415 | if ( @optionlist > 0 && ref($optionlist[0]) ) { | ||||
416 | print STDERR ("=> link \"$orig\" to $optionlist[0]\n") | ||||
417 | if $debug; | ||||
418 | my $rl = ref($linkage{$orig} = shift (@optionlist)); | ||||
419 | |||||
420 | if ( $rl eq "ARRAY" ) { | ||||
421 | $opctl{$name}[CTL_DEST] = CTL_DEST_ARRAY; | ||||
422 | } | ||||
423 | elsif ( $rl eq "HASH" ) { | ||||
424 | $opctl{$name}[CTL_DEST] = CTL_DEST_HASH; | ||||
425 | } | ||||
426 | elsif ( $rl eq "SCALAR" || $rl eq "REF" ) { | ||||
427 | # if ( $opctl{$name}[CTL_DEST] == CTL_DEST_ARRAY ) { | ||||
428 | # my $t = $linkage{$orig}; | ||||
429 | # $$t = $linkage{$orig} = []; | ||||
430 | # } | ||||
431 | # elsif ( $opctl{$name}[CTL_DEST] == CTL_DEST_HASH ) { | ||||
432 | # } | ||||
433 | # else { | ||||
434 | # Ok. | ||||
435 | # } | ||||
436 | } | ||||
437 | elsif ( $rl eq "CODE" ) { | ||||
438 | # Ok. | ||||
439 | } | ||||
440 | else { | ||||
441 | $error .= "Invalid option linkage for \"$opt\"\n"; | ||||
442 | } | ||||
443 | } | ||||
444 | else { | ||||
445 | # Link to global $opt_XXX variable. | ||||
446 | # Make sure a valid perl identifier results. | ||||
447 | my $ov = $orig; | ||||
448 | $ov =~ s/\W/_/g; | ||||
449 | if ( $opctl{$name}[CTL_DEST] == CTL_DEST_ARRAY ) { | ||||
450 | print STDERR ("=> link \"$orig\" to \@$pkg","::opt_$ov\n") | ||||
451 | if $debug; | ||||
452 | eval ("\$linkage{\$orig} = \\\@".$pkg."::opt_$ov;"); | ||||
453 | } | ||||
454 | elsif ( $opctl{$name}[CTL_DEST] == CTL_DEST_HASH ) { | ||||
455 | print STDERR ("=> link \"$orig\" to \%$pkg","::opt_$ov\n") | ||||
456 | if $debug; | ||||
457 | eval ("\$linkage{\$orig} = \\\%".$pkg."::opt_$ov;"); | ||||
458 | } | ||||
459 | else { | ||||
460 | print STDERR ("=> link \"$orig\" to \$$pkg","::opt_$ov\n") | ||||
461 | if $debug; | ||||
462 | eval ("\$linkage{\$orig} = \\\$".$pkg."::opt_$ov;"); | ||||
463 | } | ||||
464 | } | ||||
465 | |||||
466 | if ( $opctl{$name}[CTL_TYPE] eq 'I' | ||||
467 | && ( $opctl{$name}[CTL_DEST] == CTL_DEST_ARRAY | ||||
468 | || $opctl{$name}[CTL_DEST] == CTL_DEST_HASH ) | ||||
469 | ) { | ||||
470 | $error .= "Invalid option linkage for \"$opt\"\n"; | ||||
471 | } | ||||
472 | |||||
473 | } | ||||
474 | |||||
475 | 1 | 2µs | 1 | 600ns | $error .= "GetOptionsFromArray: 1st parameter is not an array reference\n" # spent 600ns making 1 call to UNIVERSAL::isa |
476 | unless $argv && UNIVERSAL::isa( $argv, 'ARRAY' ); | ||||
477 | |||||
478 | # Bail out if errors found. | ||||
479 | 1 | 200ns | die ($error) if $error; | ||
480 | 1 | 400ns | $error = 0; | ||
481 | |||||
482 | # Supply --version and --help support, if needed and allowed. | ||||
483 | 1 | 500ns | if ( defined($auto_version) ? $auto_version : ($requested_version >= 2.3203) ) { | ||
484 | 1 | 700ns | if ( !defined($opctl{version}) ) { | ||
485 | 1 | 1µs | $opctl{version} = ['','version',0,CTL_DEST_CODE,undef]; | ||
486 | 1 | 600ns | $linkage{version} = \&VersionMessage; | ||
487 | } | ||||
488 | 1 | 200ns | $auto_version = 1; | ||
489 | } | ||||
490 | 1 | 900ns | if ( defined($auto_help) ? $auto_help : ($requested_version >= 2.3203) ) { | ||
491 | if ( !defined($opctl{help}) && !defined($opctl{'?'}) ) { | ||||
492 | $opctl{help} = $opctl{'?'} = ['','help',0,CTL_DEST_CODE,undef]; | ||||
493 | $linkage{help} = \&HelpMessage; | ||||
494 | } | ||||
495 | $auto_help = 1; | ||||
496 | } | ||||
497 | |||||
498 | # Show the options tables if debugging. | ||||
499 | 1 | 300ns | if ( $debug ) { | ||
500 | my ($arrow, $k, $v); | ||||
501 | $arrow = "=> "; | ||||
502 | while ( ($k,$v) = each(%opctl) ) { | ||||
503 | print STDERR ($arrow, "\$opctl{$k} = $v ", OptCtl($v), "\n"); | ||||
504 | $arrow = " "; | ||||
505 | } | ||||
506 | } | ||||
507 | |||||
508 | # Process argument list | ||||
509 | 1 | 500ns | my $goon = 1; | ||
510 | 1 | 700ns | while ( $goon && @$argv > 0 ) { | ||
511 | |||||
512 | # Get next argument. | ||||
513 | 6 | 1µs | $opt = shift (@$argv); | ||
514 | 6 | 400ns | print STDERR ("=> arg \"", $opt, "\"\n") if $debug; | ||
515 | |||||
516 | # Double dash is option list terminator. | ||||
517 | 6 | 1µs | if ( defined($opt) && $opt eq $argend ) { | ||
518 | push (@ret, $argend) if $passthrough; | ||||
519 | last; | ||||
520 | } | ||||
521 | |||||
522 | # Look it up. | ||||
523 | 6 | 700ns | my $tryopt = $opt; | ||
524 | 6 | 700ns | my $found; # success status | ||
525 | my $key; # key (if hash type) | ||||
526 | my $arg; # option argument | ||||
527 | my $ctl; # the opctl entry | ||||
528 | |||||
529 | 6 | 6µs | 6 | 74µs | ($found, $opt, $ctl, $arg, $key) = # spent 74µs making 6 calls to Getopt::Long::FindOption, avg 12µs/call |
530 | FindOption ($argv, $prefix, $argend, $opt, \%opctl); | ||||
531 | |||||
532 | 6 | 2µs | if ( $found ) { | ||
533 | |||||
534 | # FindOption undefines $opt in case of errors. | ||||
535 | 5 | 500ns | next unless defined $opt; | ||
536 | |||||
537 | 5 | 500ns | my $argcnt = 0; | ||
538 | 5 | 500ns | while ( defined $arg ) { | ||
539 | |||||
540 | # Get the canonical name. | ||||
541 | 5 | 300ns | my $given = $opt; | ||
542 | 5 | 400ns | print STDERR ("=> cname for \"$opt\" is ") if $debug; | ||
543 | 5 | 700ns | $opt = $ctl->[CTL_CNAME]; | ||
544 | 5 | 500ns | print STDERR ("\"$ctl->[CTL_CNAME]\"\n") if $debug; | ||
545 | |||||
546 | 5 | 2µs | if ( defined $linkage{$opt} ) { | ||
547 | print STDERR ("=> ref(\$L{$opt}) -> ", | ||||
548 | ref($linkage{$opt}), "\n") if $debug; | ||||
549 | |||||
550 | if ( ref($linkage{$opt}) eq 'SCALAR' | ||||
551 | || ref($linkage{$opt}) eq 'REF' ) { | ||||
552 | if ( $ctl->[CTL_TYPE] eq '+' ) { | ||||
553 | print STDERR ("=> \$\$L{$opt} += \"$arg\"\n") | ||||
554 | if $debug; | ||||
555 | if ( defined ${$linkage{$opt}} ) { | ||||
556 | ${$linkage{$opt}} += $arg; | ||||
557 | } | ||||
558 | else { | ||||
559 | ${$linkage{$opt}} = $arg; | ||||
560 | } | ||||
561 | } | ||||
562 | elsif ( $ctl->[CTL_DEST] == CTL_DEST_ARRAY ) { | ||||
563 | print STDERR ("=> ref(\$L{$opt}) auto-vivified", | ||||
564 | " to ARRAY\n") | ||||
565 | if $debug; | ||||
566 | my $t = $linkage{$opt}; | ||||
567 | $$t = $linkage{$opt} = []; | ||||
568 | print STDERR ("=> push(\@{\$L{$opt}, \"$arg\")\n") | ||||
569 | if $debug; | ||||
570 | push (@{$linkage{$opt}}, $arg); | ||||
571 | } | ||||
572 | elsif ( $ctl->[CTL_DEST] == CTL_DEST_HASH ) { | ||||
573 | print STDERR ("=> ref(\$L{$opt}) auto-vivified", | ||||
574 | " to HASH\n") | ||||
575 | if $debug; | ||||
576 | my $t = $linkage{$opt}; | ||||
577 | $$t = $linkage{$opt} = {}; | ||||
578 | print STDERR ("=> \$\$L{$opt}->{$key} = \"$arg\"\n") | ||||
579 | if $debug; | ||||
580 | $linkage{$opt}->{$key} = $arg; | ||||
581 | } | ||||
582 | else { | ||||
583 | print STDERR ("=> \$\$L{$opt} = \"$arg\"\n") | ||||
584 | if $debug; | ||||
585 | ${$linkage{$opt}} = $arg; | ||||
586 | } | ||||
587 | } | ||||
588 | elsif ( ref($linkage{$opt}) eq 'ARRAY' ) { | ||||
589 | print STDERR ("=> push(\@{\$L{$opt}, \"$arg\")\n") | ||||
590 | if $debug; | ||||
591 | push (@{$linkage{$opt}}, $arg); | ||||
592 | } | ||||
593 | elsif ( ref($linkage{$opt}) eq 'HASH' ) { | ||||
594 | print STDERR ("=> \$\$L{$opt}->{$key} = \"$arg\"\n") | ||||
595 | if $debug; | ||||
596 | $linkage{$opt}->{$key} = $arg; | ||||
597 | } | ||||
598 | elsif ( ref($linkage{$opt}) eq 'CODE' ) { | ||||
599 | print STDERR ("=> &L{$opt}(\"$opt\"", | ||||
600 | $ctl->[CTL_DEST] == CTL_DEST_HASH ? ", \"$key\"" : "", | ||||
601 | ", \"$arg\")\n") | ||||
602 | if $debug; | ||||
603 | my $eval_error = do { | ||||
604 | local $@; | ||||
605 | local $SIG{__DIE__} = 'DEFAULT'; | ||||
606 | eval { | ||||
607 | &{$linkage{$opt}} | ||||
608 | (Getopt::Long::CallBack->new | ||||
609 | (name => $opt, | ||||
610 | given => $given, | ||||
611 | ctl => $ctl, | ||||
612 | opctl => \%opctl, | ||||
613 | linkage => \%linkage, | ||||
614 | prefix => $prefix, | ||||
615 | ), | ||||
616 | $ctl->[CTL_DEST] == CTL_DEST_HASH ? ($key) : (), | ||||
617 | $arg); | ||||
618 | }; | ||||
619 | $@; | ||||
620 | }; | ||||
621 | print STDERR ("=> die($eval_error)\n") | ||||
622 | if $debug && $eval_error ne ''; | ||||
623 | if ( $eval_error =~ /^!/ ) { | ||||
624 | if ( $eval_error =~ /^!FINISH\b/ ) { | ||||
625 | $goon = 0; | ||||
626 | } | ||||
627 | } | ||||
628 | elsif ( $eval_error ne '' ) { | ||||
629 | warn ($eval_error); | ||||
630 | $error++; | ||||
631 | } | ||||
632 | } | ||||
633 | else { | ||||
634 | print STDERR ("Invalid REF type \"", ref($linkage{$opt}), | ||||
635 | "\" in linkage\n"); | ||||
636 | die("Getopt::Long -- internal error!\n"); | ||||
637 | } | ||||
638 | } | ||||
639 | # No entry in linkage means entry in userlinkage. | ||||
640 | elsif ( $ctl->[CTL_DEST] == CTL_DEST_ARRAY ) { | ||||
641 | 5 | 1µs | if ( defined $userlinkage->{$opt} ) { | ||
642 | 2 | 200ns | print STDERR ("=> push(\@{\$L{$opt}}, \"$arg\")\n") | ||
643 | if $debug; | ||||
644 | 2 | 1µs | push (@{$userlinkage->{$opt}}, $arg); | ||
645 | } | ||||
646 | else { | ||||
647 | 3 | 300ns | print STDERR ("=>\$L{$opt} = [\"$arg\"]\n") | ||
648 | if $debug; | ||||
649 | 3 | 1µs | $userlinkage->{$opt} = [$arg]; | ||
650 | } | ||||
651 | } | ||||
652 | elsif ( $ctl->[CTL_DEST] == CTL_DEST_HASH ) { | ||||
653 | if ( defined $userlinkage->{$opt} ) { | ||||
654 | print STDERR ("=> \$L{$opt}->{$key} = \"$arg\"\n") | ||||
655 | if $debug; | ||||
656 | $userlinkage->{$opt}->{$key} = $arg; | ||||
657 | } | ||||
658 | else { | ||||
659 | print STDERR ("=>\$L{$opt} = {$key => \"$arg\"}\n") | ||||
660 | if $debug; | ||||
661 | $userlinkage->{$opt} = {$key => $arg}; | ||||
662 | } | ||||
663 | } | ||||
664 | else { | ||||
665 | if ( $ctl->[CTL_TYPE] eq '+' ) { | ||||
666 | print STDERR ("=> \$L{$opt} += \"$arg\"\n") | ||||
667 | if $debug; | ||||
668 | if ( defined $userlinkage->{$opt} ) { | ||||
669 | $userlinkage->{$opt} += $arg; | ||||
670 | } | ||||
671 | else { | ||||
672 | $userlinkage->{$opt} = $arg; | ||||
673 | } | ||||
674 | } | ||||
675 | else { | ||||
676 | print STDERR ("=>\$L{$opt} = \"$arg\"\n") if $debug; | ||||
677 | $userlinkage->{$opt} = $arg; | ||||
678 | } | ||||
679 | } | ||||
680 | |||||
681 | 5 | 500ns | $argcnt++; | ||
682 | 5 | 2µs | last if $argcnt >= $ctl->[CTL_AMAX] && $ctl->[CTL_AMAX] != -1; | ||
683 | undef($arg); | ||||
684 | |||||
685 | # Need more args? | ||||
686 | if ( $argcnt < $ctl->[CTL_AMIN] ) { | ||||
687 | if ( @$argv ) { | ||||
688 | if ( ValidValue($ctl, $argv->[0], 1, $argend, $prefix) ) { | ||||
689 | $arg = shift(@$argv); | ||||
690 | if ( $ctl->[CTL_TYPE] =~ /^[iIo]$/ ) { | ||||
691 | $arg =~ tr/_//d; | ||||
692 | $arg = $ctl->[CTL_TYPE] eq 'o' && $arg =~ /^0/ | ||||
693 | ? oct($arg) | ||||
694 | : 0+$arg | ||||
695 | } | ||||
696 | ($key,$arg) = $arg =~ /^([^=]+)=(.*)/ | ||||
697 | if $ctl->[CTL_DEST] == CTL_DEST_HASH; | ||||
698 | next; | ||||
699 | } | ||||
700 | warn("Value \"$$argv[0]\" invalid for option $opt\n"); | ||||
701 | $error++; | ||||
702 | } | ||||
703 | else { | ||||
704 | warn("Insufficient arguments for option $opt\n"); | ||||
705 | $error++; | ||||
706 | } | ||||
707 | } | ||||
708 | |||||
709 | # Any more args? | ||||
710 | if ( @$argv && ValidValue($ctl, $argv->[0], 0, $argend, $prefix) ) { | ||||
711 | $arg = shift(@$argv); | ||||
712 | if ( $ctl->[CTL_TYPE] =~ /^[iIo]$/ ) { | ||||
713 | $arg =~ tr/_//d; | ||||
714 | $arg = $ctl->[CTL_TYPE] eq 'o' && $arg =~ /^0/ | ||||
715 | ? oct($arg) | ||||
716 | : 0+$arg | ||||
717 | } | ||||
718 | ($key,$arg) = $arg =~ /^([^=]+)=(.*)/ | ||||
719 | if $ctl->[CTL_DEST] == CTL_DEST_HASH; | ||||
720 | next; | ||||
721 | } | ||||
722 | } | ||||
723 | } | ||||
724 | |||||
725 | # Not an option. Save it if we $PERMUTE and don't have a <>. | ||||
726 | elsif ( $order == $PERMUTE ) { | ||||
727 | # Try non-options call-back. | ||||
728 | 1 | 400ns | my $cb; | ||
729 | 1 | 600ns | if ( defined ($cb = $linkage{'<>'}) ) { | ||
730 | print STDERR ("=> &L{$tryopt}(\"$tryopt\")\n") | ||||
731 | if $debug; | ||||
732 | my $eval_error = do { | ||||
733 | local $@; | ||||
734 | local $SIG{__DIE__} = 'DEFAULT'; | ||||
735 | eval { | ||||
736 | # The arg to <> cannot be the CallBack object | ||||
737 | # since it may be passed to other modules that | ||||
738 | # get confused (e.g., Archive::Tar). Well, | ||||
739 | # it's not relevant for this callback anyway. | ||||
740 | &$cb($tryopt); | ||||
741 | }; | ||||
742 | $@; | ||||
743 | }; | ||||
744 | print STDERR ("=> die($eval_error)\n") | ||||
745 | if $debug && $eval_error ne ''; | ||||
746 | if ( $eval_error =~ /^!/ ) { | ||||
747 | if ( $eval_error =~ /^!FINISH\b/ ) { | ||||
748 | $goon = 0; | ||||
749 | } | ||||
750 | } | ||||
751 | elsif ( $eval_error ne '' ) { | ||||
752 | warn ($eval_error); | ||||
753 | $error++; | ||||
754 | } | ||||
755 | } | ||||
756 | else { | ||||
757 | 1 | 100ns | print STDERR ("=> saving \"$tryopt\" ", | ||
758 | "(not an option, may permute)\n") if $debug; | ||||
759 | 1 | 300ns | push (@ret, $tryopt); | ||
760 | } | ||||
761 | 1 | 400ns | next; | ||
762 | } | ||||
763 | |||||
764 | # ...otherwise, terminate. | ||||
765 | else { | ||||
766 | # Push this one back and exit. | ||||
767 | unshift (@$argv, $tryopt); | ||||
768 | return ($error == 0); | ||||
769 | } | ||||
770 | |||||
771 | } | ||||
772 | |||||
773 | # Finish. | ||||
774 | 1 | 700ns | if ( @ret && ( $order == $PERMUTE || $passthrough ) ) { | ||
775 | # Push back accumulated arguments | ||||
776 | 1 | 0s | print STDERR ("=> restoring \"", join('" "', @ret), "\"\n") | ||
777 | if $debug; | ||||
778 | 1 | 500ns | unshift (@$argv, @ret); | ||
779 | } | ||||
780 | |||||
781 | 1 | 6µs | return ($error == 0); | ||
782 | } | ||||
783 | |||||
784 | # A readable representation of what's in an optbl. | ||||
785 | sub OptCtl ($) { | ||||
786 | my ($v) = @_; | ||||
787 | my @v = map { defined($_) ? ($_) : ("<undef>") } @$v; | ||||
788 | "[". | ||||
789 | join(",", | ||||
790 | "\"$v[CTL_TYPE]\"", | ||||
791 | "\"$v[CTL_CNAME]\"", | ||||
792 | "\"$v[CTL_DEFAULT]\"", | ||||
793 | ("\$","\@","\%","\&")[$v[CTL_DEST] || 0], | ||||
794 | $v[CTL_AMIN] || '', | ||||
795 | $v[CTL_AMAX] || '', | ||||
796 | # $v[CTL_RANGE] || '', | ||||
797 | # $v[CTL_REPEAT] || '', | ||||
798 | ). "]"; | ||||
799 | } | ||||
800 | |||||
801 | # Parse an option specification and fill the tables. | ||||
802 | # spent 86µs (60+26) within Getopt::Long::ParseOptionSpec which was called 5 times, avg 17µs/call:
# 5 times (60µs+26µs) by Getopt::Long::GetOptionsFromArray at line 386, avg 17µs/call | ||||
803 | 5 | 1µs | my ($opt, $opctl) = @_; | ||
804 | |||||
805 | # Match option spec. | ||||
806 | 5 | 27µs | 5 | 21µs | if ( $opt !~ m;^ # spent 21µs making 5 calls to Getopt::Long::CORE:match, avg 4µs/call |
807 | ( | ||||
808 | # Option name | ||||
809 | (?: \w+[-\w]* ) | ||||
810 | # Aliases | ||||
811 | (?: \| (?: . [^|!+=:]* )? )* | ||||
812 | )? | ||||
813 | ( | ||||
814 | # Either modifiers ... | ||||
815 | [!+] | ||||
816 | | | ||||
817 | # ... or a value/dest/repeat specification | ||||
818 | [=:] [ionfs] [@%]? (?: \{\d*,?\d*\} )? | ||||
819 | | | ||||
820 | # ... or an optional-with-default spec | ||||
821 | : (?: -?\d+ | \+ ) [@%]? | ||||
822 | )? | ||||
823 | $;x ) { | ||||
824 | return (undef, "Error in option spec: \"$opt\"\n"); | ||||
825 | } | ||||
826 | |||||
827 | 5 | 4µs | my ($names, $spec) = ($1, $2); | ||
828 | 5 | 800ns | $spec = '' unless defined $spec; | ||
829 | |||||
830 | # $orig keeps track of the primary name the user specified. | ||||
831 | # This name will be used for the internal or external linkage. | ||||
832 | # In other words, if the user specifies "FoO|BaR", it will | ||||
833 | # match any case combinations of 'foo' and 'bar', but if a global | ||||
834 | # variable needs to be set, it will be $opt_FoO in the exact case | ||||
835 | # as specified. | ||||
836 | 5 | 500ns | my $orig; | ||
837 | |||||
838 | my @names; | ||||
839 | 5 | 900ns | if ( defined $names ) { | ||
840 | 5 | 3µs | @names = split (/\|/, $names); | ||
841 | 5 | 900ns | $orig = $names[0]; | ||
842 | } | ||||
843 | else { | ||||
844 | @names = (''); | ||||
845 | $orig = ''; | ||||
846 | } | ||||
847 | |||||
848 | # Construct the opctl entries. | ||||
849 | 5 | 300ns | my $entry; | ||
850 | 5 | 6µs | 4 | 400ns | if ( $spec eq '' || $spec eq '+' || $spec eq '!' ) { # spent 400ns making 4 calls to Getopt::Long::CORE:match, avg 100ns/call |
851 | # Fields are hard-wired here. | ||||
852 | $entry = [$spec,$orig,undef,CTL_DEST_SCALAR,0,0]; | ||||
853 | } | ||||
854 | elsif ( $spec =~ /^:(-?\d+|\+)([@%])?$/ ) { | ||||
855 | my $def = $1; | ||||
856 | my $dest = $2; | ||||
857 | my $type = $def eq '+' ? 'I' : 'i'; | ||||
858 | $dest ||= '$'; | ||||
859 | $dest = $dest eq '@' ? CTL_DEST_ARRAY | ||||
860 | : $dest eq '%' ? CTL_DEST_HASH : CTL_DEST_SCALAR; | ||||
861 | # Fields are hard-wired here. | ||||
862 | $entry = [$type,$orig,$def eq '+' ? undef : $def, | ||||
863 | $dest,0,1]; | ||||
864 | } | ||||
865 | else { | ||||
866 | 4 | 9µs | 4 | 5µs | my ($mand, $type, $dest) = # spent 5µs making 4 calls to Getopt::Long::CORE:match, avg 1µs/call |
867 | $spec =~ /^([=:])([ionfs])([@%])?(\{(\d+)?(,)?(\d+)?\})?$/; | ||||
868 | 4 | 1µs | return (undef, "Cannot repeat while bundling: \"$opt\"\n") | ||
869 | if $bundling && defined($4); | ||||
870 | 4 | 2µs | my ($mi, $cm, $ma) = ($5, $6, $7); | ||
871 | 4 | 600ns | return (undef, "{0} is useless in option spec: \"$opt\"\n") | ||
872 | if defined($mi) && !$mi && !defined($ma) && !defined($cm); | ||||
873 | |||||
874 | 4 | 500ns | $type = 'i' if $type eq 'n'; | ||
875 | 4 | 500ns | $dest ||= '$'; | ||
876 | 4 | 1µs | $dest = $dest eq '@' ? CTL_DEST_ARRAY | ||
877 | : $dest eq '%' ? CTL_DEST_HASH : CTL_DEST_SCALAR; | ||||
878 | # Default minargs to 1/0 depending on mand status. | ||||
879 | 4 | 900ns | $mi = $mand eq '=' ? 1 : 0 unless defined $mi; | ||
880 | # Adjust mand status according to minargs. | ||||
881 | 4 | 500ns | $mand = $mi ? '=' : ':'; | ||
882 | # Adjust maxargs. | ||||
883 | 4 | 700ns | $ma = $mi ? $mi : 1 unless defined $ma || defined $cm; | ||
884 | 4 | 500ns | return (undef, "Max must be greater than zero in option spec: \"$opt\"\n") | ||
885 | if defined($ma) && !$ma; | ||||
886 | 4 | 600ns | return (undef, "Max less than min in option spec: \"$opt\"\n") | ||
887 | if defined($ma) && $ma < $mi; | ||||
888 | |||||
889 | # Fields are hard-wired here. | ||||
890 | 4 | 2µs | $entry = [$type,$orig,undef,$dest,$mi,$ma||-1]; | ||
891 | } | ||||
892 | |||||
893 | # Process all names. First is canonical, the rest are aliases. | ||||
894 | 5 | 600ns | my $dups = ''; | ||
895 | 5 | 1µs | foreach ( @names ) { | ||
896 | |||||
897 | 13 | 4µs | $_ = lc ($_) | ||
898 | if $ignorecase > (($bundling && length($_) == 1) ? 1 : 0); | ||||
899 | |||||
900 | 13 | 2µs | if ( exists $opctl->{$_} ) { | ||
901 | $dups .= "Duplicate specification \"$opt\" for option \"$_\"\n"; | ||||
902 | } | ||||
903 | |||||
904 | 13 | 3µs | if ( $spec eq '!' ) { | ||
905 | $opctl->{"no$_"} = $entry; | ||||
906 | $opctl->{"no-$_"} = $entry; | ||||
907 | $opctl->{$_} = [@$entry]; | ||||
908 | $opctl->{$_}->[CTL_TYPE] = ''; | ||||
909 | } | ||||
910 | else { | ||||
911 | 13 | 4µs | $opctl->{$_} = $entry; | ||
912 | } | ||||
913 | } | ||||
914 | |||||
915 | 5 | 600ns | if ( $dups && $^W ) { | ||
916 | foreach ( split(/\n+/, $dups) ) { | ||||
917 | warn($_."\n"); | ||||
918 | } | ||||
919 | } | ||||
920 | 5 | 8µs | ($names[0], $orig); | ||
921 | } | ||||
922 | |||||
923 | # Option lookup. | ||||
924 | # spent 74µs (54+20) within Getopt::Long::FindOption which was called 6 times, avg 12µs/call:
# 6 times (54µs+20µs) by Getopt::Long::GetOptionsFromArray at line 529, avg 12µs/call | ||||
925 | |||||
926 | # returns (1, $opt, $ctl, $arg, $key) if okay, | ||||
927 | # returns (1, undef) if option in error, | ||||
928 | # returns (0) otherwise. | ||||
929 | |||||
930 | 6 | 1µs | my ($argv, $prefix, $argend, $opt, $opctl) = @_; | ||
931 | |||||
932 | 6 | 400ns | print STDERR ("=> find \"$opt\"\n") if $debug; | ||
933 | |||||
934 | 6 | 700ns | return (0) unless defined($opt); | ||
935 | 6 | 24µs | 12 | 15µs | return (0) unless $opt =~ /^($prefix)(.*)$/s; # spent 12µs making 6 calls to Getopt::Long::CORE:regcomp, avg 2µs/call
# spent 3µs making 6 calls to Getopt::Long::CORE:match, avg 467ns/call |
936 | 5 | 800ns | return (0) if $opt eq "-" && !defined $opctl->{''}; | ||
937 | |||||
938 | 5 | 2µs | $opt = substr( $opt, length($1) ); # retain taintedness | ||
939 | 5 | 1µs | my $starter = $1; | ||
940 | |||||
941 | 5 | 300ns | print STDERR ("=> split \"$starter\"+\"$opt\"\n") if $debug; | ||
942 | |||||
943 | 5 | 500ns | my $optarg; # value supplied with --opt=value | ||
944 | my $rest; # remainder from unbundling | ||||
945 | |||||
946 | # If it is a long option, it may include the value. | ||||
947 | # With getopt_compat, only if not bundling. | ||||
948 | 5 | 11µs | 10 | 5µs | if ( ($starter=~/^$longprefix$/ # spent 5µs making 5 calls to Getopt::Long::CORE:regcomp, avg 980ns/call
# spent 100ns making 5 calls to Getopt::Long::CORE:match, avg 20ns/call |
949 | || ($getopt_compat && ($bundling == 0 || $bundling == 2))) | ||||
950 | && (my $oppos = index($opt, '=', 1)) > 0) { | ||||
951 | my $optorg = $opt; | ||||
952 | $opt = substr($optorg, 0, $oppos); | ||||
953 | $optarg = substr($optorg, $oppos + 1); # retain tainedness | ||||
954 | print STDERR ("=> option \"", $opt, | ||||
955 | "\", optarg = \"$optarg\"\n") if $debug; | ||||
956 | } | ||||
957 | |||||
958 | #### Look it up ### | ||||
959 | |||||
960 | 5 | 700ns | my $tryopt = $opt; # option to try | ||
961 | |||||
962 | 5 | 1µs | if ( ( $bundling || $bundling_values ) && $starter eq '-' ) { | ||
963 | |||||
964 | # To try overrides, obey case ignore. | ||||
965 | 5 | 1µs | $tryopt = $ignorecase ? lc($opt) : $opt; | ||
966 | |||||
967 | # If bundling == 2, long options can override bundles. | ||||
968 | 5 | 1µs | if ( $bundling == 2 && length($tryopt) > 1 | ||
969 | && defined ($opctl->{$tryopt}) ) { | ||||
970 | print STDERR ("=> $starter$tryopt overrides unbundling\n") | ||||
971 | if $debug; | ||||
972 | } | ||||
973 | |||||
974 | # If bundling_values, option may be followed by the value. | ||||
975 | elsif ( $bundling_values ) { | ||||
976 | $tryopt = $opt; | ||||
977 | # Unbundle single letter option. | ||||
978 | $rest = length ($tryopt) > 0 ? substr ($tryopt, 1) : ''; | ||||
979 | $tryopt = substr ($tryopt, 0, 1); | ||||
980 | $tryopt = lc ($tryopt) if $ignorecase > 1; | ||||
981 | print STDERR ("=> $starter$tryopt unbundled from ", | ||||
982 | "$starter$tryopt$rest\n") if $debug; | ||||
983 | # Whatever remains may not be considered an option. | ||||
984 | $optarg = $rest eq '' ? undef : $rest; | ||||
985 | $rest = undef; | ||||
986 | } | ||||
987 | |||||
988 | # Split off a single letter and leave the rest for | ||||
989 | # further processing. | ||||
990 | else { | ||||
991 | 5 | 500ns | $tryopt = $opt; | ||
992 | # Unbundle single letter option. | ||||
993 | 5 | 1µs | $rest = length ($tryopt) > 0 ? substr ($tryopt, 1) : ''; | ||
994 | 5 | 1µs | $tryopt = substr ($tryopt, 0, 1); | ||
995 | 5 | 500ns | $tryopt = lc ($tryopt) if $ignorecase > 1; | ||
996 | 5 | 500ns | print STDERR ("=> $starter$tryopt unbundled from ", | ||
997 | "$starter$tryopt$rest\n") if $debug; | ||||
998 | 5 | 1µs | $rest = undef unless $rest ne ''; | ||
999 | } | ||||
1000 | } | ||||
1001 | |||||
1002 | # Try auto-abbreviation. | ||||
1003 | elsif ( $autoabbrev && $opt ne "" ) { | ||||
1004 | # Sort the possible long option names. | ||||
1005 | my @names = sort(keys (%$opctl)); | ||||
1006 | # Downcase if allowed. | ||||
1007 | $opt = lc ($opt) if $ignorecase; | ||||
1008 | $tryopt = $opt; | ||||
1009 | # Turn option name into pattern. | ||||
1010 | my $pat = quotemeta ($opt); | ||||
1011 | # Look up in option names. | ||||
1012 | my @hits = grep (/^$pat/, @names); | ||||
1013 | print STDERR ("=> ", scalar(@hits), " hits (@hits) with \"$pat\" ", | ||||
1014 | "out of ", scalar(@names), "\n") if $debug; | ||||
1015 | |||||
1016 | # Check for ambiguous results. | ||||
1017 | unless ( (@hits <= 1) || (grep ($_ eq $opt, @hits) == 1) ) { | ||||
1018 | # See if all matches are for the same option. | ||||
1019 | my %hit; | ||||
1020 | foreach ( @hits ) { | ||||
1021 | my $hit = $opctl->{$_}->[CTL_CNAME] | ||||
1022 | if defined $opctl->{$_}->[CTL_CNAME]; | ||||
1023 | $hit = "no" . $hit if $opctl->{$_}->[CTL_TYPE] eq '!'; | ||||
1024 | $hit{$hit} = 1; | ||||
1025 | } | ||||
1026 | # Remove auto-supplied options (version, help). | ||||
1027 | if ( keys(%hit) == 2 ) { | ||||
1028 | if ( $auto_version && exists($hit{version}) ) { | ||||
1029 | delete $hit{version}; | ||||
1030 | } | ||||
1031 | elsif ( $auto_help && exists($hit{help}) ) { | ||||
1032 | delete $hit{help}; | ||||
1033 | } | ||||
1034 | } | ||||
1035 | # Now see if it really is ambiguous. | ||||
1036 | unless ( keys(%hit) == 1 ) { | ||||
1037 | return (0) if $passthrough; | ||||
1038 | warn ("Option ", $opt, " is ambiguous (", | ||||
1039 | join(", ", @hits), ")\n"); | ||||
1040 | $error++; | ||||
1041 | return (1, undef); | ||||
1042 | } | ||||
1043 | @hits = keys(%hit); | ||||
1044 | } | ||||
1045 | |||||
1046 | # Complete the option name, if appropriate. | ||||
1047 | if ( @hits == 1 && $hits[0] ne $opt ) { | ||||
1048 | $tryopt = $hits[0]; | ||||
1049 | $tryopt = lc ($tryopt) | ||||
1050 | if $ignorecase > (($bundling && length($tryopt) == 1) ? 1 : 0); | ||||
1051 | print STDERR ("=> option \"$opt\" -> \"$tryopt\"\n") | ||||
1052 | if $debug; | ||||
1053 | } | ||||
1054 | } | ||||
1055 | |||||
1056 | # Map to all lowercase if ignoring case. | ||||
1057 | elsif ( $ignorecase ) { | ||||
1058 | $tryopt = lc ($opt); | ||||
1059 | } | ||||
1060 | |||||
1061 | # Check validity by fetching the info. | ||||
1062 | 5 | 2µs | my $ctl = $opctl->{$tryopt}; | ||
1063 | 5 | 500ns | unless ( defined $ctl ) { | ||
1064 | return (0) if $passthrough; | ||||
1065 | # Pretend one char when bundling. | ||||
1066 | if ( $bundling == 1 && length($starter) == 1 ) { | ||||
1067 | $opt = substr($opt,0,1); | ||||
1068 | unshift (@$argv, $starter.$rest) if defined $rest; | ||||
1069 | } | ||||
1070 | if ( $opt eq "" ) { | ||||
1071 | warn ("Missing option after ", $starter, "\n"); | ||||
1072 | } | ||||
1073 | else { | ||||
1074 | warn ("Unknown option: ", $opt, "\n"); | ||||
1075 | } | ||||
1076 | $error++; | ||||
1077 | return (1, undef); | ||||
1078 | } | ||||
1079 | # Apparently valid. | ||||
1080 | 5 | 500ns | $opt = $tryopt; | ||
1081 | 5 | 400ns | print STDERR ("=> found ", OptCtl($ctl), | ||
1082 | " for \"", $opt, "\"\n") if $debug; | ||||
1083 | |||||
1084 | #### Determine argument status #### | ||||
1085 | |||||
1086 | # If it is an option w/o argument, we're almost finished with it. | ||||
1087 | 5 | 1µs | my $type = $ctl->[CTL_TYPE]; | ||
1088 | 5 | 300ns | my $arg; | ||
1089 | |||||
1090 | 5 | 1µs | if ( $type eq '' || $type eq '!' || $type eq '+' ) { | ||
1091 | if ( defined $optarg ) { | ||||
1092 | return (0) if $passthrough; | ||||
1093 | warn ("Option ", $opt, " does not take an argument\n"); | ||||
1094 | $error++; | ||||
1095 | undef $opt; | ||||
1096 | undef $optarg if $bundling_values; | ||||
1097 | } | ||||
1098 | elsif ( $type eq '' || $type eq '+' ) { | ||||
1099 | # Supply explicit value. | ||||
1100 | $arg = 1; | ||||
1101 | } | ||||
1102 | else { | ||||
1103 | $opt =~ s/^no-?//i; # strip NO prefix | ||||
1104 | $arg = 0; # supply explicit value | ||||
1105 | } | ||||
1106 | unshift (@$argv, $starter.$rest) if defined $rest; | ||||
1107 | return (1, $opt, $ctl, $arg); | ||||
1108 | } | ||||
1109 | |||||
1110 | # Get mandatory status and type info. | ||||
1111 | 5 | 800ns | my $mand = $ctl->[CTL_AMIN]; | ||
1112 | |||||
1113 | # Check if there is an option argument available. | ||||
1114 | 5 | 800ns | if ( $gnu_compat ) { | ||
1115 | 5 | 400ns | my $optargtype = 0; # none, 1 = empty, 2 = nonempty, 3 = aux | ||
1116 | 5 | 2µs | if ( defined($optarg) ) { | ||
1117 | $optargtype = (length($optarg) == 0) ? 1 : 2; | ||||
1118 | } | ||||
1119 | elsif ( defined $rest || @$argv > 0 ) { | ||||
1120 | # GNU getopt_long() does not accept the (optional) | ||||
1121 | # argument to be passed to the option without = sign. | ||||
1122 | # We do, since not doing so breaks existing scripts. | ||||
1123 | $optargtype = 3; | ||||
1124 | } | ||||
1125 | 5 | 600ns | if(($optargtype == 0) && !$mand) { | ||
1126 | if ( $type eq 'I' ) { | ||||
1127 | # Fake incremental type. | ||||
1128 | my @c = @$ctl; | ||||
1129 | $c[CTL_TYPE] = '+'; | ||||
1130 | return (1, $opt, \@c, 1); | ||||
1131 | } | ||||
1132 | my $val | ||||
1133 | = defined($ctl->[CTL_DEFAULT]) ? $ctl->[CTL_DEFAULT] | ||||
1134 | : $type eq 's' ? '' | ||||
1135 | : 0; | ||||
1136 | return (1, $opt, $ctl, $val); | ||||
1137 | } | ||||
1138 | 5 | 600ns | return (1, $opt, $ctl, $type eq 's' ? '' : 0) | ||
1139 | if $optargtype == 1; # --foo= -> return nothing | ||||
1140 | } | ||||
1141 | |||||
1142 | # Check if there is an option argument available. | ||||
1143 | 5 | 1µs | if ( defined $optarg | ||
1144 | ? ($optarg eq '') | ||||
1145 | : !(defined $rest || @$argv > 0) ) { | ||||
1146 | # Complain if this option needs an argument. | ||||
1147 | # if ( $mand && !($type eq 's' ? defined($optarg) : 0) ) { | ||||
1148 | if ( $mand || $ctl->[CTL_DEST] == CTL_DEST_HASH ) { | ||||
1149 | return (0) if $passthrough; | ||||
1150 | warn ("Option ", $opt, " requires an argument\n"); | ||||
1151 | $error++; | ||||
1152 | return (1, undef); | ||||
1153 | } | ||||
1154 | if ( $type eq 'I' ) { | ||||
1155 | # Fake incremental type. | ||||
1156 | my @c = @$ctl; | ||||
1157 | $c[CTL_TYPE] = '+'; | ||||
1158 | return (1, $opt, \@c, 1); | ||||
1159 | } | ||||
1160 | return (1, $opt, $ctl, | ||||
1161 | defined($ctl->[CTL_DEFAULT]) ? $ctl->[CTL_DEFAULT] : | ||||
1162 | $type eq 's' ? '' : 0); | ||||
1163 | } | ||||
1164 | |||||
1165 | # Get (possibly optional) argument. | ||||
1166 | 5 | 2µs | $arg = (defined $rest ? $rest | ||
1167 | : (defined $optarg ? $optarg : shift (@$argv))); | ||||
1168 | |||||
1169 | # Get key if this is a "name=value" pair for a hash option. | ||||
1170 | 5 | 400ns | my $key; | ||
1171 | 5 | 500ns | if ($ctl->[CTL_DEST] == CTL_DEST_HASH && defined $arg) { | ||
1172 | ($key, $arg) = ($arg =~ /^([^=]*)=(.*)$/s) ? ($1, $2) | ||||
1173 | : ($arg, defined($ctl->[CTL_DEFAULT]) ? $ctl->[CTL_DEFAULT] : | ||||
1174 | ($mand ? undef : ($type eq 's' ? "" : 1))); | ||||
1175 | if (! defined $arg) { | ||||
1176 | warn ("Option $opt, key \"$key\", requires a value\n"); | ||||
1177 | $error++; | ||||
1178 | # Push back. | ||||
1179 | unshift (@$argv, $starter.$rest) if defined $rest; | ||||
1180 | return (1, undef); | ||||
1181 | } | ||||
1182 | } | ||||
1183 | |||||
1184 | #### Check if the argument is valid for this option #### | ||||
1185 | |||||
1186 | 5 | 1µs | my $key_valid = $ctl->[CTL_DEST] == CTL_DEST_HASH ? "[^=]+=" : ""; | ||
1187 | |||||
1188 | 5 | 700ns | if ( $type eq 's' ) { # string | ||
1189 | # A mandatory string takes anything. | ||||
1190 | 5 | 8µs | return (1, $opt, $ctl, $arg, $key) if $mand; | ||
1191 | |||||
1192 | # Same for optional string as a hash value | ||||
1193 | return (1, $opt, $ctl, $arg, $key) | ||||
1194 | if $ctl->[CTL_DEST] == CTL_DEST_HASH; | ||||
1195 | |||||
1196 | # An optional string takes almost anything. | ||||
1197 | return (1, $opt, $ctl, $arg, $key) | ||||
1198 | if defined $optarg || defined $rest; | ||||
1199 | return (1, $opt, $ctl, $arg, $key) if $arg eq "-"; # ?? | ||||
1200 | |||||
1201 | # Check for option or option list terminator. | ||||
1202 | if ($arg eq $argend || | ||||
1203 | $arg =~ /^$prefix.+/) { | ||||
1204 | # Push back. | ||||
1205 | unshift (@$argv, $arg); | ||||
1206 | # Supply empty value. | ||||
1207 | $arg = ''; | ||||
1208 | } | ||||
1209 | } | ||||
1210 | |||||
1211 | elsif ( $type eq 'i' # numeric/integer | ||||
1212 | || $type eq 'I' # numeric/integer w/ incr default | ||||
1213 | || $type eq 'o' ) { # dec/oct/hex/bin value | ||||
1214 | |||||
1215 | my $o_valid = $type eq 'o' ? PAT_XINT : PAT_INT; | ||||
1216 | |||||
1217 | if ( $bundling && defined $rest | ||||
1218 | && $rest =~ /^($key_valid)($o_valid)(.*)$/si ) { | ||||
1219 | ($key, $arg, $rest) = ($1, $2, $+); | ||||
1220 | chop($key) if $key; | ||||
1221 | $arg = ($type eq 'o' && $arg =~ /^0/) ? oct($arg) : 0+$arg; | ||||
1222 | unshift (@$argv, $starter.$rest) if defined $rest && $rest ne ''; | ||||
1223 | } | ||||
1224 | elsif ( $arg =~ /^$o_valid$/si ) { | ||||
1225 | $arg =~ tr/_//d; | ||||
1226 | $arg = ($type eq 'o' && $arg =~ /^0/) ? oct($arg) : 0+$arg; | ||||
1227 | } | ||||
1228 | else { | ||||
1229 | if ( defined $optarg || $mand ) { | ||||
1230 | if ( $passthrough ) { | ||||
1231 | unshift (@$argv, defined $rest ? $starter.$rest : $arg) | ||||
1232 | unless defined $optarg; | ||||
1233 | return (0); | ||||
1234 | } | ||||
1235 | warn ("Value \"", $arg, "\" invalid for option ", | ||||
1236 | $opt, " (", | ||||
1237 | $type eq 'o' ? "extended " : '', | ||||
1238 | "number expected)\n"); | ||||
1239 | $error++; | ||||
1240 | # Push back. | ||||
1241 | unshift (@$argv, $starter.$rest) if defined $rest; | ||||
1242 | return (1, undef); | ||||
1243 | } | ||||
1244 | else { | ||||
1245 | # Push back. | ||||
1246 | unshift (@$argv, defined $rest ? $starter.$rest : $arg); | ||||
1247 | if ( $type eq 'I' ) { | ||||
1248 | # Fake incremental type. | ||||
1249 | my @c = @$ctl; | ||||
1250 | $c[CTL_TYPE] = '+'; | ||||
1251 | return (1, $opt, \@c, 1); | ||||
1252 | } | ||||
1253 | # Supply default value. | ||||
1254 | $arg = defined($ctl->[CTL_DEFAULT]) ? $ctl->[CTL_DEFAULT] : 0; | ||||
1255 | } | ||||
1256 | } | ||||
1257 | } | ||||
1258 | |||||
1259 | elsif ( $type eq 'f' ) { # real number, int is also ok | ||||
1260 | my $o_valid = PAT_FLOAT; | ||||
1261 | if ( $bundling && defined $rest && | ||||
1262 | $rest =~ /^($key_valid)($o_valid)(.*)$/s ) { | ||||
1263 | $arg =~ tr/_//d; | ||||
1264 | ($key, $arg, $rest) = ($1, $2, $+); | ||||
1265 | chop($key) if $key; | ||||
1266 | unshift (@$argv, $starter.$rest) if defined $rest && $rest ne ''; | ||||
1267 | } | ||||
1268 | elsif ( $arg =~ /^$o_valid$/ ) { | ||||
1269 | $arg =~ tr/_//d; | ||||
1270 | } | ||||
1271 | else { | ||||
1272 | if ( defined $optarg || $mand ) { | ||||
1273 | if ( $passthrough ) { | ||||
1274 | unshift (@$argv, defined $rest ? $starter.$rest : $arg) | ||||
1275 | unless defined $optarg; | ||||
1276 | return (0); | ||||
1277 | } | ||||
1278 | warn ("Value \"", $arg, "\" invalid for option ", | ||||
1279 | $opt, " (real number expected)\n"); | ||||
1280 | $error++; | ||||
1281 | # Push back. | ||||
1282 | unshift (@$argv, $starter.$rest) if defined $rest; | ||||
1283 | return (1, undef); | ||||
1284 | } | ||||
1285 | else { | ||||
1286 | # Push back. | ||||
1287 | unshift (@$argv, defined $rest ? $starter.$rest : $arg); | ||||
1288 | # Supply default value. | ||||
1289 | $arg = 0.0; | ||||
1290 | } | ||||
1291 | } | ||||
1292 | } | ||||
1293 | else { | ||||
1294 | die("Getopt::Long internal error (Can't happen)\n"); | ||||
1295 | } | ||||
1296 | return (1, $opt, $ctl, $arg, $key); | ||||
1297 | } | ||||
1298 | |||||
1299 | sub ValidValue ($$$$$) { | ||||
1300 | my ($ctl, $arg, $mand, $argend, $prefix) = @_; | ||||
1301 | |||||
1302 | if ( $ctl->[CTL_DEST] == CTL_DEST_HASH ) { | ||||
1303 | return 0 unless $arg =~ /[^=]+=(.*)/; | ||||
1304 | $arg = $1; | ||||
1305 | } | ||||
1306 | |||||
1307 | my $type = $ctl->[CTL_TYPE]; | ||||
1308 | |||||
1309 | if ( $type eq 's' ) { # string | ||||
1310 | # A mandatory string takes anything. | ||||
1311 | return (1) if $mand; | ||||
1312 | |||||
1313 | return (1) if $arg eq "-"; | ||||
1314 | |||||
1315 | # Check for option or option list terminator. | ||||
1316 | return 0 if $arg eq $argend || $arg =~ /^$prefix.+/; | ||||
1317 | return 1; | ||||
1318 | } | ||||
1319 | |||||
1320 | elsif ( $type eq 'i' # numeric/integer | ||||
1321 | || $type eq 'I' # numeric/integer w/ incr default | ||||
1322 | || $type eq 'o' ) { # dec/oct/hex/bin value | ||||
1323 | |||||
1324 | my $o_valid = $type eq 'o' ? PAT_XINT : PAT_INT; | ||||
1325 | return $arg =~ /^$o_valid$/si; | ||||
1326 | } | ||||
1327 | |||||
1328 | elsif ( $type eq 'f' ) { # real number, int is also ok | ||||
1329 | my $o_valid = PAT_FLOAT; | ||||
1330 | return $arg =~ /^$o_valid$/; | ||||
1331 | } | ||||
1332 | die("ValidValue: Cannot happen\n"); | ||||
1333 | } | ||||
1334 | |||||
1335 | # Getopt::Long Configuration. | ||||
1336 | sub Configure (@) { | ||||
1337 | 2 | 900ns | my (@options) = @_; | ||
1338 | |||||
1339 | 2 | 3µs | my $prevconfig = | ||
1340 | [ $error, $debug, $major_version, $minor_version, $caller, | ||||
1341 | $autoabbrev, $getopt_compat, $ignorecase, $bundling, $order, | ||||
1342 | $gnu_compat, $passthrough, $genprefix, $auto_version, $auto_help, | ||||
1343 | $longprefix, $bundling_values ]; | ||||
1344 | |||||
1345 | 2 | 700ns | if ( ref($options[0]) eq 'ARRAY' ) { | ||
1346 | ( $error, $debug, $major_version, $minor_version, $caller, | ||||
1347 | $autoabbrev, $getopt_compat, $ignorecase, $bundling, $order, | ||||
1348 | $gnu_compat, $passthrough, $genprefix, $auto_version, $auto_help, | ||||
1349 | $longprefix, $bundling_values ) = @{shift(@options)}; | ||||
1350 | } | ||||
1351 | |||||
1352 | 2 | 300ns | my $opt; | ||
1353 | 2 | 1µs | foreach $opt ( @options ) { | ||
1354 | 2 | 900ns | my $try = lc ($opt); | ||
1355 | 2 | 200ns | my $action = 1; | ||
1356 | 2 | 2µs | 2 | 500ns | if ( $try =~ /^no_?(.*)$/s ) { # spent 500ns making 2 calls to Getopt::Long::CORE:match, avg 250ns/call |
1357 | $action = 0; | ||||
1358 | $try = $+; | ||||
1359 | } | ||||
1360 | 2 | 5µs | 1 | 1µs | if ( ($try eq 'default' or $try eq 'defaults') && $action ) { # spent 1µs making 1 call to Getopt::Long::CORE:match |
1361 | ConfigDefaults (); | ||||
1362 | } | ||||
1363 | elsif ( ($try eq 'posix_default' or $try eq 'posix_defaults') ) { | ||||
1364 | local $ENV{POSIXLY_CORRECT}; | ||||
1365 | $ENV{POSIXLY_CORRECT} = 1 if $action; | ||||
1366 | ConfigDefaults (); | ||||
1367 | } | ||||
1368 | elsif ( $try eq 'auto_abbrev' or $try eq 'autoabbrev' ) { | ||||
1369 | $autoabbrev = $action; | ||||
1370 | } | ||||
1371 | elsif ( $try eq 'getopt_compat' ) { | ||||
1372 | $getopt_compat = $action; | ||||
1373 | $genprefix = $action ? "(--|-|\\+)" : "(--|-)"; | ||||
1374 | } | ||||
1375 | elsif ( $try eq 'gnu_getopt' ) { | ||||
1376 | 1 | 300ns | if ( $action ) { | ||
1377 | 1 | 100ns | $gnu_compat = 1; | ||
1378 | 1 | 100ns | $bundling = 1; | ||
1379 | 1 | 100ns | $getopt_compat = 0; | ||
1380 | 1 | 200ns | $genprefix = "(--|-)"; | ||
1381 | 1 | 100ns | $order = $PERMUTE; | ||
1382 | 1 | 100ns | $bundling_values = 0; | ||
1383 | } | ||||
1384 | } | ||||
1385 | elsif ( $try eq 'gnu_compat' ) { | ||||
1386 | $gnu_compat = $action; | ||||
1387 | $bundling = 0; | ||||
1388 | $bundling_values = 1; | ||||
1389 | } | ||||
1390 | elsif ( $try =~ /^(auto_?)?version$/ ) { | ||||
1391 | 1 | 200ns | $auto_version = $action; | ||
1392 | } | ||||
1393 | elsif ( $try =~ /^(auto_?)?help$/ ) { | ||||
1394 | $auto_help = $action; | ||||
1395 | } | ||||
1396 | elsif ( $try eq 'ignorecase' or $try eq 'ignore_case' ) { | ||||
1397 | $ignorecase = $action; | ||||
1398 | } | ||||
1399 | elsif ( $try eq 'ignorecase_always' or $try eq 'ignore_case_always' ) { | ||||
1400 | $ignorecase = $action ? 2 : 0; | ||||
1401 | } | ||||
1402 | elsif ( $try eq 'bundling' ) { | ||||
1403 | $bundling = $action; | ||||
1404 | $bundling_values = 0 if $action; | ||||
1405 | } | ||||
1406 | elsif ( $try eq 'bundling_override' ) { | ||||
1407 | $bundling = $action ? 2 : 0; | ||||
1408 | $bundling_values = 0 if $action; | ||||
1409 | } | ||||
1410 | elsif ( $try eq 'bundling_values' ) { | ||||
1411 | $bundling_values = $action; | ||||
1412 | $bundling = 0 if $action; | ||||
1413 | } | ||||
1414 | elsif ( $try eq 'require_order' ) { | ||||
1415 | $order = $action ? $REQUIRE_ORDER : $PERMUTE; | ||||
1416 | } | ||||
1417 | elsif ( $try eq 'permute' ) { | ||||
1418 | $order = $action ? $PERMUTE : $REQUIRE_ORDER; | ||||
1419 | } | ||||
1420 | elsif ( $try eq 'pass_through' or $try eq 'passthrough' ) { | ||||
1421 | $passthrough = $action; | ||||
1422 | } | ||||
1423 | elsif ( $try =~ /^prefix=(.+)$/ && $action ) { | ||||
1424 | $genprefix = $1; | ||||
1425 | # Turn into regexp. Needs to be parenthesized! | ||||
1426 | $genprefix = "(" . quotemeta($genprefix) . ")"; | ||||
1427 | eval { '' =~ /$genprefix/; }; | ||||
1428 | die("Getopt::Long: invalid pattern \"$genprefix\"\n") if $@; | ||||
1429 | } | ||||
1430 | elsif ( $try =~ /^prefix_pattern=(.+)$/ && $action ) { | ||||
1431 | $genprefix = $1; | ||||
1432 | # Parenthesize if needed. | ||||
1433 | $genprefix = "(" . $genprefix . ")" | ||||
1434 | unless $genprefix =~ /^\(.*\)$/; | ||||
1435 | eval { '' =~ m"$genprefix"; }; | ||||
1436 | die("Getopt::Long: invalid pattern \"$genprefix\"\n") if $@; | ||||
1437 | } | ||||
1438 | elsif ( $try =~ /^long_prefix_pattern=(.+)$/ && $action ) { | ||||
1439 | $longprefix = $1; | ||||
1440 | # Parenthesize if needed. | ||||
1441 | $longprefix = "(" . $longprefix . ")" | ||||
1442 | unless $longprefix =~ /^\(.*\)$/; | ||||
1443 | eval { '' =~ m"$longprefix"; }; | ||||
1444 | die("Getopt::Long: invalid long prefix pattern \"$longprefix\"\n") if $@; | ||||
1445 | } | ||||
1446 | elsif ( $try eq 'debug' ) { | ||||
1447 | $debug = $action; | ||||
1448 | } | ||||
1449 | else { | ||||
1450 | die("Getopt::Long: unknown or erroneous config parameter \"$opt\"\n") | ||||
1451 | } | ||||
1452 | } | ||||
1453 | 2 | 5µs | $prevconfig; | ||
1454 | } | ||||
1455 | |||||
1456 | # Deprecated name. | ||||
1457 | sub config (@) { | ||||
1458 | Configure (@_); | ||||
1459 | } | ||||
1460 | |||||
1461 | # Issue a standard message for --version. | ||||
1462 | # | ||||
1463 | # The arguments are mostly the same as for Pod::Usage::pod2usage: | ||||
1464 | # | ||||
1465 | # - a number (exit value) | ||||
1466 | # - a string (lead in message) | ||||
1467 | # - a hash with options. See Pod::Usage for details. | ||||
1468 | # | ||||
1469 | sub VersionMessage(@) { | ||||
1470 | # Massage args. | ||||
1471 | my $pa = setup_pa_args("version", @_); | ||||
1472 | |||||
1473 | my $v = $main::VERSION; | ||||
1474 | my $fh = $pa->{-output} || | ||||
1475 | ( ($pa->{-exitval} eq "NOEXIT" || $pa->{-exitval} < 2) ? \*STDOUT : \*STDERR ); | ||||
1476 | |||||
1477 | print $fh (defined($pa->{-message}) ? $pa->{-message} : (), | ||||
1478 | $0, defined $v ? " version $v" : (), | ||||
1479 | "\n", | ||||
1480 | "(", __PACKAGE__, "::", "GetOptions", | ||||
1481 | " version ", | ||||
1482 | defined($Getopt::Long::VERSION_STRING) | ||||
1483 | ? $Getopt::Long::VERSION_STRING : $VERSION, ";", | ||||
1484 | " Perl version ", | ||||
1485 | $] >= 5.006 ? sprintf("%vd", $^V) : $], | ||||
1486 | ")\n"); | ||||
1487 | exit($pa->{-exitval}) unless $pa->{-exitval} eq "NOEXIT"; | ||||
1488 | } | ||||
1489 | |||||
1490 | # Issue a standard message for --help. | ||||
1491 | # | ||||
1492 | # The arguments are the same as for Pod::Usage::pod2usage: | ||||
1493 | # | ||||
1494 | # - a number (exit value) | ||||
1495 | # - a string (lead in message) | ||||
1496 | # - a hash with options. See Pod::Usage for details. | ||||
1497 | # | ||||
1498 | sub HelpMessage(@) { | ||||
1499 | eval { | ||||
1500 | require Pod::Usage; | ||||
1501 | import Pod::Usage; | ||||
1502 | 1; | ||||
1503 | } || die("Cannot provide help: cannot load Pod::Usage\n"); | ||||
1504 | |||||
1505 | # Note that pod2usage will issue a warning if -exitval => NOEXIT. | ||||
1506 | pod2usage(setup_pa_args("help", @_)); | ||||
1507 | |||||
1508 | } | ||||
1509 | |||||
1510 | # Helper routine to set up a normalized hash ref to be used as | ||||
1511 | # argument to pod2usage. | ||||
1512 | sub setup_pa_args($@) { | ||||
1513 | my $tag = shift; # who's calling | ||||
1514 | |||||
1515 | # If called by direct binding to an option, it will get the option | ||||
1516 | # name and value as arguments. Remove these, if so. | ||||
1517 | @_ = () if @_ == 2 && $_[0] eq $tag; | ||||
1518 | |||||
1519 | my $pa; | ||||
1520 | if ( @_ > 1 ) { | ||||
1521 | $pa = { @_ }; | ||||
1522 | } | ||||
1523 | else { | ||||
1524 | $pa = shift || {}; | ||||
1525 | } | ||||
1526 | |||||
1527 | # At this point, $pa can be a number (exit value), string | ||||
1528 | # (message) or hash with options. | ||||
1529 | |||||
1530 | if ( UNIVERSAL::isa($pa, 'HASH') ) { | ||||
1531 | # Get rid of -msg vs. -message ambiguity. | ||||
1532 | $pa->{-message} = $pa->{-msg}; | ||||
1533 | delete($pa->{-msg}); | ||||
1534 | } | ||||
1535 | elsif ( $pa =~ /^-?\d+$/ ) { | ||||
1536 | $pa = { -exitval => $pa }; | ||||
1537 | } | ||||
1538 | else { | ||||
1539 | $pa = { -message => $pa }; | ||||
1540 | } | ||||
1541 | |||||
1542 | # These are _our_ defaults. | ||||
1543 | $pa->{-verbose} = 0 unless exists($pa->{-verbose}); | ||||
1544 | $pa->{-exitval} = 0 unless exists($pa->{-exitval}); | ||||
1545 | $pa; | ||||
1546 | } | ||||
1547 | |||||
1548 | # Sneak way to know what version the user requested. | ||||
1549 | sub VERSION { | ||||
1550 | $requested_version = $_[1] if @_ > 1; | ||||
1551 | shift->SUPER::VERSION(@_); | ||||
1552 | } | ||||
1553 | |||||
1554 | package Getopt::Long::CallBack; | ||||
1555 | |||||
1556 | sub new { | ||||
1557 | my ($pkg, %atts) = @_; | ||||
1558 | bless { %atts }, $pkg; | ||||
1559 | } | ||||
1560 | |||||
1561 | sub name { | ||||
1562 | my $self = shift; | ||||
1563 | ''.$self->{name}; | ||||
1564 | } | ||||
1565 | |||||
1566 | sub given { | ||||
1567 | my $self = shift; | ||||
1568 | $self->{given}; | ||||
1569 | } | ||||
1570 | |||||
1571 | use overload | ||||
1572 | # Treat this object as an ordinary string for legacy API. | ||||
1573 | 1 | 5µs | 1 | 22µs | # spent 30µs (8+22) within Getopt::Long::CallBack::BEGIN@1573 which was called:
# once (8µs+22µs) by main::BEGIN@32 at line 1574 # spent 22µs making 1 call to overload::import |
1574 | 1 | 47µs | 1 | 30µs | fallback => 1; # spent 30µs making 1 call to Getopt::Long::CallBack::BEGIN@1573 |
1575 | |||||
1576 | 1 | 11µs | 1; | ||
1577 | |||||
1578 | ################ Documentation ################ | ||||
1579 | |||||
# spent 45µs within Getopt::Long::CORE:match which was called 34 times, avg 1µs/call:
# 6 times (3µs+0s) by Getopt::Long::FindOption at line 935, avg 467ns/call
# 5 times (21µs+0s) by Getopt::Long::ParseOptionSpec at line 806, avg 4µs/call
# 5 times (3µs+0s) by Getopt::Long::GetOptionsFromArray at line 364, avg 580ns/call
# 5 times (100ns+0s) by Getopt::Long::FindOption at line 948, avg 20ns/call
# 4 times (5µs+0s) by Getopt::Long::ParseOptionSpec at line 866, avg 1µs/call
# 4 times (400ns+0s) by Getopt::Long::ParseOptionSpec at line 850, avg 100ns/call
# 2 times (500ns+0s) by Getopt::Long::Configure at line 1356, avg 250ns/call
# once (9µs+0s) by main::BEGIN@32 at line 129
# once (3µs+0s) by Getopt::Long::GetOptionsFromArray at line 342
# once (1µs+0s) by Getopt::Long::Configure at line 1360 | |||||
# spent 33µs within Getopt::Long::CORE:regcomp which was called 16 times, avg 2µs/call:
# 6 times (12µs+0s) by Getopt::Long::FindOption at line 935, avg 2µs/call
# 5 times (16µs+0s) by Getopt::Long::GetOptionsFromArray at line 364, avg 3µs/call
# 5 times (5µs+0s) by Getopt::Long::FindOption at line 948, avg 980ns/call |