| Filename | /usr/share/perl/5.28/Getopt/Long.pm |
| Statements | Executed 1322 statements in 9.58ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 27 | 1 | 1 | 358µs | 436µs | Getopt::Long::ParseOptionSpec |
| 1 | 1 | 1 | 235µs | 1.00ms | Getopt::Long::GetOptionsFromArray |
| 3 | 1 | 1 | 194µs | 266µs | Getopt::Long::FindOption |
| 175 | 9 | 1 | 135µs | 135µs | Getopt::Long::CORE:match (opcode) |
| 98 | 4 | 1 | 91µs | 91µs | Getopt::Long::CORE:regcomp (opcode) |
| 1 | 1 | 1 | 25µs | 25µs | main::BEGIN@13 |
| 1 | 1 | 1 | 24µs | 46µs | Getopt::Long::BEGIN@232 |
| 1 | 1 | 1 | 16µs | 60µs | Getopt::Long::CallBack::BEGIN@1568 |
| 2 | 1 | 1 | 13µs | 13µs | Getopt::Long::CORE:sort (opcode) |
| 1 | 1 | 1 | 13µs | 188µs | Getopt::Long::import |
| 1 | 1 | 1 | 12µs | 17µs | main::BEGIN@15 |
| 1 | 1 | 1 | 12µs | 77µs | Getopt::Long::BEGIN@220 |
| 1 | 1 | 1 | 9µs | 39µs | Getopt::Long::BEGIN@20 |
| 1 | 1 | 1 | 9µs | 43µs | main::BEGIN@16 |
| 1 | 1 | 1 | 8µs | 8µs | Getopt::Long::ConfigDefaults |
| 1 | 1 | 1 | 8µs | 22µs | Getopt::Long::BEGIN@26 |
| 1 | 1 | 1 | 7µs | 58µs | Getopt::Long::BEGIN@259 |
| 1 | 1 | 1 | 6µs | 19µs | Getopt::Long::BEGIN@23 |
| 1 | 1 | 1 | 6µs | 33µs | Getopt::Long::BEGIN@234 |
| 1 | 1 | 1 | 6µs | 25µs | Getopt::Long::BEGIN@237 |
| 1 | 1 | 1 | 5µs | 29µs | Getopt::Long::BEGIN@235 |
| 1 | 1 | 1 | 5µs | 74µs | Getopt::Long::BEGIN@46 |
| 1 | 1 | 1 | 5µs | 29µs | Getopt::Long::BEGIN@230 |
| 1 | 1 | 1 | 5µs | 42µs | Getopt::Long::BEGIN@47 |
| 1 | 1 | 1 | 5µs | 26µs | Getopt::Long::BEGIN@238 |
| 1 | 1 | 1 | 5µs | 26µs | Getopt::Long::BEGIN@240 |
| 1 | 1 | 1 | 5µs | 53µs | Getopt::Long::BEGIN@49 |
| 1 | 1 | 1 | 5µs | 46µs | Getopt::Long::BEGIN@52 |
| 1 | 1 | 1 | 5µs | 31µs | Getopt::Long::BEGIN@249 |
| 1 | 1 | 1 | 5µs | 33µs | Getopt::Long::BEGIN@27 |
| 1 | 1 | 1 | 5µs | 5µs | Getopt::Long::BEGIN@38 |
| 1 | 1 | 1 | 4µs | 25µs | Getopt::Long::BEGIN@241 |
| 1 | 1 | 1 | 4µs | 26µs | Getopt::Long::BEGIN@236 |
| 1 | 1 | 1 | 4µs | 25µs | Getopt::Long::BEGIN@248 |
| 1 | 1 | 1 | 4µs | 4µs | Getopt::Long::Configure |
| 1 | 1 | 1 | 2µs | 2µs | main::__ANON__ (xsub) |
| 1 | 1 | 1 | 700ns | 700ns | main::CORE:subst (opcode) |
| 0 | 0 | 0 | 0s | 0s | Getopt::Long::CallBack::name |
| 0 | 0 | 0 | 0s | 0s | Getopt::Long::CallBack::new |
| 0 | 0 | 0 | 0s | 0s | Getopt::Long::GetOptions |
| 0 | 0 | 0 | 0s | 0s | Getopt::Long::GetOptionsFromString |
| 0 | 0 | 0 | 0s | 0s | Getopt::Long::HelpMessage |
| 0 | 0 | 0 | 0s | 0s | Getopt::Long::OptCtl |
| 0 | 0 | 0 | 0s | 0s | Getopt::Long::Parser::configure |
| 0 | 0 | 0 | 0s | 0s | Getopt::Long::Parser::getoptions |
| 0 | 0 | 0 | 0s | 0s | Getopt::Long::Parser::getoptionsfromarray |
| 0 | 0 | 0 | 0s | 0s | Getopt::Long::Parser::new |
| 0 | 0 | 0 | 0s | 0s | Getopt::Long::VERSION |
| 0 | 0 | 0 | 0s | 0s | Getopt::Long::ValidValue |
| 0 | 0 | 0 | 0s | 0s | Getopt::Long::VersionMessage |
| 0 | 0 | 0 | 0s | 0s | Getopt::Long::config |
| 0 | 0 | 0 | 0s | 0s | Getopt::Long::setup_pa_args |
| 0 | 0 | 0 | 0s | 0s | main::RUNTIME |
| 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: Sat May 27 12:11:39 2017 | ||||
| 8 | # Update Count : 1715 | ||||
| 9 | # Status : Released | ||||
| 10 | |||||
| 11 | ################ Module Preamble ################ | ||||
| 12 | |||||
| 13 | 2 | 52µs | 1 | 25µs | # spent 25µs within main::BEGIN@13 which was called:
# once (25µs+0s) by main::BEGIN@8 at line 13 # spent 25µs making 1 call to main::BEGIN@13 |
| 14 | |||||
| 15 | 2 | 23µs | 2 | 22µs | # spent 17µs (12+5) within main::BEGIN@15 which was called:
# once (12µs+5µs) by main::BEGIN@8 at line 15 # spent 17µs making 1 call to main::BEGIN@15
# spent 5µs making 1 call to strict::import |
| 16 | 2 | 37µs | 2 | 78µs | # spent 43µs (9+34) within main::BEGIN@16 which was called:
# once (9µs+34µs) by main::BEGIN@8 at line 16 # spent 43µs making 1 call to main::BEGIN@16
# spent 34µs making 1 call to warnings::import |
| 17 | |||||
| 18 | package Getopt::Long; | ||||
| 19 | |||||
| 20 | 2 | 34µs | 2 | 68µs | # spent 39µs (9+30) within Getopt::Long::BEGIN@20 which was called:
# once (9µs+30µs) by main::BEGIN@8 at line 20 # spent 39µs making 1 call to Getopt::Long::BEGIN@20
# spent 30µs making 1 call to vars::import |
| 21 | 1 | 800ns | $VERSION = 2.50; | ||
| 22 | # For testing versions only. | ||||
| 23 | 2 | 26µs | 2 | 32µs | # spent 19µs (6+13) within Getopt::Long::BEGIN@23 which was called:
# once (6µs+13µs) by main::BEGIN@8 at line 23 # spent 19µs making 1 call to Getopt::Long::BEGIN@23
# spent 13µs making 1 call to vars::import |
| 24 | 1 | 700ns | $VERSION_STRING = "2.50"; | ||
| 25 | |||||
| 26 | 2 | 28µs | 2 | 35µs | # spent 22µs (8+13) within Getopt::Long::BEGIN@26 which was called:
# once (8µs+13µs) by main::BEGIN@8 at line 26 # spent 22µs making 1 call to Getopt::Long::BEGIN@26
# spent 13µs making 1 call to Exporter::import |
| 27 | 2 | 125µs | 2 | 62µs | # spent 33µs (5+28) within Getopt::Long::BEGIN@27 which was called:
# once (5µs+28µs) by main::BEGIN@8 at line 27 # spent 33µs making 1 call to Getopt::Long::BEGIN@27
# spent 28µs making 1 call to vars::import |
| 28 | 1 | 11µ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 5µs within Getopt::Long::BEGIN@38 which was called:
# once (5µs+0s) by main::BEGIN@8 at line 43 | ||||
| 39 | # Init immediately so their contents can be used in the 'use vars' below. | ||||
| 40 | 1 | 900ns | @EXPORT = qw(&GetOptions $REQUIRE_ORDER $PERMUTE $RETURN_IN_ORDER); | ||
| 41 | 1 | 5µs | @EXPORT_OK = qw(&HelpMessage &VersionMessage &Configure | ||
| 42 | &GetOptionsFromArray &GetOptionsFromString); | ||||
| 43 | 1 | 24µs | 1 | 5µs | } # spent 5µs making 1 call to Getopt::Long::BEGIN@38 |
| 44 | |||||
| 45 | # User visible variables. | ||||
| 46 | 2 | 25µs | 2 | 142µs | # spent 74µs (5+68) within Getopt::Long::BEGIN@46 which was called:
# once (5µs+68µs) by main::BEGIN@8 at line 46 # spent 74µs making 1 call to Getopt::Long::BEGIN@46
# spent 68µs making 1 call to vars::import |
| 47 | 2 | 26µs | 2 | 80µs | # spent 42µs (5+37) within Getopt::Long::BEGIN@47 which was called:
# once (5µs+37µs) by main::BEGIN@8 at line 47 # spent 42µs making 1 call to Getopt::Long::BEGIN@47
# spent 37µs making 1 call to vars::import |
| 48 | # Deprecated visible variables. | ||||
| 49 | 1 | 3µs | 1 | 48µs | # spent 53µs (5+48) within Getopt::Long::BEGIN@49 which was called:
# once (5µs+48µs) by main::BEGIN@8 at line 50 # spent 48µs making 1 call to vars::import |
| 50 | 1 | 22µs | 1 | 53µs | $passthrough); # spent 53µs making 1 call to Getopt::Long::BEGIN@49 |
| 51 | # Official invisible variables. | ||||
| 52 | 2 | 714µs | 2 | 87µs | # spent 46µs (5+41) within Getopt::Long::BEGIN@52 which was called:
# once (5µs+41µs) by main::BEGIN@8 at line 52 # spent 46µs making 1 call to Getopt::Long::BEGIN@52
# spent 41µ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 8µs within Getopt::Long::ConfigDefaults which was called:
# once (8µs+0s) by main::BEGIN@8 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 | 900ns | $genprefix = "(--|-|\\+)"; | ||
| 87 | 1 | 400ns | $autoabbrev = 1; # automatic abbrev of options | ||
| 88 | 1 | 600ns | $bundling = 0; # bundling off by default | ||
| 89 | 1 | 100ns | $getopt_compat = 1; # allow '+' to start options | ||
| 90 | 1 | 500ns | $order = $PERMUTE; | ||
| 91 | } | ||||
| 92 | # Other configurable settings. | ||||
| 93 | 1 | 1µs | $debug = 0; # for debugging | ||
| 94 | 1 | 300ns | $error = 0; # error tally | ||
| 95 | 1 | 300ns | $ignorecase = 1; # ignore case when matching options | ||
| 96 | 1 | 200ns | $passthrough = 0; # leave unrecognized options alone | ||
| 97 | 1 | 200ns | $gnu_compat = 0; # require --opt=val if value is optional | ||
| 98 | 1 | 900ns | $longprefix = "(--)"; # what does a long prefix look like | ||
| 99 | 1 | 3µs | $bundling_values = 0; # no bundling of values | ||
| 100 | } | ||||
| 101 | |||||
| 102 | # Override import. | ||||
| 103 | # spent 188µs (13+175) within Getopt::Long::import which was called:
# once (13µs+175µs) by main::BEGIN@8 at line 8 of /root/tor-browser-build/rbm/rbm | ||||
| 104 | 1 | 500ns | my $pkg = shift; # package | ||
| 105 | 1 | 300ns | my @syms = (); # symbols to import | ||
| 106 | 1 | 100ns | my @config = (); # configuration | ||
| 107 | 1 | 800ns | my $dest = \@syms; # symbols first | ||
| 108 | 1 | 700ns | for ( @_ ) { | ||
| 109 | if ( $_ eq ':config' ) { | ||||
| 110 | $dest = \@config; # config next | ||||
| 111 | next; | ||||
| 112 | } | ||||
| 113 | push(@$dest, $_); # push | ||||
| 114 | } | ||||
| 115 | # Hide one level and call super. | ||||
| 116 | 1 | 900ns | local $Exporter::ExportLevel = 1; | ||
| 117 | 1 | 500ns | push(@syms, qw(&GetOptions)) if @syms; # always export GetOptions | ||
| 118 | 1 | 500ns | $requested_version = 0; | ||
| 119 | 1 | 6µs | 1 | 175µs | $pkg->SUPER::import(@syms); # spent 175µs making 1 call to Exporter::import |
| 120 | # And configure. | ||||
| 121 | 1 | 4µs | Configure(@config) if @config; | ||
| 122 | } | ||||
| 123 | |||||
| 124 | ################ Initialization ################ | ||||
| 125 | |||||
| 126 | # Values for $order. See GNU getopt.c for details. | ||||
| 127 | 1 | 800ns | ($REQUIRE_ORDER, $PERMUTE, $RETURN_IN_ORDER) = (0..2); | ||
| 128 | # Version major/minor numbers. | ||||
| 129 | 1 | 32µs | 1 | 24µs | ($major_version, $minor_version) = $VERSION =~ /^(\d+)\.(\d+)/; # spent 24µs making 1 call to Getopt::Long::CORE:match |
| 130 | |||||
| 131 | 1 | 2µs | 1 | 8µs | ConfigDefaults(); # spent 8µ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 | 800ns | 1 | 4µs | my $default_config = do { # spent 4µ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 | 38µs | 2 | 142µs | # spent 77µs (12+65) within Getopt::Long::BEGIN@220 which was called:
# once (12µs+65µs) by main::BEGIN@8 at line 220 # spent 77µs making 1 call to Getopt::Long::BEGIN@220
# spent 65µ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 | 22µs | 2 | 52µs | # spent 29µs (5+24) within Getopt::Long::BEGIN@230 which was called:
# once (5µs+24µs) by main::BEGIN@8 at line 230 # spent 29µs making 1 call to Getopt::Long::BEGIN@230
# spent 24µs making 1 call to constant::import |
| 231 | |||||
| 232 | 2 | 22µs | 2 | 68µs | # spent 46µs (24+22) within Getopt::Long::BEGIN@232 which was called:
# once (24µs+22µs) by main::BEGIN@8 at line 232 # spent 46µs making 1 call to Getopt::Long::BEGIN@232
# spent 22µs making 1 call to constant::import |
| 233 | |||||
| 234 | 2 | 24µs | 2 | 59µs | # spent 33µs (6+27) within Getopt::Long::BEGIN@234 which was called:
# once (6µs+27µs) by main::BEGIN@8 at line 234 # spent 33µs making 1 call to Getopt::Long::BEGIN@234
# spent 27µs making 1 call to constant::import |
| 235 | 2 | 20µs | 2 | 53µs | # spent 29µs (5+24) within Getopt::Long::BEGIN@235 which was called:
# once (5µs+24µs) by main::BEGIN@8 at line 235 # spent 29µs making 1 call to Getopt::Long::BEGIN@235
# spent 24µs making 1 call to constant::import |
| 236 | 2 | 21µs | 2 | 47µs | # spent 26µs (4+22) within Getopt::Long::BEGIN@236 which was called:
# once (4µs+22µs) by main::BEGIN@8 at line 236 # spent 26µs making 1 call to Getopt::Long::BEGIN@236
# spent 22µs making 1 call to constant::import |
| 237 | 2 | 20µs | 2 | 45µs | # spent 25µs (6+20) within Getopt::Long::BEGIN@237 which was called:
# once (6µs+20µs) by main::BEGIN@8 at line 237 # spent 25µs making 1 call to Getopt::Long::BEGIN@237
# spent 20µs making 1 call to constant::import |
| 238 | 2 | 19µs | 2 | 47µs | # spent 26µs (5+21) within Getopt::Long::BEGIN@238 which was called:
# once (5µs+21µs) by main::BEGIN@8 at line 238 # spent 26µs making 1 call to Getopt::Long::BEGIN@238
# spent 21µs making 1 call to constant::import |
| 239 | |||||
| 240 | 2 | 23µs | 2 | 47µs | # spent 26µs (5+21) within Getopt::Long::BEGIN@240 which was called:
# once (5µs+21µs) by main::BEGIN@8 at line 240 # spent 26µs making 1 call to Getopt::Long::BEGIN@240
# spent 21µs making 1 call to constant::import |
| 241 | 2 | 27µs | 2 | 46µs | # spent 25µs (4+20) within Getopt::Long::BEGIN@241 which was called:
# once (4µs+20µs) by main::BEGIN@8 at line 241 # spent 25µs making 1 call to Getopt::Long::BEGIN@241
# spent 20µ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 | 38µs | 2 | 45µs | # spent 25µs (4+21) within Getopt::Long::BEGIN@248 which was called:
# once (4µs+21µs) by main::BEGIN@8 at line 248 # spent 25µs making 1 call to Getopt::Long::BEGIN@248
# spent 20µs making 1 call to constant::import |
| 249 | 1 | 3µs | 1 | 26µs | # spent 31µs (5+26) within Getopt::Long::BEGIN@249 which was called:
# once (5µs+26µs) by main::BEGIN@8 at line 258 # spent 26µ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 | 34µs | 1 | 31µs | ")"; # spent 31µs making 1 call to Getopt::Long::BEGIN@249 |
| 259 | 1 | 4µs | 1 | 51µs | # spent 58µs (7+51) within Getopt::Long::BEGIN@259 which was called:
# once (7µs+51µs) by main::BEGIN@8 at line 264 # spent 51µ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 | 6.93ms | 1 | 58µs | "([eE][-+]?[0-9_]+)?"; # optional exponent # spent 58µs making 1 call to Getopt::Long::BEGIN@259 |
| 265 | |||||
| 266 | sub GetOptions(@) { | ||||
| 267 | # Shift in default array. | ||||
| 268 | unshift(@_, \@ARGV); | ||||
| 269 | # Try to keep caller() and Carp consistent. | ||||
| 270 | goto &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 1.00ms (235µs+769µs) within Getopt::Long::GetOptionsFromArray which was called:
# once (235µs+769µs) by main::set_options at line 100 of /root/tor-browser-build/rbm/rbm | ||||
| 288 | |||||
| 289 | 1 | 3µs | my ($argv, @optionlist) = @_; # local copy of the option descriptions | ||
| 290 | 1 | 800ns | my $argend = '--'; # option list terminator | ||
| 291 | 1 | 800ns | my %opctl = (); # table of option specs | ||
| 292 | 1 | 2µs | my $pkg = $caller || (caller)[0]; # current context | ||
| 293 | # Needed if linkage is omitted. | ||||
| 294 | 1 | 200ns | 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 | 1µs | my $prefix = $genprefix; # current prefix | ||
| 299 | |||||
| 300 | 1 | 1µs | $error = ''; | ||
| 301 | |||||
| 302 | 1 | 400ns | if ( $debug ) { | ||
| 303 | # Avoid some warnings if debugging. | ||||
| 304 | local ($^W) = 0; | ||||
| 305 | print STDERR | ||||
| 306 | ("Getopt::Long $Getopt::Long::VERSION ", | ||||
| 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 | 600ns | $userlinkage = undef; | ||
| 333 | 1 | 8µs | 1 | 2µs | if ( @optionlist && ref($optionlist[0]) and # spent 2µs making 1 call to UNIVERSAL::isa |
| 334 | UNIVERSAL::isa($optionlist[0],'HASH') ) { | ||||
| 335 | 1 | 500ns | $userlinkage = shift (@optionlist); | ||
| 336 | 1 | 200ns | 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 | 7µs | 1 | 2µs | if ( @optionlist && $optionlist[0] =~ /^\W+$/ # spent 2µ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 | 800ns | %opctl = (); | ||
| 355 | 1 | 4µs | while ( @optionlist ) { | ||
| 356 | 27 | 8µs | my $opt = shift (@optionlist); | ||
| 357 | |||||
| 358 | 27 | 3µs | 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 | 27 | 118µs | 54 | 61µs | $opt = $+ if $opt =~ /^$prefix+(.*)$/s; # spent 45µs making 27 calls to Getopt::Long::CORE:regcomp, avg 2µs/call
# spent 17µs making 27 calls to Getopt::Long::CORE:match, avg 615ns/call |
| 365 | |||||
| 366 | 27 | 5µs | 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 | 27 | 30µs | 27 | 436µs | my ($name, $orig) = ParseOptionSpec ($opt, \%opctl); # spent 436µs making 27 calls to Getopt::Long::ParseOptionSpec, avg 16µs/call |
| 387 | 27 | 3µs | 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 | 27 | 4µs | if ( defined $userlinkage ) { | ||
| 399 | 27 | 7µs | unless ( @optionlist > 0 && ref($optionlist[0]) ) { | ||
| 400 | 27 | 5µs | 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 | 27 | 15µ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 | 4µs | 1 | 700ns | $error .= "GetOptionsFromArray: 1st parameter is not an array reference\n" # spent 700ns making 1 call to UNIVERSAL::isa |
| 476 | unless $argv && UNIVERSAL::isa( $argv, 'ARRAY' ); | ||||
| 477 | |||||
| 478 | # Bail out if errors found. | ||||
| 479 | 1 | 400ns | die ($error) if $error; | ||
| 480 | 1 | 400ns | $error = 0; | ||
| 481 | |||||
| 482 | # Supply --version and --help support, if needed and allowed. | ||||
| 483 | 1 | 2µs | if ( defined($auto_version) ? $auto_version : ($requested_version >= 2.3203) ) { | ||
| 484 | if ( !defined($opctl{version}) ) { | ||||
| 485 | $opctl{version} = ['','version',0,CTL_DEST_CODE,undef]; | ||||
| 486 | $linkage{version} = \&VersionMessage; | ||||
| 487 | } | ||||
| 488 | $auto_version = 1; | ||||
| 489 | } | ||||
| 490 | 1 | 2µs | 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 | 400ns | 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 | 1µs | my $goon = 1; | ||
| 510 | 1 | 1µs | while ( $goon && @$argv > 0 ) { | ||
| 511 | |||||
| 512 | # Get next argument. | ||||
| 513 | 3 | 1µs | $opt = shift (@$argv); | ||
| 514 | 3 | 700ns | print STDERR ("=> arg \"", $opt, "\"\n") if $debug; | ||
| 515 | |||||
| 516 | # Double dash is option list terminator. | ||||
| 517 | 3 | 1µs | if ( defined($opt) && $opt eq $argend ) { | ||
| 518 | push (@ret, $argend) if $passthrough; | ||||
| 519 | last; | ||||
| 520 | } | ||||
| 521 | |||||
| 522 | # Look it up. | ||||
| 523 | 3 | 900ns | my $tryopt = $opt; | ||
| 524 | 3 | 800ns | my $found; # success status | ||
| 525 | my $key; # key (if hash type) | ||||
| 526 | my $arg; # option argument | ||||
| 527 | my $ctl; # the opctl entry | ||||
| 528 | |||||
| 529 | 3 | 7µs | 3 | 266µs | ($found, $opt, $ctl, $arg, $key) = # spent 266µs making 3 calls to Getopt::Long::FindOption, avg 89µs/call |
| 530 | FindOption ($argv, $prefix, $argend, $opt, \%opctl); | ||||
| 531 | |||||
| 532 | 3 | 2µs | if ( $found ) { | ||
| 533 | |||||
| 534 | # FindOption undefines $opt in case of errors. | ||||
| 535 | 2 | 400ns | next unless defined $opt; | ||
| 536 | |||||
| 537 | 2 | 500ns | my $argcnt = 0; | ||
| 538 | 2 | 500ns | while ( defined $arg ) { | ||
| 539 | |||||
| 540 | # Get the canonical name. | ||||
| 541 | 2 | 400ns | print STDERR ("=> cname for \"$opt\" is ") if $debug; | ||
| 542 | 2 | 900ns | $opt = $ctl->[CTL_CNAME]; | ||
| 543 | 2 | 600ns | print STDERR ("\"$ctl->[CTL_CNAME]\"\n") if $debug; | ||
| 544 | |||||
| 545 | 2 | 2µs | if ( defined $linkage{$opt} ) { | ||
| 546 | print STDERR ("=> ref(\$L{$opt}) -> ", | ||||
| 547 | ref($linkage{$opt}), "\n") if $debug; | ||||
| 548 | |||||
| 549 | if ( ref($linkage{$opt}) eq 'SCALAR' | ||||
| 550 | || ref($linkage{$opt}) eq 'REF' ) { | ||||
| 551 | if ( $ctl->[CTL_TYPE] eq '+' ) { | ||||
| 552 | print STDERR ("=> \$\$L{$opt} += \"$arg\"\n") | ||||
| 553 | if $debug; | ||||
| 554 | if ( defined ${$linkage{$opt}} ) { | ||||
| 555 | ${$linkage{$opt}} += $arg; | ||||
| 556 | } | ||||
| 557 | else { | ||||
| 558 | ${$linkage{$opt}} = $arg; | ||||
| 559 | } | ||||
| 560 | } | ||||
| 561 | elsif ( $ctl->[CTL_DEST] == CTL_DEST_ARRAY ) { | ||||
| 562 | print STDERR ("=> ref(\$L{$opt}) auto-vivified", | ||||
| 563 | " to ARRAY\n") | ||||
| 564 | if $debug; | ||||
| 565 | my $t = $linkage{$opt}; | ||||
| 566 | $$t = $linkage{$opt} = []; | ||||
| 567 | print STDERR ("=> push(\@{\$L{$opt}, \"$arg\")\n") | ||||
| 568 | if $debug; | ||||
| 569 | push (@{$linkage{$opt}}, $arg); | ||||
| 570 | } | ||||
| 571 | elsif ( $ctl->[CTL_DEST] == CTL_DEST_HASH ) { | ||||
| 572 | print STDERR ("=> ref(\$L{$opt}) auto-vivified", | ||||
| 573 | " to HASH\n") | ||||
| 574 | if $debug; | ||||
| 575 | my $t = $linkage{$opt}; | ||||
| 576 | $$t = $linkage{$opt} = {}; | ||||
| 577 | print STDERR ("=> \$\$L{$opt}->{$key} = \"$arg\"\n") | ||||
| 578 | if $debug; | ||||
| 579 | $linkage{$opt}->{$key} = $arg; | ||||
| 580 | } | ||||
| 581 | else { | ||||
| 582 | print STDERR ("=> \$\$L{$opt} = \"$arg\"\n") | ||||
| 583 | if $debug; | ||||
| 584 | ${$linkage{$opt}} = $arg; | ||||
| 585 | } | ||||
| 586 | } | ||||
| 587 | elsif ( ref($linkage{$opt}) eq 'ARRAY' ) { | ||||
| 588 | print STDERR ("=> push(\@{\$L{$opt}, \"$arg\")\n") | ||||
| 589 | if $debug; | ||||
| 590 | push (@{$linkage{$opt}}, $arg); | ||||
| 591 | } | ||||
| 592 | elsif ( ref($linkage{$opt}) eq 'HASH' ) { | ||||
| 593 | print STDERR ("=> \$\$L{$opt}->{$key} = \"$arg\"\n") | ||||
| 594 | if $debug; | ||||
| 595 | $linkage{$opt}->{$key} = $arg; | ||||
| 596 | } | ||||
| 597 | elsif ( ref($linkage{$opt}) eq 'CODE' ) { | ||||
| 598 | print STDERR ("=> &L{$opt}(\"$opt\"", | ||||
| 599 | $ctl->[CTL_DEST] == CTL_DEST_HASH ? ", \"$key\"" : "", | ||||
| 600 | ", \"$arg\")\n") | ||||
| 601 | if $debug; | ||||
| 602 | my $eval_error = do { | ||||
| 603 | local $@; | ||||
| 604 | local $SIG{__DIE__} = 'DEFAULT'; | ||||
| 605 | eval { | ||||
| 606 | &{$linkage{$opt}} | ||||
| 607 | (Getopt::Long::CallBack->new | ||||
| 608 | (name => $opt, | ||||
| 609 | ctl => $ctl, | ||||
| 610 | opctl => \%opctl, | ||||
| 611 | linkage => \%linkage, | ||||
| 612 | prefix => $prefix, | ||||
| 613 | ), | ||||
| 614 | $ctl->[CTL_DEST] == CTL_DEST_HASH ? ($key) : (), | ||||
| 615 | $arg); | ||||
| 616 | }; | ||||
| 617 | $@; | ||||
| 618 | }; | ||||
| 619 | print STDERR ("=> die($eval_error)\n") | ||||
| 620 | if $debug && $eval_error ne ''; | ||||
| 621 | if ( $eval_error =~ /^!/ ) { | ||||
| 622 | if ( $eval_error =~ /^!FINISH\b/ ) { | ||||
| 623 | $goon = 0; | ||||
| 624 | } | ||||
| 625 | } | ||||
| 626 | elsif ( $eval_error ne '' ) { | ||||
| 627 | warn ($eval_error); | ||||
| 628 | $error++; | ||||
| 629 | } | ||||
| 630 | } | ||||
| 631 | else { | ||||
| 632 | print STDERR ("Invalid REF type \"", ref($linkage{$opt}), | ||||
| 633 | "\" in linkage\n"); | ||||
| 634 | die("Getopt::Long -- internal error!\n"); | ||||
| 635 | } | ||||
| 636 | } | ||||
| 637 | # No entry in linkage means entry in userlinkage. | ||||
| 638 | elsif ( $ctl->[CTL_DEST] == CTL_DEST_ARRAY ) { | ||||
| 639 | 2 | 1µs | if ( defined $userlinkage->{$opt} ) { | ||
| 640 | 1 | 200ns | print STDERR ("=> push(\@{\$L{$opt}}, \"$arg\")\n") | ||
| 641 | if $debug; | ||||
| 642 | 1 | 1µs | push (@{$userlinkage->{$opt}}, $arg); | ||
| 643 | } | ||||
| 644 | else { | ||||
| 645 | 1 | 200ns | print STDERR ("=>\$L{$opt} = [\"$arg\"]\n") | ||
| 646 | if $debug; | ||||
| 647 | 1 | 900ns | $userlinkage->{$opt} = [$arg]; | ||
| 648 | } | ||||
| 649 | } | ||||
| 650 | elsif ( $ctl->[CTL_DEST] == CTL_DEST_HASH ) { | ||||
| 651 | if ( defined $userlinkage->{$opt} ) { | ||||
| 652 | print STDERR ("=> \$L{$opt}->{$key} = \"$arg\"\n") | ||||
| 653 | if $debug; | ||||
| 654 | $userlinkage->{$opt}->{$key} = $arg; | ||||
| 655 | } | ||||
| 656 | else { | ||||
| 657 | print STDERR ("=>\$L{$opt} = {$key => \"$arg\"}\n") | ||||
| 658 | if $debug; | ||||
| 659 | $userlinkage->{$opt} = {$key => $arg}; | ||||
| 660 | } | ||||
| 661 | } | ||||
| 662 | else { | ||||
| 663 | if ( $ctl->[CTL_TYPE] eq '+' ) { | ||||
| 664 | print STDERR ("=> \$L{$opt} += \"$arg\"\n") | ||||
| 665 | if $debug; | ||||
| 666 | if ( defined $userlinkage->{$opt} ) { | ||||
| 667 | $userlinkage->{$opt} += $arg; | ||||
| 668 | } | ||||
| 669 | else { | ||||
| 670 | $userlinkage->{$opt} = $arg; | ||||
| 671 | } | ||||
| 672 | } | ||||
| 673 | else { | ||||
| 674 | print STDERR ("=>\$L{$opt} = \"$arg\"\n") if $debug; | ||||
| 675 | $userlinkage->{$opt} = $arg; | ||||
| 676 | } | ||||
| 677 | } | ||||
| 678 | |||||
| 679 | 2 | 500ns | $argcnt++; | ||
| 680 | 2 | 3µs | last if $argcnt >= $ctl->[CTL_AMAX] && $ctl->[CTL_AMAX] != -1; | ||
| 681 | undef($arg); | ||||
| 682 | |||||
| 683 | # Need more args? | ||||
| 684 | if ( $argcnt < $ctl->[CTL_AMIN] ) { | ||||
| 685 | if ( @$argv ) { | ||||
| 686 | if ( ValidValue($ctl, $argv->[0], 1, $argend, $prefix) ) { | ||||
| 687 | $arg = shift(@$argv); | ||||
| 688 | if ( $ctl->[CTL_TYPE] =~ /^[iIo]$/ ) { | ||||
| 689 | $arg =~ tr/_//d; | ||||
| 690 | $arg = $ctl->[CTL_TYPE] eq 'o' && $arg =~ /^0/ | ||||
| 691 | ? oct($arg) | ||||
| 692 | : 0+$arg | ||||
| 693 | } | ||||
| 694 | ($key,$arg) = $arg =~ /^([^=]+)=(.*)/ | ||||
| 695 | if $ctl->[CTL_DEST] == CTL_DEST_HASH; | ||||
| 696 | next; | ||||
| 697 | } | ||||
| 698 | warn("Value \"$$argv[0]\" invalid for option $opt\n"); | ||||
| 699 | $error++; | ||||
| 700 | } | ||||
| 701 | else { | ||||
| 702 | warn("Insufficient arguments for option $opt\n"); | ||||
| 703 | $error++; | ||||
| 704 | } | ||||
| 705 | } | ||||
| 706 | |||||
| 707 | # Any more args? | ||||
| 708 | if ( @$argv && ValidValue($ctl, $argv->[0], 0, $argend, $prefix) ) { | ||||
| 709 | $arg = shift(@$argv); | ||||
| 710 | if ( $ctl->[CTL_TYPE] =~ /^[iIo]$/ ) { | ||||
| 711 | $arg =~ tr/_//d; | ||||
| 712 | $arg = $ctl->[CTL_TYPE] eq 'o' && $arg =~ /^0/ | ||||
| 713 | ? oct($arg) | ||||
| 714 | : 0+$arg | ||||
| 715 | } | ||||
| 716 | ($key,$arg) = $arg =~ /^([^=]+)=(.*)/ | ||||
| 717 | if $ctl->[CTL_DEST] == CTL_DEST_HASH; | ||||
| 718 | next; | ||||
| 719 | } | ||||
| 720 | } | ||||
| 721 | } | ||||
| 722 | |||||
| 723 | # Not an option. Save it if we $PERMUTE and don't have a <>. | ||||
| 724 | elsif ( $order == $PERMUTE ) { | ||||
| 725 | # Try non-options call-back. | ||||
| 726 | 1 | 200ns | my $cb; | ||
| 727 | 1 | 700ns | if ( defined ($cb = $linkage{'<>'}) ) { | ||
| 728 | print STDERR ("=> &L{$tryopt}(\"$tryopt\")\n") | ||||
| 729 | if $debug; | ||||
| 730 | my $eval_error = do { | ||||
| 731 | local $@; | ||||
| 732 | local $SIG{__DIE__} = 'DEFAULT'; | ||||
| 733 | eval { | ||||
| 734 | # The arg to <> cannot be the CallBack object | ||||
| 735 | # since it may be passed to other modules that | ||||
| 736 | # get confused (e.g., Archive::Tar). Well, | ||||
| 737 | # it's not relevant for this callback anyway. | ||||
| 738 | &$cb($tryopt); | ||||
| 739 | }; | ||||
| 740 | $@; | ||||
| 741 | }; | ||||
| 742 | print STDERR ("=> die($eval_error)\n") | ||||
| 743 | if $debug && $eval_error ne ''; | ||||
| 744 | if ( $eval_error =~ /^!/ ) { | ||||
| 745 | if ( $eval_error =~ /^!FINISH\b/ ) { | ||||
| 746 | $goon = 0; | ||||
| 747 | } | ||||
| 748 | } | ||||
| 749 | elsif ( $eval_error ne '' ) { | ||||
| 750 | warn ($eval_error); | ||||
| 751 | $error++; | ||||
| 752 | } | ||||
| 753 | } | ||||
| 754 | else { | ||||
| 755 | 1 | 200ns | print STDERR ("=> saving \"$tryopt\" ", | ||
| 756 | "(not an option, may permute)\n") if $debug; | ||||
| 757 | 1 | 500ns | push (@ret, $tryopt); | ||
| 758 | } | ||||
| 759 | 1 | 600ns | next; | ||
| 760 | } | ||||
| 761 | |||||
| 762 | # ...otherwise, terminate. | ||||
| 763 | else { | ||||
| 764 | # Push this one back and exit. | ||||
| 765 | unshift (@$argv, $tryopt); | ||||
| 766 | return ($error == 0); | ||||
| 767 | } | ||||
| 768 | |||||
| 769 | } | ||||
| 770 | |||||
| 771 | # Finish. | ||||
| 772 | 1 | 1µs | if ( @ret && $order == $PERMUTE ) { | ||
| 773 | # Push back accumulated arguments | ||||
| 774 | 1 | 0s | print STDERR ("=> restoring \"", join('" "', @ret), "\"\n") | ||
| 775 | if $debug; | ||||
| 776 | 1 | 500ns | unshift (@$argv, @ret); | ||
| 777 | } | ||||
| 778 | |||||
| 779 | 1 | 13µs | return ($error == 0); | ||
| 780 | } | ||||
| 781 | |||||
| 782 | # A readable representation of what's in an optbl. | ||||
| 783 | sub OptCtl ($) { | ||||
| 784 | my ($v) = @_; | ||||
| 785 | my @v = map { defined($_) ? ($_) : ("<undef>") } @$v; | ||||
| 786 | "[". | ||||
| 787 | join(",", | ||||
| 788 | "\"$v[CTL_TYPE]\"", | ||||
| 789 | "\"$v[CTL_CNAME]\"", | ||||
| 790 | "\"$v[CTL_DEFAULT]\"", | ||||
| 791 | ("\$","\@","\%","\&")[$v[CTL_DEST] || 0], | ||||
| 792 | $v[CTL_AMIN] || '', | ||||
| 793 | $v[CTL_AMAX] || '', | ||||
| 794 | # $v[CTL_RANGE] || '', | ||||
| 795 | # $v[CTL_REPEAT] || '', | ||||
| 796 | ). "]"; | ||||
| 797 | } | ||||
| 798 | |||||
| 799 | # Parse an option specification and fill the tables. | ||||
| 800 | # spent 436µs (358+78) within Getopt::Long::ParseOptionSpec which was called 27 times, avg 16µs/call:
# 27 times (358µs+78µs) by Getopt::Long::GetOptionsFromArray at line 386, avg 16µs/call | ||||
| 801 | 27 | 6µs | my ($opt, $opctl) = @_; | ||
| 802 | |||||
| 803 | # Match option spec. | ||||
| 804 | 27 | 69µs | 27 | 43µs | if ( $opt !~ m;^ # spent 43µs making 27 calls to Getopt::Long::CORE:match, avg 2µs/call |
| 805 | ( | ||||
| 806 | # Option name | ||||
| 807 | (?: \w+[-\w]* ) | ||||
| 808 | # Alias names, or "?" | ||||
| 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 | 27 | 20µs | my ($names, $spec) = ($1, $2); | ||
| 828 | 27 | 3µs | $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 | 27 | 3µs | my $orig; | ||
| 837 | |||||
| 838 | my @names; | ||||
| 839 | 27 | 7µs | if ( defined $names ) { | ||
| 840 | 27 | 16µs | @names = split (/\|/, $names); | ||
| 841 | 27 | 6µs | $orig = $names[0]; | ||
| 842 | } | ||||
| 843 | else { | ||||
| 844 | @names = (''); | ||||
| 845 | $orig = ''; | ||||
| 846 | } | ||||
| 847 | |||||
| 848 | # Construct the opctl entries. | ||||
| 849 | 27 | 2µs | my $entry; | ||
| 850 | 27 | 43µs | 24 | 5µs | if ( $spec eq '' || $spec eq '+' || $spec eq '!' ) { # spent 5µs making 24 calls to Getopt::Long::CORE:match, avg 192ns/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 | 24 | 66µs | 24 | 30µs | my ($mand, $type, $dest) = # spent 30µs making 24 calls to Getopt::Long::CORE:match, avg 1µs/call |
| 867 | $spec =~ /^([=:])([ionfs])([@%])?(\{(\d+)?(,)?(\d+)?\})?$/; | ||||
| 868 | 24 | 3µs | return (undef, "Cannot repeat while bundling: \"$opt\"\n") | ||
| 869 | if $bundling && defined($4); | ||||
| 870 | 24 | 14µs | my ($mi, $cm, $ma) = ($5, $6, $7); | ||
| 871 | 24 | 4µs | return (undef, "{0} is useless in option spec: \"$opt\"\n") | ||
| 872 | if defined($mi) && !$mi && !defined($ma) && !defined($cm); | ||||
| 873 | |||||
| 874 | 24 | 4µs | $type = 'i' if $type eq 'n'; | ||
| 875 | 24 | 5µs | $dest ||= '$'; | ||
| 876 | 24 | 8µ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 | 24 | 6µs | $mi = $mand eq '=' ? 1 : 0 unless defined $mi; | ||
| 880 | # Adjust mand status according to minargs. | ||||
| 881 | 24 | 5µs | $mand = $mi ? '=' : ':'; | ||
| 882 | # Adjust maxargs. | ||||
| 883 | 24 | 6µs | $ma = $mi ? $mi : 1 unless defined $ma || defined $cm; | ||
| 884 | 24 | 4µs | return (undef, "Max must be greater than zero in option spec: \"$opt\"\n") | ||
| 885 | if defined($ma) && !$ma; | ||||
| 886 | 24 | 4µs | 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 | 24 | 23µs | $entry = [$type,$orig,undef,$dest,$mi,$ma||-1]; | ||
| 891 | } | ||||
| 892 | |||||
| 893 | # Process all names. First is canonical, the rest are aliases. | ||||
| 894 | 27 | 5µs | my $dups = ''; | ||
| 895 | 27 | 9µs | foreach ( @names ) { | ||
| 896 | |||||
| 897 | 27 | 13µs | $_ = lc ($_) | ||
| 898 | if $ignorecase > (($bundling && length($_) == 1) ? 1 : 0); | ||||
| 899 | |||||
| 900 | 27 | 6µs | if ( exists $opctl->{$_} ) { | ||
| 901 | $dups .= "Duplicate specification \"$opt\" for option \"$_\"\n"; | ||||
| 902 | } | ||||
| 903 | |||||
| 904 | 27 | 13µs | if ( $spec eq '!' ) { | ||
| 905 | 3 | 3µs | $opctl->{"no$_"} = $entry; | ||
| 906 | 3 | 4µs | $opctl->{"no-$_"} = $entry; | ||
| 907 | 3 | 3µs | $opctl->{$_} = [@$entry]; | ||
| 908 | 3 | 1µs | $opctl->{$_}->[CTL_TYPE] = ''; | ||
| 909 | } | ||||
| 910 | else { | ||||
| 911 | 24 | 14µs | $opctl->{$_} = $entry; | ||
| 912 | } | ||||
| 913 | } | ||||
| 914 | |||||
| 915 | 27 | 3µs | if ( $dups && $^W ) { | ||
| 916 | foreach ( split(/\n+/, $dups) ) { | ||||
| 917 | warn($_."\n"); | ||||
| 918 | } | ||||
| 919 | } | ||||
| 920 | 27 | 51µs | ($names[0], $orig); | ||
| 921 | } | ||||
| 922 | |||||
| 923 | # Option lookup. | ||||
| 924 | # spent 266µs (194+73) within Getopt::Long::FindOption which was called 3 times, avg 89µs/call:
# 3 times (194µs+73µs) by Getopt::Long::GetOptionsFromArray at line 529, avg 89µ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 | 3 | 2µs | my ($argv, $prefix, $argend, $opt, $opctl) = @_; | ||
| 931 | |||||
| 932 | 3 | 900ns | print STDERR ("=> find \"$opt\"\n") if $debug; | ||
| 933 | |||||
| 934 | 3 | 1µs | return (0) unless defined($opt); | ||
| 935 | 3 | 32µs | 6 | 20µs | return (0) unless $opt =~ /^($prefix)(.*)$/s; # spent 16µs making 3 calls to Getopt::Long::CORE:regcomp, avg 5µs/call
# spent 4µs making 3 calls to Getopt::Long::CORE:match, avg 1µs/call |
| 936 | 2 | 1µs | return (0) if $opt eq "-" && !defined $opctl->{''}; | ||
| 937 | |||||
| 938 | 2 | 2µs | $opt = substr( $opt, length($1) ); # retain taintedness | ||
| 939 | 2 | 1µs | my $starter = $1; | ||
| 940 | |||||
| 941 | 2 | 300ns | print STDERR ("=> split \"$starter\"+\"$opt\"\n") if $debug; | ||
| 942 | |||||
| 943 | 2 | 800ns | 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 | 2 | 17µs | 4 | 7µs | if ( ($starter=~/^$longprefix$/ # spent 6µs making 2 calls to Getopt::Long::CORE:regcomp, avg 3µs/call
# spent 2µs making 2 calls to Getopt::Long::CORE:match, avg 750ns/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 | 2 | 900ns | my $tryopt = $opt; # option to try | ||
| 961 | |||||
| 962 | 2 | 3µs | if ( ( $bundling || $bundling_values ) && $starter eq '-' ) { | ||
| 963 | |||||
| 964 | # To try overrides, obey case ignore. | ||||
| 965 | $tryopt = $ignorecase ? lc($opt) : $opt; | ||||
| 966 | |||||
| 967 | # If bundling == 2, long options can override bundles. | ||||
| 968 | 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 | $tryopt = $opt; | ||||
| 992 | # Unbundle single letter option. | ||||
| 993 | $rest = length ($tryopt) > 0 ? substr ($tryopt, 1) : ''; | ||||
| 994 | $tryopt = substr ($tryopt, 0, 1); | ||||
| 995 | $tryopt = lc ($tryopt) if $ignorecase > 1; | ||||
| 996 | print STDERR ("=> $starter$tryopt unbundled from ", | ||||
| 997 | "$starter$tryopt$rest\n") if $debug; | ||||
| 998 | $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 | 2 | 28µs | 2 | 13µs | my @names = sort(keys (%$opctl)); # spent 13µs making 2 calls to Getopt::Long::CORE:sort, avg 6µs/call |
| 1006 | # Downcase if allowed. | ||||
| 1007 | 2 | 1µs | $opt = lc ($opt) if $ignorecase; | ||
| 1008 | 2 | 700ns | $tryopt = $opt; | ||
| 1009 | # Turn option name into pattern. | ||||
| 1010 | 2 | 1µs | my $pat = quotemeta ($opt); | ||
| 1011 | # Look up in option names. | ||||
| 1012 | 2 | 148µs | 132 | 32µs | my @hits = grep (/^$pat/, @names); # spent 24µs making 66 calls to Getopt::Long::CORE:regcomp, avg 362ns/call
# spent 8µs making 66 calls to Getopt::Long::CORE:match, avg 121ns/call |
| 1013 | 2 | 700ns | print STDERR ("=> ", scalar(@hits), " hits (@hits) with \"$pat\" ", | ||
| 1014 | "out of ", scalar(@names), "\n") if $debug; | ||||
| 1015 | |||||
| 1016 | # Check for ambiguous results. | ||||
| 1017 | 2 | 1µs | 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 | 2 | 3µs | 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 | 2 | 2µs | my $ctl = $opctl->{$tryopt}; | ||
| 1063 | 2 | 300ns | 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 | 2 | 800ns | $opt = $tryopt; | ||
| 1081 | 2 | 700ns | 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 | 2 | 1µs | my $type = $ctl->[CTL_TYPE]; | ||
| 1088 | 2 | 300ns | my $arg; | ||
| 1089 | |||||
| 1090 | 2 | 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 | 2 | 800ns | my $mand = $ctl->[CTL_AMIN]; | ||
| 1112 | |||||
| 1113 | # Check if there is an option argument available. | ||||
| 1114 | 2 | 600ns | if ( $gnu_compat ) { | ||
| 1115 | my $optargtype = 0; # none, 1 = empty, 2 = nonempty, 3 = aux | ||||
| 1116 | 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 | 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 | 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 | 2 | 2µ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 ) { | ||||
| 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 | 2 | 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 | 2 | 500ns | my $key; | ||
| 1171 | 2 | 800ns | 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 | 2 | 2µs | my $key_valid = $ctl->[CTL_DEST] == CTL_DEST_HASH ? "[^=]+=" : ""; | ||
| 1187 | |||||
| 1188 | 2 | 2µs | if ( $type eq 's' ) { # string | ||
| 1189 | # A mandatory string takes anything. | ||||
| 1190 | 2 | 6µ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 | # spent 4µs within Getopt::Long::Configure which was called:
# once (4µs+0s) by main::BEGIN@8 at line 139 | ||||
| 1337 | 1 | 300ns | my (@options) = @_; | ||
| 1338 | |||||
| 1339 | 1 | 2µ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 | 1 | 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 | 1 | 0s | my $opt; | ||
| 1353 | 1 | 600ns | foreach $opt ( @options ) { | ||
| 1354 | my $try = lc ($opt); | ||||
| 1355 | my $action = 1; | ||||
| 1356 | if ( $try =~ /^no_?(.*)$/s ) { | ||||
| 1357 | $action = 0; | ||||
| 1358 | $try = $+; | ||||
| 1359 | } | ||||
| 1360 | if ( ($try eq 'default' or $try eq 'defaults') && $action ) { | ||||
| 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 | if ( $action ) { | ||||
| 1377 | $gnu_compat = 1; | ||||
| 1378 | $bundling = 1; | ||||
| 1379 | $getopt_compat = 0; | ||||
| 1380 | $genprefix = "(--|-)"; | ||||
| 1381 | $order = $PERMUTE; | ||||
| 1382 | $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 | $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 | 1 | 3µ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]; | ||||
| 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 | use overload | ||||
| 1567 | # Treat this object as an ordinary string for legacy API. | ||||
| 1568 | 1 | 10µs | 1 | 44µs | # spent 60µs (16+44) within Getopt::Long::CallBack::BEGIN@1568 which was called:
# once (16µs+44µs) by main::BEGIN@8 at line 1569 # spent 44µs making 1 call to overload::import |
| 1569 | 1 | 90µs | 1 | 60µs | fallback => 1; # spent 60µs making 1 call to Getopt::Long::CallBack::BEGIN@1568 |
| 1570 | |||||
| 1571 | 1 | 12µs | 1; | ||
| 1572 | |||||
| 1573 | ################ Documentation ################ | ||||
| 1574 | |||||
# spent 135µs within Getopt::Long::CORE:match which was called 175 times, avg 769ns/call:
# 66 times (8µs+0s) by Getopt::Long::FindOption at line 1012, avg 121ns/call
# 27 times (43µs+0s) by Getopt::Long::ParseOptionSpec at line 804, avg 2µs/call
# 27 times (17µs+0s) by Getopt::Long::GetOptionsFromArray at line 364, avg 615ns/call
# 24 times (30µs+0s) by Getopt::Long::ParseOptionSpec at line 866, avg 1µs/call
# 24 times (5µs+0s) by Getopt::Long::ParseOptionSpec at line 850, avg 192ns/call
# 3 times (4µs+0s) by Getopt::Long::FindOption at line 935, avg 1µs/call
# 2 times (2µs+0s) by Getopt::Long::FindOption at line 948, avg 750ns/call
# once (24µs+0s) by main::BEGIN@8 at line 129
# once (2µs+0s) by Getopt::Long::GetOptionsFromArray at line 342 | |||||
# spent 91µs within Getopt::Long::CORE:regcomp which was called 98 times, avg 929ns/call:
# 66 times (24µs+0s) by Getopt::Long::FindOption at line 1012, avg 362ns/call
# 27 times (45µs+0s) by Getopt::Long::GetOptionsFromArray at line 364, avg 2µs/call
# 3 times (16µs+0s) by Getopt::Long::FindOption at line 935, avg 5µs/call
# 2 times (6µs+0s) by Getopt::Long::FindOption at line 948, avg 3µs/call | |||||
# spent 13µs within Getopt::Long::CORE:sort which was called 2 times, avg 6µs/call:
# 2 times (13µs+0s) by Getopt::Long::FindOption at line 1005, avg 6µs/call | |||||
# spent 700ns within main::CORE:subst which was called:
# once (700ns+0s) by main::set_options at line 107 of /root/tor-browser-build/rbm/rbm | |||||
# spent 2µs within main::__ANON__ which was called:
# once (2µs+0s) by main::BEGIN@6 at line 6 of /root/tor-browser-build/rbm/rbm |