| 1 | package Getopt::Tabular; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Getopt/Tabular.pm | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # Perl module for table-driven argument parsing, somewhat like Tk's | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # ParseArgv. To use the package, you just have to set up an argument table | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # (a list of array references), and call &GetOptions (the name is exported | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # from the module). &GetOptions takes two or three arguments; a reference | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # to your argument table (which is not modified), a reference to the list | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # of command line arguments, e.g. @ARGV (or a copy of it), and (optionally) | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # a reference to a new empty array. In the two argument form, the second | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # argument is modified in place to remove all options and their arguments. | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # In the three argument form, the second argument is unmodified, and the | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # third argument is set to a copy of it with options removed. | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # The argument table consists of one element per valid command-line option; | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # each element should be a reference to a list of the form: | ||||||||||||||||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||||||||||||||||
| 20 | # ( option_name, type, num_values, option_data, help_string, arg_desc ) | ||||||||||||||||||||||||||||||||||||||||||
| 21 | # | ||||||||||||||||||||||||||||||||||||||||||
| 22 | # See Getopt/Tabular.pod for complete information. | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # | ||||||||||||||||||||||||||||||||||||||||||
| 24 | # originally by Greg Ward 1995/07/06-07/09 as ParseArgs.pm | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # renamed to Getopt::Tabular and somewhat reorganized/reworked, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # 1996/11/08-11/10 | ||||||||||||||||||||||||||||||||||||||||||
| 27 | # | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # $Id: Tabular.pm,v 1.8 1999/04/08 01:11:24 greg Exp $ | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | # Copyright (c) 1995-98 Greg Ward. All rights reserved. This package is | ||||||||||||||||||||||||||||||||||||||||||
| 31 | # free software; you can redistribute it and/or modify it under the same | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | use vars qw/%Patterns %OptionHandlers %TypeDescriptions @OptionPatterns | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | %SpoofCode $OptionTerminator $HelpOption | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | $LongHelp $Usage $ErrorClass $ErrorMessage/; | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | $VERSION = 0.3; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | @ISA = qw/Exporter/; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | @EXPORT = qw/GetOptions/; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | @EXPORT_OK = qw/SetHelp SetHelpOption SetError GetError SpoofGetOptions/; | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | # -------------------------------------------------------------------- # | ||||||||||||||||||||||||||||||||||||||||||
| 49 | # Private global variables # | ||||||||||||||||||||||||||||||||||||||||||
| 50 | # -------------------------------------------------------------------- # | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | # The regexp for floating point numbers here is a little more permissive | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # than the C standard -- it recognizes "0", "0.", ".0", and "0.0" (where 0 | ||||||||||||||||||||||||||||||||||||||||||
| 55 | # can be substituted by any string of one or more digits), preceded by an | ||||||||||||||||||||||||||||||||||||||||||
| 56 | # optional sign, and followed by an optional exponent. | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | %Patterns = ('integer' => '[+-]?\d+', | |||||||||||||||||||||||||||||||||||||||||
| 59 | 'float' => '[+-]? ( \d+(\.\d*)? | \.\d+ ) ([Ee][+-]?\d+)?', | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 'string' => '.*'); | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # This hash defines the allowable option types, and what to do when we | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # see an argument of a given type in the argument list. New types | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # can be added by calling AddType, as long as you supply an option | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # handler that acts like one of the existing handlers. (Ie. takes | ||||||||||||||||||||||||||||||||||||||||||
| 67 | # the same three arguments, returns 1 for success and 0 for failure, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | # and calls SetError appropriately.) | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | %OptionHandlers = ("string", \&process_pattern_option, | |||||||||||||||||||||||||||||||||||||||||
| 71 | "integer", \&process_pattern_option, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | "float", \&process_pattern_option, | ||||||||||||||||||||||||||||||||||||||||||
| 73 | "boolean", \&process_boolean_option, | ||||||||||||||||||||||||||||||||||||||||||
| 74 | "const", \&process_constant_option, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | "copy", \&process_constant_option, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | "arrayconst",\&process_constant_option, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | "hashconst", \&process_constant_option, | ||||||||||||||||||||||||||||||||||||||||||
| 78 | "call", \&process_call_option, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | "eval", \&process_eval_option, | ||||||||||||||||||||||||||||||||||||||||||
| 80 | "section", undef); | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | # This hash is used for building error messages for pattern types. A | ||||||||||||||||||||||||||||||||||||||||||
| 83 | # subtle point is that the description should be such that it can be | ||||||||||||||||||||||||||||||||||||||||||
| 84 | # pluralized by adding an "s". OK, OK, you can supply an alternate | ||||||||||||||||||||||||||||||||||||||||||
| 85 | # plural form by making the description a reference to a two-element list, | ||||||||||||||||||||||||||||||||||||||||||
| 86 | # singular and plural forms. I18N fanatics should be happy. | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | %TypeDescriptions = ("integer" => "integer", | |||||||||||||||||||||||||||||||||||||||||
| 89 | "float" => "floating-point number", | ||||||||||||||||||||||||||||||||||||||||||
| 90 | "string" => "string"); | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | @OptionPatterns = ('(-)(\w+)'); # two parts: "prefix" and "body" | |||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | $OptionTerminator = "--"; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | $HelpOption = "-help"; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | # The %SpoofCode hash is for storing alternate versions of callbacks | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # for call or eval options. The alternate versions should have no side | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # effects apart from changing the argument list identically to their | ||||||||||||||||||||||||||||||||||||||||||
| 99 | # "real" alternatives. | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | %SpoofCode = (); | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | $ErrorClass = ""; # can be "bad_option", "bad_value", | |||||||||||||||||||||||||||||||||||||||||
| 104 | # "bad_eval", or "help" | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | $ErrorMessage = ""; # can be anything | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | # -------------------------------------------------------------------- # | ||||||||||||||||||||||||||||||||||||||||||
| 108 | # Public (but not exported) subroutines used to set options before # | ||||||||||||||||||||||||||||||||||||||||||
| 109 | # calling GetOptions. # | ||||||||||||||||||||||||||||||||||||||||||
| 110 | # -------------------------------------------------------------------- # | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | sub SetHelp | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SetHelp: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $LongHelp = shift; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | $Usage = shift; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | sub SetOptionPatterns | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SetOptionPatterns: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | @OptionPatterns = @_; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | sub SetHelpOption | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SetHelpOption: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $HelpOption = shift; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | sub SetTerminator | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SetTerminator: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | $OptionTerminator = shift; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | sub UnsetTerminator | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
UnsetTerminator: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | undef $OptionTerminator; | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | sub AddType | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AddType: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my ($type, $handler) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | croak "AddType: \$handler must be a code ref" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | unless ref $handler eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $OptionHandlers{$type} = $handler; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | sub AddPatternType | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AddPatternType: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my ($type, $pattern, $description) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $OptionHandlers{$type} = \&process_pattern_option; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $Patterns{$type} = $pattern; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | $TypeDescriptions{$type} = ($description || $type); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$description || $type
MC/DC0%0/2
$description || $type
$description
$type
Truth table0%0/3
A || B
A= $descriptionB= $type
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | sub GetPattern | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
GetPattern: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my ($type) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $Patterns{$type}; | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | sub SetSpoofCodes | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SetSpoofCodes: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | my ($option, $code); | |||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | croak "Even number of arguments required" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ > 0 and @_ % 2 == 0
MC/DC0%0/2
@_ > 0 and @_ % 2 == 0
@_ > 0
@_ % 2 == 0
Truth table0%0/3
A and B
A= @_ > 0B= @_ % 2 == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | unless (@_ > 0 && @_ % 2 == 0); | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | while (@_) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | { | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ($option, $code) = (shift, shift); | |||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | $SpoofCode{$option} = $code; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | sub SetError | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SetError: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 6 | $ErrorClass = shift; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 6 | $ErrorMessage = shift; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | sub GetError | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
GetError: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ($ErrorClass, $ErrorMessage); | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | # -------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 185 | # Private utility subroutines: | ||||||||||||||||||||||||||||||||||||||||||
| 186 | # quote_strings | ||||||||||||||||||||||||||||||||||||||||||
| 187 | # print_help | ||||||||||||||||||||||||||||||||||||||||||
| 188 | # scan_table | ||||||||||||||||||||||||||||||||||||||||||
| 189 | # match_abbreviation | ||||||||||||||||||||||||||||||||||||||||||
| 190 | # option_error | ||||||||||||||||||||||||||||||||||||||||||
| 191 | # check_value | ||||||||||||||||||||||||||||||||||||||||||
| 192 | # split_option | ||||||||||||||||||||||||||||||||||||||||||
| 193 | # find_calling_package | ||||||||||||||||||||||||||||||||||||||||||
| 194 | # -------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | # | ||||||||||||||||||||||||||||||||||||||||||
| 198 | # "e_strings | ||||||||||||||||||||||||||||||||||||||||||
| 199 | # | ||||||||||||||||||||||||||||||||||||||||||
| 200 | # prepares strings for printing in a list of default values (for the | ||||||||||||||||||||||||||||||||||||||||||
| 201 | # help text). If a string is empty or contains whitespace, it is quoted; | ||||||||||||||||||||||||||||||||||||||||||
| 202 | # otherwise, it is left alone. The input list of strings is returned | ||||||||||||||||||||||||||||||||||||||||||
| 203 | # concatenated into a single space-separated string. This is *not* | ||||||||||||||||||||||||||||||||||||||||||
| 204 | # rigorous by any stretch; it's just to make the help text look nice. | ||||||||||||||||||||||||||||||||||||||||||
| 205 | # | ||||||||||||||||||||||||||||||||||||||||||
| 206 | sub quote_strings | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quote_strings: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my @strings = @_; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | my $string; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | foreach $string (@strings) | |||||||||||||||||||||||||||||||||||||||||
| 211 | { | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | $string = qq["$string"] if ($string eq '' || $string =~ /\s/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$string eq "" or $string =~ /\s/
MC/DC0%0/2
$string eq "" or $string =~ /\s/
$string eq ""
$string =~ /\s/
Truth table0%0/3
A or B
A= $string eq ""B= $string =~ /\s/
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | return join (' ', @strings); | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | # | ||||||||||||||||||||||||||||||||||||||||||
| 219 | # &print_help | ||||||||||||||||||||||||||||||||||||||||||
| 220 | # | ||||||||||||||||||||||||||||||||||||||||||
| 221 | # walks through an argument table and prints out nicely-formatted | ||||||||||||||||||||||||||||||||||||||||||
| 222 | # option help for all entries that provide it. Also does the Right Thing | ||||||||||||||||||||||||||||||||||||||||||
| 223 | # (trust me) if you supply "argument description" text after the help. | ||||||||||||||||||||||||||||||||||||||||||
| 224 | # | ||||||||||||||||||||||||||||||||||||||||||
| 225 | # Don't read this code if you can possibly avoid it. It's pretty gross. | ||||||||||||||||||||||||||||||||||||||||||
| 226 | # | ||||||||||||||||||||||||||||||||||||||||||
| 227 | sub print_help | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_help: not called CC=38 SCAR=73.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | confess ("internal error, wrong number of input args to &print_help") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | if (scalar (@_) != 1); | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my ($argtable) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my ($maxoption, $maxargdesc, $numcols, $opt, $breakers); | |||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | my ($textlength, $std_format, $alt_format); | |||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | my ($option, $type, $num, $value, $help, $argdesc); | |||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | $maxoption = 0; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | $maxargdesc = 0; | |||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | # Loop over all options to determine the length of the longest option name | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | foreach $opt (@$argtable) | |||||||||||||||||||||||||||||||||||||||||
| 241 | { | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my ($argdesclen, $neg_option); | |||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | my ($option, $type, $help, $argdesc) = @{$opt} [0,1,4,5]; | |||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | next if $type eq "section" or ! defined $help; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type eq "section" or not defined $help
MC/DC0%0/2
$type eq "section" or not defined $help
$type eq "section"
not defined $help
Truth table0%0/3
A or not(B)
A= $type eq "section"B= not defined $help
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | # Boolean options contribute *two* lines to the help: one for the | ||||||||||||||||||||||||||||||||||||||||||
| 247 | # option, and one for its negative. Other options just contribute | ||||||||||||||||||||||||||||||||||||||||||
| 248 | # one line, so they're a bit simpler. | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if ($type eq 'boolean') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | { | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my ($pos, $neg) = &split_option ($opt); | |||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | my $pos_len = length ($pos); | |||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | my $neg_len = length ($neg); | |||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | $maxoption = $pos_len if ($pos_len > $maxoption); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | $maxoption = $neg_len if ($pos_len > $maxoption); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | carp "Getopt::Tabular: argument descriptions ignored " . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | "for boolean option \"$option\"" | ||||||||||||||||||||||||||||||||||||||||||
| 258 | if defined $argdesc; | ||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | else | ||||||||||||||||||||||||||||||||||||||||||
| 261 | { | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | my $optlen = length ($option); | |||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | $maxoption = $optlen if ($optlen > $maxoption); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | if (defined $argdesc) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | { | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | $argdesclen = length ($argdesc); | |||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | $maxargdesc = $argdesclen if ($argdesclen > $maxargdesc); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | # We need to construct and eval code that looks something like this: | ||||||||||||||||||||||||||||||||||||||||||
| 274 | # format STANDARD = | ||||||||||||||||||||||||||||||||||||||||||
| 275 | # @<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||||||||||||||||||||||||||||||||||||||||||
| 276 | # $option, $help | ||||||||||||||||||||||||||||||||||||||||||
| 277 | # ~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||||||||||||||||||||||||||||||||||||||||||
| 278 | # $help | ||||||||||||||||||||||||||||||||||||||||||
| 279 | # . | ||||||||||||||||||||||||||||||||||||||||||
| 280 | # | ||||||||||||||||||||||||||||||||||||||||||
| 281 | # with an alternative format like this: | ||||||||||||||||||||||||||||||||||||||||||
| 282 | # format ALTERNATIVE = | ||||||||||||||||||||||||||||||||||||||||||
| 283 | # @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||||||||||||||||||||||||||||||||||||||||||
| 284 | # $option, $argdesc | ||||||||||||||||||||||||||||||||||||||||||
| 285 | # ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||||||||||||||||||||||||||||||||||||||||||
| 286 | # $help | ||||||||||||||||||||||||||||||||||||||||||
| 287 | # ~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||||||||||||||||||||||||||||||||||||||||||
| 288 | # $help | ||||||||||||||||||||||||||||||||||||||||||
| 289 | # . | ||||||||||||||||||||||||||||||||||||||||||
| 290 | # in order to nicely print out the help. Can't hardcode a format, | ||||||||||||||||||||||||||||||||||||||||||
| 291 | # though, because we don't know until now how much space to allocate | ||||||||||||||||||||||||||||||||||||||||||
| 292 | # for the option (ie. $maxoption). | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | local $: = " \n"; | |||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | local $~; | |||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $numcols = 80; # not always accurate, but faster! | |||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | # width of text = width of terminal, with columns removed as follows: | ||||||||||||||||||||||||||||||||||||||||||
| 300 | # 3 (for left margin), $maxoption (option names), 2 (gutter between | ||||||||||||||||||||||||||||||||||||||||||
| 301 | # option names and help text), and 2 (right margin) | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $textlength = $numcols - 3 - $maxoption - 2 - 2; | |||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | $std_format = "format STANDARD =\n" . | |||||||||||||||||||||||||||||||||||||||||
| 304 | " @" . ("<" x $maxoption) . " ^" . ("<" x ($textlength-1)) . "\n". | ||||||||||||||||||||||||||||||||||||||||||
| 305 | "\$option, \$help\n" . | ||||||||||||||||||||||||||||||||||||||||||
| 306 | "~~ " . (" " x $maxoption) . " ^" . ("<" x ($textlength-1)) . "\n" . | ||||||||||||||||||||||||||||||||||||||||||
| 307 | "\$help\n."; | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $alt_format = "format ALTERNATIVE =\n" . | |||||||||||||||||||||||||||||||||||||||||
| 309 | " @" . ("<" x ($maxoption + $maxargdesc)) . "\n" . | ||||||||||||||||||||||||||||||||||||||||||
| 310 | "\$option\n" . | ||||||||||||||||||||||||||||||||||||||||||
| 311 | " " . (" " x $maxoption) . " ^" . ("<" x ($textlength-1)) . "\n" . | ||||||||||||||||||||||||||||||||||||||||||
| 312 | "\$help\n" . | ||||||||||||||||||||||||||||||||||||||||||
| 313 | "~~ " . (" " x $maxoption) . " ^" . ("<" x ($textlength-1)) . "\n" . | ||||||||||||||||||||||||||||||||||||||||||
| 314 | "\$help\n."; | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | eval $std_format; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | confess ("internal error with format \"$std_format\": $@") if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | eval $alt_format; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | confess ("internal error with format \"$alt_format\": $@") if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | my $show_defaults = 1; | |||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | print $LongHelp . "\n" if defined $LongHelp; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | print "Summary of options:\n"; | |||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | foreach $opt (@$argtable) | |||||||||||||||||||||||||||||||||||||||||
| 326 | { | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ($option, $type, $num, $value, $help, $argdesc) = @$opt; | |||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | if ($type eq "section") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | { | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | printf "\n-- %s %s\n", $option, "-" x ($numcols-4-length($option)); | |||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | next unless defined $help; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | $argdesc = "" unless defined $argdesc; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | my $show_default = $show_defaults && $help !~ /\[default/; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$show_defaults && !($help =~ /\[default/)
MC/DC0%0/2
$show_defaults && !($help =~ /\[default/)
$show_defaults
!($help =~ /\[default/)
Truth table0%0/3
A && not(B)
A= $show_defaultsB= !($help =~ /\[default/)
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | $~ = 'STANDARD'; | |||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | if ($type eq 'boolean') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | { | ||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | undef $option; # arg! why is this necessary? | |||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | my ($pos, $neg) = &split_option ($opt); | |||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | $option = $pos; | |||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | $help .= ' [default]' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$show_default and defined $$value and $$value
$show_default and defined $$value
MC/DC0%0/3
$show_default and defined $$value and $$value
$show_default
defined $$value
$$value
Truth table0%0/4
A and B and C
A= $show_defaultB= defined $$valueC= $$value
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | if $show_default && defined $$value && $$value; | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | write; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | $help = "opposite of $pos"; | |||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | $help .= ' [default]' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$show_default and defined $$value and not $$value
$show_default and defined $$value
MC/DC0%0/3
$show_default and defined $$value and not $$value
$show_default
defined $$value
not $$value
Truth table0%0/4
A and B and not(C)
A= $show_defaultB= defined $$valueC= not $$value
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | if $show_default && defined $$value && ! $$value; | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | $option = $neg; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | write; | |||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | else | ||||||||||||||||||||||||||||||||||||||||||
| 356 | { | ||||||||||||||||||||||||||||||||||||||||||
| 357 | # If the option type is of the argument-taking variety, then | ||||||||||||||||||||||||||||||||||||||||||
| 358 | # we'll try to help out by saying what the default value(s) | ||||||||||||||||||||||||||||||||||||||||||
| 359 | # is/are | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | if ($OptionHandlers{$type} == \&process_pattern_option) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | { | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | if ($num == 1) # expectes a scalar value | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | { | ||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | $help .= ' [default: ' . quote_strings ($$value) . ']' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$show_default and defined $$value
MC/DC0%0/2
$show_default and defined $$value
$show_default
defined $$value
Truth table0%0/3
A and B
A= $show_defaultB= defined $$value
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | if ($show_default && defined $$value); | ||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||
| 367 | else # expects a vector value | ||||||||||||||||||||||||||||||||||||||||||
| 368 | { | ||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | $help .= ' [default: ' . quote_strings (@$value) . ']' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$show_default and @$value and not grep((!defined($_)), @$value)
$show_default and @$value
MC/DC0%0/3
$show_default and @$value and not grep((!defined($_)), @$value)
$show_default
@$value
not grep((!defined($_)), @$value)
Truth table0%0/4
A and B and not(C)
A= $show_defaultB= @$valueC= not grep((!defined($_)), @$value)
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | if ($show_default && | ||||||||||||||||||||||||||||||||||||||||||
| 371 | @$value && ! grep (! defined $_, @$value)); | ||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | if ($argdesc) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | { | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | my $expanded_option = $option . " " . $argdesc if $argdesc; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | $option = $expanded_option; | |||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | if (length ($expanded_option) > $maxoption+1) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | { | ||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | $~ = 'ALTERNATIVE'; | |||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | write; | |||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | print $Usage if defined $Usage; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | # | ||||||||||||||||||||||||||||||||||||||||||
| 395 | # &scan_table | ||||||||||||||||||||||||||||||||||||||||||
| 396 | # | ||||||||||||||||||||||||||||||||||||||||||
| 397 | # walks through an argument table, building a hash that lets us quickly | ||||||||||||||||||||||||||||||||||||||||||
| 398 | # and painlessly look up an option. | ||||||||||||||||||||||||||||||||||||||||||
| 399 | # | ||||||||||||||||||||||||||||||||||||||||||
| 400 | sub scan_table | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
scan_table: called CC=6 SCAR=18.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 6 | my ($argtable, $arghash) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 403 | 6 | my ($opt, $option, $type, $value); | |||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 6 | my $i; | |||||||||||||||||||||||||||||||||||||||||
| 406 | 6 | for $i (0 .. $#$argtable) | |||||||||||||||||||||||||||||||||||||||||
| 407 | { | ||||||||||||||||||||||||||||||||||||||||||
| 408 | 36 | $opt = $argtable->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 409 | 36 | ($option, $type, $value) = @$opt; | |||||||||||||||||||||||||||||||||||||||||
| 410 | 36 | ▶ | unless (exists $OptionHandlers{$type}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | { | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | croak "Unknown option type \"$type\" supplied for option $option"; | |||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 36 | ▶ | if ($type eq "boolean") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | { | ||||||||||||||||||||||||||||||||||||||||||
| 417 | 6 | my ($pos,$neg) = &split_option($opt); | |||||||||||||||||||||||||||||||||||||||||
| 418 | 6 | $arghash->{$pos} = $i; | |||||||||||||||||||||||||||||||||||||||||
| 419 | 6 | ▶ | $arghash->{$neg} = $i if defined $neg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||
| 421 | elsif ($type ne "section") | ||||||||||||||||||||||||||||||||||||||||||
| 422 | { | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 30 | $arghash->{$option} = $i; | |||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | # | ||||||||||||||||||||||||||||||||||||||||||
| 430 | # &match_abbreviation | ||||||||||||||||||||||||||||||||||||||||||
| 431 | # | ||||||||||||||||||||||||||||||||||||||||||
| 432 | # Given a string $s and a list of words @$words, finds the word for which | ||||||||||||||||||||||||||||||||||||||||||
| 433 | # $s is a non-ambiguous abbreviation. If $s is found to be ambiguous or | ||||||||||||||||||||||||||||||||||||||||||
| 434 | # doesn't match, a clear and concise error message is printed, using | ||||||||||||||||||||||||||||||||||||||||||
| 435 | # $err_format as a format for sprintf. Suggested form for $err_format is | ||||||||||||||||||||||||||||||||||||||||||
| 436 | # "%s option: %s"; the first %s will be substituted with either "ambiguous" | ||||||||||||||||||||||||||||||||||||||||||
| 437 | # or "unknown" (depending on the problem), and the second will be | ||||||||||||||||||||||||||||||||||||||||||
| 438 | # substituted with $s. Thus, with this format, the error message will look | ||||||||||||||||||||||||||||||||||||||||||
| 439 | # something like "unknown option: -foo" or "ambiguous option: -f". | ||||||||||||||||||||||||||||||||||||||||||
| 440 | # | ||||||||||||||||||||||||||||||||||||||||||
| 441 | sub match_abbreviation | ||||||||||||||||||||||||||||||||||||||||||
| 442 | 15 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_abbreviation: called CC=6 SCAR=25.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 15 | my ($s, $words, $err_format) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 15 | my ($match); | |||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | my $word; | ||||||||||||||||||||||||||||||||||||||||||
| 447 | 15 | foreach $word (@$words) | |||||||||||||||||||||||||||||||||||||||||
| 448 | { | ||||||||||||||||||||||||||||||||||||||||||
| 449 | # If $s is a prefix of $word, it's at least an approximate match, | ||||||||||||||||||||||||||||||||||||||||||
| 450 | # so try to do better | ||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 46 | ▶ | next unless ($s eq substr ($word, 0, length ($s))); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||
| 454 | # We have an exact match, so return it now | ||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | 15 | ▶ | return $word if ($s eq $word); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | # We have an approx. match, and already had one before | ||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | ▶ | if ($match) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | { | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | &SetError ("bad_option", sprintf ("$err_format", "ambiguous", $s)); | |||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | $match = $word; | |||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | &SetError ("bad_option", sprintf ("$err_format", "unknown", $s)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | if !$match; | ||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | $match; | |||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | # | ||||||||||||||||||||||||||||||||||||||||||
| 475 | # &option_error | ||||||||||||||||||||||||||||||||||||||||||
| 476 | # | ||||||||||||||||||||||||||||||||||||||||||
| 477 | # Constructs a useful error message to deal with an option that expects | ||||||||||||||||||||||||||||||||||||||||||
| 478 | # a certain number of values of certain types, but a command-line that | ||||||||||||||||||||||||||||||||||||||||||
| 479 | # falls short of this mark. $option should be the option that triggers | ||||||||||||||||||||||||||||||||||||||||||
| 480 | # the situation; $type should be the expected type; $n should be the | ||||||||||||||||||||||||||||||||||||||||||
| 481 | # number of values expected. | ||||||||||||||||||||||||||||||||||||||||||
| 482 | # | ||||||||||||||||||||||||||||||||||||||||||
| 483 | # The error message (returned by the function) will look something like | ||||||||||||||||||||||||||||||||||||||||||
| 484 | # "-foo option must be followed by an integer" (yes, it does pick "a" | ||||||||||||||||||||||||||||||||||||||||||
| 485 | # or "an", depending on whether the description of the type starts | ||||||||||||||||||||||||||||||||||||||||||
| 486 | # with a vowel) or "-bar option must be followed by 3 strings". | ||||||||||||||||||||||||||||||||||||||||||
| 487 | # | ||||||||||||||||||||||||||||||||||||||||||
| 488 | # The error message is put in the global $ErrorMessage, as well as returned | ||||||||||||||||||||||||||||||||||||||||||
| 489 | # by the function. Also, the global $ErrorClass is set to "bad_value". | ||||||||||||||||||||||||||||||||||||||||||
| 490 | # | ||||||||||||||||||||||||||||||||||||||||||
| 491 | sub option_error | ||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
option_error: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | my ($option, $type, $n) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | my ($typedesc, $singular, $plural, $article, $desc); | |||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | $typedesc = $TypeDescriptions{$type}; | |||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | ▶ | ($singular,$plural) = (ref $typedesc eq 'ARRAY') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | ? @$typedesc | ||||||||||||||||||||||||||||||||||||||||||
| 499 | : ($typedesc, $typedesc . "s"); | ||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | ▶ | $article = ($typedesc =~ /^[aeiou]/) ? "an" : "a"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | ▶ | $desc = ($n > 1) ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | "$n $plural" : | ||||||||||||||||||||||||||||||||||||||||||
| 504 | "$article $singular"; | ||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | &SetError ("bad_value", "$option option must be followed by $desc"); | |||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | # | ||||||||||||||||||||||||||||||||||||||||||
| 510 | # &check_value | ||||||||||||||||||||||||||||||||||||||||||
| 511 | # | ||||||||||||||||||||||||||||||||||||||||||
| 512 | # Verifies that a value (presumably from the command line) satisfies | ||||||||||||||||||||||||||||||||||||||||||
| 513 | # the requirements for the expected type. | ||||||||||||||||||||||||||||||||||||||||||
| 514 | # | ||||||||||||||||||||||||||||||||||||||||||
| 515 | # Calls &option_error (to set $ErrorClass and $ErrorMessage globals) and returns | ||||||||||||||||||||||||||||||||||||||||||
| 516 | # 0 if the value isn't up to scratch. | ||||||||||||||||||||||||||||||||||||||||||
| 517 | # | ||||||||||||||||||||||||||||||||||||||||||
| 518 | sub check_value | ||||||||||||||||||||||||||||||||||||||||||
| 519 | 14 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_value: called CC=3 SCAR=15.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | 14 | my ($val, $option, $type, $n) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | 14 | ▶ | unless (defined $val && $val =~ /^$Patterns{$type}$/x) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $val and $val =~ /^$Getopt::Tabular::Patterns{$type}$/x
MC/DC0%0/2
defined $val and $val =~ /^$Getopt::Tabular::Patterns{$type}$/x
defined $val
$val =~ /^$Getopt::Tabular::Patterns{$type}$/x
Truth table33%1/3
A and B
A= defined $valB= $val =~ /^$Getopt::Tabular::Patterns{$type}$/x
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | { | ||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | &option_error ($option, $type, $n); | |||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | # | ||||||||||||||||||||||||||||||||||||||||||
| 531 | # &split_option | ||||||||||||||||||||||||||||||||||||||||||
| 532 | # | ||||||||||||||||||||||||||||||||||||||||||
| 533 | # Splits a boolean option into positive and negative alternatives. The | ||||||||||||||||||||||||||||||||||||||||||
| 534 | # two alternatives are returned as a two-element array. | ||||||||||||||||||||||||||||||||||||||||||
| 535 | # | ||||||||||||||||||||||||||||||||||||||||||
| 536 | # Croaks if it can't figure out the alternatives, or if there appear to be | ||||||||||||||||||||||||||||||||||||||||||
| 537 | # more than 2 alternatives specified. | ||||||||||||||||||||||||||||||||||||||||||
| 538 | # | ||||||||||||||||||||||||||||||||||||||||||
| 539 | sub split_option | ||||||||||||||||||||||||||||||||||||||||||
| 540 | 46 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
split_option: called CC=6 SCAR=19.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 541 | 46 | my ($opt_desc) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 542 | 46 | my ($option, @options); | |||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||
| 544 | 46 | $option = $opt_desc->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 545 | 46 | ▶ | return ($option) if $opt_desc->[1] ne "boolean"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | 16 | @options = split ('\|', $option); | |||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | 16 | ▶ | if (@options == 2) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 550 | { | ||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | return @options; | |||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||
| 553 | elsif (@options == 1) | ||||||||||||||||||||||||||||||||||||||||||
| 554 | { | ||||||||||||||||||||||||||||||||||||||||||
| 555 | 16 | my ($pattern, $prefix, $positive_alt, $negative_alt); | |||||||||||||||||||||||||||||||||||||||||
| 556 | 16 | for $pattern (@OptionPatterns) | |||||||||||||||||||||||||||||||||||||||||
| 557 | { | ||||||||||||||||||||||||||||||||||||||||||
| 558 | 16 | my ($prefix, $body); | |||||||||||||||||||||||||||||||||||||||||
| 559 | 16 | ▶ | if (($prefix, $body) = $option =~ /^$pattern$/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 560 | { | ||||||||||||||||||||||||||||||||||||||||||
| 561 | 16 | $negative_alt = $prefix . "no" . $body; | |||||||||||||||||||||||||||||||||||||||||
| 562 | 16 | return ($option, $negative_alt); | |||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | croak "Boolean option \"$option\" did not match " . | |||||||||||||||||||||||||||||||||||||||||
| 566 | "any option prefixes - unable to guess negative alternative"; | ||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | return ($option); | |||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||
| 569 | else | ||||||||||||||||||||||||||||||||||||||||||
| 570 | { | ||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | croak "Too many alternatives supplied for boolean option \"$option\""; | |||||||||||||||||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | # | ||||||||||||||||||||||||||||||||||||||||||
| 577 | # &find_calling_package | ||||||||||||||||||||||||||||||||||||||||||
| 578 | # | ||||||||||||||||||||||||||||||||||||||||||
| 579 | # walks up the call stack until we find a caller in a different package | ||||||||||||||||||||||||||||||||||||||||||
| 580 | # from the current one. (Handy for `eval' options, when we want to | ||||||||||||||||||||||||||||||||||||||||||
| 581 | # eval a chunk of code in the package that called GetOptions.) | ||||||||||||||||||||||||||||||||||||||||||
| 582 | # | ||||||||||||||||||||||||||||||||||||||||||
| 583 | sub find_calling_package | ||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_calling_package: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | my ($i, $this_pkg, $up_pkg, @caller); | |||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | $this_pkg = (caller(0))[0]; | |||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | ▶ | while (@caller = caller($i++)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 590 | { | ||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | $up_pkg = $caller[0]; | |||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | ▶ | last if $up_pkg ne $this_pkg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | $up_pkg; | |||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||
| 598 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 599 | # Option-handling routines: | ||||||||||||||||||||||||||||||||||||||||||
| 600 | # process_constant_option | ||||||||||||||||||||||||||||||||||||||||||
| 601 | # process_boolean_option | ||||||||||||||||||||||||||||||||||||||||||
| 602 | # process_call_option | ||||||||||||||||||||||||||||||||||||||||||
| 603 | # process_eval_option | ||||||||||||||||||||||||||||||||||||||||||
| 604 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||
| 606 | # General description of these routines: | ||||||||||||||||||||||||||||||||||||||||||
| 607 | # * each one is passed exactly four options: | ||||||||||||||||||||||||||||||||||||||||||
| 608 | # $arg - the argument that triggered this routine, expanded | ||||||||||||||||||||||||||||||||||||||||||
| 609 | # into unabbreviated form | ||||||||||||||||||||||||||||||||||||||||||
| 610 | # $arglist - reference to list containing rest of command line | ||||||||||||||||||||||||||||||||||||||||||
| 611 | # $opt_desc - reference to an option descriptor list | ||||||||||||||||||||||||||||||||||||||||||
| 612 | # $spoof - flag: if true, then no side effects | ||||||||||||||||||||||||||||||||||||||||||
| 613 | # * they are called from GetOptions, through code references in the | ||||||||||||||||||||||||||||||||||||||||||
| 614 | # %OptionHandlers hash | ||||||||||||||||||||||||||||||||||||||||||
| 615 | # * if they return a false value, then GetOptions immediately returns | ||||||||||||||||||||||||||||||||||||||||||
| 616 | # 0 to its caller, with no error message -- thus, the option handlers | ||||||||||||||||||||||||||||||||||||||||||
| 617 | # should print out enough of an error message for the end user to | ||||||||||||||||||||||||||||||||||||||||||
| 618 | # figure out what went wrong; also, the option handlers should be | ||||||||||||||||||||||||||||||||||||||||||
| 619 | # careful to explicitly return 1 if everything went well! | ||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||
| 621 | sub process_constant_option | ||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_constant_option: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | my ($arg, $arglist, $opt_desc, $spoof) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | my ($type, $n, $value) = @$opt_desc[1,2,3]; | |||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | ▶ | return 1 if $spoof; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | ▶ | if ($type eq "const") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 629 | { | ||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | $$value = $n; | |||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||
| 632 | elsif ($type eq "copy") | ||||||||||||||||||||||||||||||||||||||||||
| 633 | { | ||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | ▶ | $$value = (defined $n) ? ($n) : ($arg); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||||||||||||||||
| 636 | elsif ($type eq "arrayconst") | ||||||||||||||||||||||||||||||||||||||||||
| 637 | { | ||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | @$value = @$n; | |||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||
| 640 | elsif ($type eq "hashconst") | ||||||||||||||||||||||||||||||||||||||||||
| 641 | { | ||||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | %$value = %$n; | |||||||||||||||||||||||||||||||||||||||||
| 643 | } | ||||||||||||||||||||||||||||||||||||||||||
| 644 | else | ||||||||||||||||||||||||||||||||||||||||||
| 645 | { | ||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | confess ("internal error: can't handle option type \"$type\""); | |||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||
| 653 | sub process_boolean_option | ||||||||||||||||||||||||||||||||||||||||||
| 654 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_boolean_option: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 655 | 4 | my ($arg, $arglist, $opt_desc, $spoof) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 656 | 4 | my ($value) = $$opt_desc[3]; | |||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||
| 658 | 4 | ▶ | return 1 if $spoof; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||
| 660 | 4 | my ($pos,$neg) = &split_option ($opt_desc); | |||||||||||||||||||||||||||||||||||||||||
| 661 | 4 | ▶ | confess ("internal error: option $arg not found in argument hash") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$arg ne $pos and $arg ne $neg
MC/DC0%0/2
$arg ne $pos and $arg ne $neg
$arg ne $pos
$arg ne $neg
Truth table66%2/3
A and B
A= $arg ne $posB= $arg ne $neg
| |||||||||||||||||||||||||||||||||||||||||||
| 662 | if ($arg ne $pos && $arg ne $neg); | ||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||
| 664 | 4 | ▶ | $$value = ($arg eq $pos) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 665 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||
| 669 | sub process_call_option | ||||||||||||||||||||||||||||||||||||||||||
| 670 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_call_option: called CC=7 SCAR=23.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 671 | 2 | my ($arg, $arglist, $opt_desc, $spoof) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 672 | 2 | my ($option, $args, $value) = @$opt_desc[0,2,3]; | |||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||
| 674 | 2 | ▶ | croak "Invalid option table entry for option \"$option\" -- \"value\" " . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 675 | "field must be a code reference" | ||||||||||||||||||||||||||||||||||||||||||
| 676 | unless (ref $value eq 'CODE'); | ||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||
| 678 | # This will crash 'n burn big time if there is no spoof code for | ||||||||||||||||||||||||||||||||||||||||||
| 679 | # this option -- but that's why we check %SpoofCode against the | ||||||||||||||||||||||||||||||||||||||||||
| 680 | # arg table from GetOptions! | ||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||
| 682 | 2 | ▶ | $value = $SpoofCode{$arg} if ($spoof); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||
| 684 | 2 | ▶ | my @args = (ref $args eq 'ARRAY') ? (@$args) : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 685 | 2 | my $result = &$value ($arg, $arglist, @args); | |||||||||||||||||||||||||||||||||||||||||
| 686 | 2 | ▶ | if (!$result) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 687 | { | ||||||||||||||||||||||||||||||||||||||||||
| 688 | # Wouldn't it be neat if we could get the sub name from the code ref? | ||||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | ▶ | &SetError | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
$Getopt::Tabular::ErrorClass || 'bad_call'
$Getopt::Tabular::ErrorMessage || qq[subroutine call from option "$arg" failed]
MC/DC0%0/1
$Getopt::Tabular::ErrorClass || 'bad_call'
$Getopt::Tabular::ErrorClass
MC/DC0%0/1
$Getopt::Tabular::ErrorMessage || qq[subroutine call from option "$arg" failed]
$Getopt::Tabular::ErrorMessage
Truth table0%0/2
A
A= $Getopt::Tabular::ErrorClass
Truth table0%0/2
A
A= $Getopt::Tabular::ErrorMessage
| |||||||||||||||||||||||||||||||||||||||||||
| 690 | ($ErrorClass || "bad_call", | ||||||||||||||||||||||||||||||||||||||||||
| 691 | $ErrorMessage || "subroutine call from option \"$arg\" failed"); | ||||||||||||||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||
| 694 | 2 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||
| 696 | } # &process_call_option | ||||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||
| 699 | sub process_eval_option | ||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_eval_option: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | my ($arg, $arglist, $opt_desc, $spoof) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | my ($value) = $$opt_desc[3]; | |||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | ▶ | $value = $SpoofCode{$arg} if ($spoof); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||
| 706 | 0 | my $up_pkg = &find_calling_package (); | |||||||||||||||||||||||||||||||||||||||||
| 707 | # print "package $up_pkg; $value"; # DEBUG ONLY | ||||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | my $result = eval "package $up_pkg; no strict; $value"; | |||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | ▶ | if ($@) # any error string set? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 711 | { | ||||||||||||||||||||||||||||||||||||||||||
| 712 | 0 | &SetError ("bad_eval", | |||||||||||||||||||||||||||||||||||||||||
| 713 | "error evaluating \"$value\" (from $arg option): $@"); | ||||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | ▶ | if (!$result) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 718 | { | ||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | ▶ | &SetError | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
$Getopt::Tabular::ErrorClass || 'bad_call'
$Getopt::Tabular::ErrorMessage || qq[code eval'd for option "$arg" failed]
MC/DC0%0/1
$Getopt::Tabular::ErrorClass || 'bad_call'
$Getopt::Tabular::ErrorClass
MC/DC0%0/1
$Getopt::Tabular::ErrorMessage || qq[code eval'd for option "$arg" failed]
$Getopt::Tabular::ErrorMessage
Truth table0%0/2
A
A= $Getopt::Tabular::ErrorClass
Truth table0%0/2
A
A= $Getopt::Tabular::ErrorMessage
| |||||||||||||||||||||||||||||||||||||||||||
| 720 | ($ErrorClass || "bad_call", | ||||||||||||||||||||||||||||||||||||||||||
| 721 | $ErrorMessage || "code eval'd for option \"$arg\" failed"); | ||||||||||||||||||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||
| 728 | sub process_pattern_option | ||||||||||||||||||||||||||||||||||||||||||
| 729 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_pattern_option: called CC=10 SCAR=24.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 730 | 9 | my ($arg, $arglist, $opt_desc, $spoof) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 731 | 9 | my ($type, $n, $value) = @$opt_desc[1,2,3]; | |||||||||||||||||||||||||||||||||||||||||
| 732 | 9 | my ($dummy, @dummies); | |||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||
| 734 | # This code looks a little more complicated than you might at first | ||||||||||||||||||||||||||||||||||||||||||
| 735 | # think necessary. But the ugliness is necessary because $value might | ||||||||||||||||||||||||||||||||||||||||||
| 736 | # reference a scalar or an array, depending on whether $n is 1 (scalar) | ||||||||||||||||||||||||||||||||||||||||||
| 737 | # or not (array). Thus, we can't just assume that either @$value or | ||||||||||||||||||||||||||||||||||||||||||
| 738 | # $$value is valid -- we always have to check which of the two it should | ||||||||||||||||||||||||||||||||||||||||||
| 739 | # be. | ||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||
| 741 | 9 | ▶ | if ($n == 1) # scalar-valued option (one argument) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 742 | { | ||||||||||||||||||||||||||||||||||||||||||
| 743 | 4 | ▶ | croak "GetOptions: \"$arg\" option must be associated with a scalar ref" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 744 | unless ref $value eq 'SCALAR'; | ||||||||||||||||||||||||||||||||||||||||||
| 745 | 4 | ▶ | $value = \$dummy if $spoof; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 746 | 4 | $$value = shift @$arglist; | |||||||||||||||||||||||||||||||||||||||||
| 747 | 4 | ▶ | return 0 unless &check_value ($$value, $arg, $type, $n); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 748 | } | ||||||||||||||||||||||||||||||||||||||||||
| 749 | else # it's a "vector-valued" option | ||||||||||||||||||||||||||||||||||||||||||
| 750 | { # (fixed number of arguments) | ||||||||||||||||||||||||||||||||||||||||||
| 751 | 5 | ▶ | croak "GetOptions: \"$arg\" option must be associated with an array ref" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 752 | unless ref $value eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 753 | 5 | ▶ | $value = \@dummies if $spoof; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 754 | 5 | @$value = splice (@$arglist, 0, $n); | |||||||||||||||||||||||||||||||||||||||||
| 755 | 5 | ▶ | if (scalar @$value != $n) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 756 | { | ||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | &option_error ($arg, $type, $n); | |||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||
| 761 | 5 | my $val; | |||||||||||||||||||||||||||||||||||||||||
| 762 | 5 | foreach $val (@$value) | |||||||||||||||||||||||||||||||||||||||||
| 763 | { | ||||||||||||||||||||||||||||||||||||||||||
| 764 | 10 | ▶ | return 0 unless &check_value ($val, $arg, $type, $n); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||||||||||||||||
| 766 | } # else | ||||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||
| 768 | 9 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||||||||||||||||
| 770 | } # &process_pattern_option | ||||||||||||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||
| 773 | # -------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 774 | # The main public subroutine: GetOptions | ||||||||||||||||||||||||||||||||||||||||||
| 775 | # -------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||
| 777 | sub GetOptions | ||||||||||||||||||||||||||||||||||||||||||
| 778 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
GetOptions: called CC=26 SCAR=49.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 779 | 6 | my ($opt_table, $arglist, $new_arglist, $spoof) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 780 | 6 | my (%argpos, $arg, $pos, $opt_ref); | |||||||||||||||||||||||||||||||||||||||||
| 781 | 6 | my ($option_re, @option_list); | |||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||
| 783 | 6 | ▶ | $new_arglist = $arglist if !defined $new_arglist; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 784 | 6 | &SetError ("", ""); | |||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||
| 786 | # Build a hash mapping option -> position in option table | ||||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||
| 788 | 6 | &scan_table ($opt_table, \%argpos); | |||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||
| 790 | # Regexp to let us recognize options on the command line | ||||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||
| 792 | 6 | $option_re = join ("|", @OptionPatterns); | |||||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||||||
| 794 | # Build a list of all acceptable options -- used to match abbreviations | ||||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||||
| 796 | 6 | my $opt_desc; | |||||||||||||||||||||||||||||||||||||||||
| 797 | 6 | foreach $opt_desc (@$opt_table) | |||||||||||||||||||||||||||||||||||||||||
| 798 | { | ||||||||||||||||||||||||||||||||||||||||||
| 799 | 36 | ▶ | push (@option_list, &split_option ($opt_desc)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 800 | unless $opt_desc->[1] eq "section"; | ||||||||||||||||||||||||||||||||||||||||||
| 801 | } | ||||||||||||||||||||||||||||||||||||||||||
| 802 | 6 | ▶ | push (@option_list, $HelpOption) if $HelpOption; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||
| 804 | # If in spoof mode: make sure we have spoof code for all call/eval options | ||||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||||
| 806 | 6 | ▶ | if ($spoof) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 807 | { | ||||||||||||||||||||||||||||||||||||||||||
| 808 | 0 | my ($opt, $type, $spoof); | |||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | foreach $opt_desc (@$opt_table) | |||||||||||||||||||||||||||||||||||||||||
| 811 | { | ||||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | $opt = $opt_desc->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | $type = $opt_desc->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 814 | 0 | $spoof = $SpoofCode{$opt}; | |||||||||||||||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | ▶ | next unless $type eq 'call' || $type eq 'eval'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type eq "call" or $type eq "eval"
MC/DC0%0/2
$type eq "call" or $type eq "eval"
$type eq "call"
$type eq "eval"
Truth table0%0/3
A or B
A= $type eq "call"B= $type eq "eval"
| |||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | ▶ | croak "No alternate code supplied for option $opt in spoof mode" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 818 | unless defined $spoof; | ||||||||||||||||||||||||||||||||||||||||||
| 819 | 0 | ▶ | croak "Alternate code must be a CODE ref for option $opt" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type eq "call" and ref $spoof ne "CODE"
MC/DC0%0/2
$type eq "call" and ref $spoof ne "CODE"
$type eq "call"
ref $spoof ne "CODE"
Truth table0%0/3
A and B
A= $type eq "call"B= ref $spoof ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 820 | if ($type eq 'call' && ref $spoof ne 'CODE'); | ||||||||||||||||||||||||||||||||||||||||||
| 821 | 0 | ▶ | croak "Alternate code must be a string for option $opt" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type eq "eval" and ref $spoof
MC/DC0%0/2
$type eq "eval" and ref $spoof
$type eq "eval"
ref $spoof
Truth table0%0/3
A and B
A= $type eq "eval"B= ref $spoof
| |||||||||||||||||||||||||||||||||||||||||||
| 822 | if ($type eq 'eval' && ref $spoof); | ||||||||||||||||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||||||||||||||||
| 824 | } | ||||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||
| 826 | # Now walk over the argument list | ||||||||||||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||||||||||
| 828 | 6 | my @tmp_arglist = @$arglist; | |||||||||||||||||||||||||||||||||||||||||
| 829 | 6 | @$new_arglist = (); | |||||||||||||||||||||||||||||||||||||||||
| 830 | 6 | ▶ | while (defined ($arg = shift @tmp_arglist)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 831 | { | ||||||||||||||||||||||||||||||||||||||||||
| 832 | # print "arg: $arg\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||
| 834 | # If this argument is the option terminator (usually "--") then | ||||||||||||||||||||||||||||||||||||||||||
| 835 | # transfer all remaining arguments to the new arg list and stop | ||||||||||||||||||||||||||||||||||||||||||
| 836 | # processing immediately. | ||||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||
| 838 | 27 | ▶ | if (defined $OptionTerminator && $arg eq $OptionTerminator) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $Getopt::Tabular::OptionTerminator and $arg eq $Getopt::Tabular::OptionTerminator
MC/DC0%0/2
defined $Getopt::Tabular::OptionTerminator and $arg eq $Getopt::Tabular::OptionTerminator
defined $Getopt::Tabular::OptionTerminator
$arg eq $Getopt::Tabular::OptionTerminator
Truth table33%1/3
A and B
A= defined $Getopt::Tabular::OptionTerminatorB= $arg eq $Getopt::Tabular::OptionTerminator
| |||||||||||||||||||||||||||||||||||||||||||
| 839 | { | ||||||||||||||||||||||||||||||||||||||||||
| 840 | 0 | push (@$new_arglist, @tmp_arglist); | |||||||||||||||||||||||||||||||||||||||||
| 841 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 842 | } | ||||||||||||||||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||||||||||||||
| 844 | # If this argument isn't an option at all, just append it to | ||||||||||||||||||||||||||||||||||||||||||
| 845 | # @$new_arglist and go to the next one. | ||||||||||||||||||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||||||||||||||||
| 847 | 27 | ▶ | if ($arg !~ /^($option_re)/o) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 848 | { | ||||||||||||||||||||||||||||||||||||||||||
| 849 | 12 | push (@$new_arglist, $arg); | |||||||||||||||||||||||||||||||||||||||||
| 850 | 12 | next; | |||||||||||||||||||||||||||||||||||||||||
| 851 | } | ||||||||||||||||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||||||||||||||||
| 853 | # We know we have something that looks like an option; see if it | ||||||||||||||||||||||||||||||||||||||||||
| 854 | # matches or is an abbreviation for one of the strings in | ||||||||||||||||||||||||||||||||||||||||||
| 855 | # @option_list | ||||||||||||||||||||||||||||||||||||||||||
| 856 | |||||||||||||||||||||||||||||||||||||||||||
| 857 | 15 | $arg = &match_abbreviation ($arg, \@option_list, "%s option: %s"); | |||||||||||||||||||||||||||||||||||||||||
| 858 | 15 | ▶ | if (! $arg) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 859 | { | ||||||||||||||||||||||||||||||||||||||||||
| 860 | 0 | ▶ | warn $Usage if defined $Usage; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 861 | 0 | warn "$ErrorMessage\n"; | |||||||||||||||||||||||||||||||||||||||||
| 862 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 863 | } | ||||||||||||||||||||||||||||||||||||||||||
| 864 | |||||||||||||||||||||||||||||||||||||||||||
| 865 | # If it's the help option, print out the help and return | ||||||||||||||||||||||||||||||||||||||||||
| 866 | # (even if in spoof mode!) | ||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||
| 868 | 15 | ▶ | if ($arg eq $HelpOption) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 869 | { | ||||||||||||||||||||||||||||||||||||||||||
| 870 | 0 | &print_help ($opt_table); | |||||||||||||||||||||||||||||||||||||||||
| 871 | 0 | &SetError ("help", ""); | |||||||||||||||||||||||||||||||||||||||||
| 872 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 873 | } | ||||||||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||||||||
| 875 | # Now we know it's a valid option, and it's not the help option -- | ||||||||||||||||||||||||||||||||||||||||||
| 876 | # so it must be in the caller's option table. Look up its | ||||||||||||||||||||||||||||||||||||||||||
| 877 | # entry there, and use that for the actual option processing. | ||||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||
| 879 | 15 | $pos = $argpos{$arg}; | |||||||||||||||||||||||||||||||||||||||||
| 880 | 15 | ▶ | confess ("internal error: didn't find arg in arg hash even " . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 881 | "after resolving abbreviation") | ||||||||||||||||||||||||||||||||||||||||||
| 882 | unless defined $pos; | ||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||
| 884 | 15 | my $opt_desc = $opt_table->[$pos]; | |||||||||||||||||||||||||||||||||||||||||
| 885 | 15 | my $type = $opt_desc->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 886 | 15 | my $handler = $OptionHandlers{$type}; | |||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||
| 888 | 15 | ▶ | if (defined $handler && ref ($handler) eq 'CODE') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $handler and ref $handler eq "CODE"
MC/DC0%0/2
defined $handler and ref $handler eq "CODE"
defined $handler
ref $handler eq "CODE"
Truth table33%1/3
A and B
A= defined $handlerB= ref $handler eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 889 | { | ||||||||||||||||||||||||||||||||||||||||||
| 890 | 15 | ▶ | if (! &$handler ($arg, \@tmp_arglist, $opt_desc, $spoof)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 891 | { | ||||||||||||||||||||||||||||||||||||||||||
| 892 | 0 | ▶ | warn $Usage if defined $Usage; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 893 | 0 | warn "$ErrorMessage\n"; | |||||||||||||||||||||||||||||||||||||||||
| 894 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 895 | } | ||||||||||||||||||||||||||||||||||||||||||
| 896 | } | ||||||||||||||||||||||||||||||||||||||||||
| 897 | else | ||||||||||||||||||||||||||||||||||||||||||
| 898 | { | ||||||||||||||||||||||||||||||||||||||||||
| 899 | 0 | croak "Unknown option type \"$type\" (found for arg $arg)"; | |||||||||||||||||||||||||||||||||||||||||
| 900 | } | ||||||||||||||||||||||||||||||||||||||||||
| 901 | } # while ($arg = shift @$arglist) | ||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||
| 903 | 6 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||||||||||||||||
| 905 | } # GetOptions | ||||||||||||||||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||||||||||||
| 908 | sub SpoofGetOptions | ||||||||||||||||||||||||||||||||||||||||||
| 909 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SpoofGetOptions: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 910 | 0 | &GetOptions (@_[0..2], 1); | |||||||||||||||||||||||||||||||||||||||||
| 911 | } | ||||||||||||||||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||||||||||||||||
| 913 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||