| 1 | 11 | ▶ | use v5.26; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 11 | ▶ | use Object::Pad; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use Getopt::Pad::Type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use Getopt::Pad::Error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use Getopt::Pad::Result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | class Getopt::Pad::Spec::Option :strict(params) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use Getopt::Pad::Util qw(camelize specError isValidName); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # The Value sources a parse hands over, in order of precedence, each with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # the wording of its user errors; the spec default follows them. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # command line gives a multiple option one word per occurrence, a config | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # file a lone value or a list. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 11 | my @valueSources = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | { key => 'commandLine', problemFormat => "option '--%s': %s", givesWords => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | { key => 'config', problemFormat => "config value for '%s': %s", givesWords => 0 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 11 | my %isValueSource = map { $_->{key} => 1 } @valueSources; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 11 | field $key :param; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 11 | field $raw :param; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1224 | ▶ | field $auto :param :reader = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
auto: not called CC=1 SCAR=0.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1224 | ▶ | field $optionalValue :param :reader = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
auto: called CC=1 SCAR=0.6
Subroutine
optionalValue: not called CC=1 SCAR=0.5
Pod
undocumented
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 15 | ▶ | field $trigger :param :reader = undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
optionalValue: called CC=1 SCAR=0.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 4259 | ▶ | field $name :reader; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Subroutine
trigger: called CC=1 SCAR=0.0
Pod
undocumented
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2714 | ▶ | field @aliases :reader; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aliases: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1135 | ▶ | field $reader :reader; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reader: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 264 | ▶ | field $type :reader; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | field $typeName :reader; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
typeName: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 87 | field $required :reader = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 87 | ▶ | field $hasDefault :reader = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
required: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 41 | ▶ | field $default :reader; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default: called CC=1 SCAR=0.0
Subroutine
hasDefault: called CC=1 SCAR=0.0
Pod
undocumented
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 112 | ▶ | field $valid :reader; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
valid: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 11 | field $lazyValid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 189 | ▶ | field $group :reader; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
group: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 149 | field $help :reader = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 149 | ▶ | field $multiple :reader = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
help: called CC=1 SCAR=0.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | field $hash :reader = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
multiple: not called CC=1 SCAR=0.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 166 | ▶ | field $csv :reader = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hash: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 163 | ▶ | field $objectlist :reader = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
csv: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 154 | ▶ | field $hidden :reader = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
objectlist: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 293 | ▶ | field $inherit :reader = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hidden: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 2690 | ▶ | field $typehint :reader; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inherit: called CC=1 SCAR=0.6
Subroutine
typehint: not called CC=1 SCAR=0.6
Pod
undocumented
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ADJUST { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | specError("option key must be a non-empty string") if !defined $key || $key eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | specError("option '%s': spec must be a hash reference", $key) if ref $raw ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | specError("option '%s': a trigger is only allowed on auto options", $key) if defined $trigger && !$auto; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | ($name, @aliases) = split /\|/, $key, -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | foreach my $candidate ($name, @aliases) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | specError("option '%s': invalid name '%s'", $key, $candidate // '') if !isValidName($candidate); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | $reader = camelize($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | specError("option '%s': reader '%s' collides with a built-in result method", $name, $reader) if !$auto && Getopt::Pad::Result->reservesReader($reader); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | my %spec = $raw->%*; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ($type, $typeName) = Getopt::Pad::Type::takeFromSpec(\%spec, 'flag', sprintf("option '%s'", $name)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | $required = delete $spec{required} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | if (exists $spec{default}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | $hasDefault = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | $default = delete $spec{default}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | $valid = delete $spec{valid}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | $lazyValid = delete $spec{lazyValid}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | $group = delete $spec{group} // 'Options'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | $help = delete $spec{help} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | $multiple = delete $spec{multiple} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | $hash = delete $spec{hash} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | $csv = delete $spec{csv} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | $objectlist = delete $spec{objectlist} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | $hidden = delete $spec{hidden} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | $inherit = delete $spec{inherit} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | $typehint = delete $spec{typehint}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | specError("option '%s': unknown key(s): %s", $name, join(', ', sort keys %spec)) if %spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | specError("option '%s': required and default are mutually exclusive", $name) if $required && $hasDefault; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | my %shapeFlags = (multiple => $multiple, hash => $hash, objectlist => $objectlist); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | my @shapes = grep { $shapeFlags{$_} } qw(multiple hash objectlist); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | specError("option '%s': %s requires a value-taking type, not '%s'", $name, $shapes[0], $typeName) if @shapes && !$type->takesValue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | specError("option '%s': %s are mutually exclusive", $name, join(' and ', @shapes)) if @shapes > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | specError("option '%s': csv requires multiple", $name) if $csv && !$multiple; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | specError("option '%s': valid must be an array or code reference", $name) if defined $valid && ref $valid ne 'ARRAY' && ref $valid ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | specError("option '%s': lazyValid must be a code reference", $name) if defined $lazyValid && ref $lazyValid ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | specError("option '%s': typehint must be a non-empty string", $name) if defined $typehint && (ref $typehint || $typehint eq ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | $default = $self->checkedDefault($default) if $hasDefault; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # The spec default in the option's shape, every value checked and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # coerced. Only a scalar default may be undef: it means "no default" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # to the help output. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 108 | ▶ | method checkedDefault($value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
checkedDefault: called CC=5 SCAR=16.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 108 | ▶ | return undef if !defined $value && !$multiple && !$hash && !$objectlist; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
defined $value or $multiple or $hash or $objectlist
defined $value or $multiple or $hash
defined $value or $multiple
MC/DC25%1/4
defined $value or $multiple or $hash or $objectlist
defined $value
$multiple
$hash
$objectlist
Truth table40%2/5
A or B or C or D
A= defined $valueB= $multipleC= $hashD= $objectlist
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 107 | ▶ | return $self->shapedValue($value, sub ($problem) { specError("option '%s': default value: %s", $name, $problem) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # What the reader gets when no value source set the option and the spec | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # has no default: an empty list or mapping, or undef. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 59 | ▶ | method emptyValue() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
emptyValue: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 59 | ▶ | return [] if $multiple || $objectlist; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$multiple or $objectlist
MC/DC100%2/2
$multiple or $objectlist
$multiple
$objectlist
Truth table100%3/3
A or B
A= $multipleB= $objectlist
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 43 | ▶ | return {} if $hash; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 27 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # Each parse gets its own copy of a list, mapping or objectlist default. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 30 | ▶ | method copiedDefault() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
copiedDefault: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 30 | ▶ | return [map { ref $_ eq 'HASH' ? { $_->%* } : $_ } $default->@*] if ref $default eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 26 | ▶ | return { $default->%* } if ref $default eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 24 | return $default; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # Whether the option collects key=value words: a hash option, or an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # objectlist option with its INDEX.FIELD keys. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 999 | ▶ | method takesPairs() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
takesPairs: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 999 | ▶ | return $hash || $objectlist ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$hash or $objectlist
MC/DC100%2/2
$hash or $objectlist
$hash
$objectlist
Truth table100%3/3
A or B
A= $hashB= $objectlist
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # The tag the help output renders after the help text: the spec's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # typehint, or what the type calls itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 99 | ▶ | method typeLabel() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
typeLabel: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 99 | ▶ | return $typehint // $type->label; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$typehint // $type->label
MC/DC100%2/2
$typehint // $type->label
$typehint
$type->label
Truth table100%3/3
A // B
A= $typehintB= $type->label
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # The values the valid constraint allows right now: the static list, or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # what the valid coderef produces when asked. Empty without a constraint. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 96 | ▶ | method validValues() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validValues: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 96 | ▶ | return () if !defined $valid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 95 | ▶ | return $valid->@* if ref $valid eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 7 | my $values = $valid->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 7 | ▶ | specError("option '%s': the valid coderef must return an array reference", $name) if ref $values ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 6 | return $values->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # Check $value's shape, then the type, the valid list and the lazyValid | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # predicate. Returns the problem description (undef when the value is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # acceptable) and the coerced value; the caller decides how to report | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # the problem. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 227 | ▶ | method checkValue($value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
checkValue: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 227 | ▶ | return ('expected a single value, not a list or mapping', $value) if ref $value eq 'ARRAY' || ref $value eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $value eq "ARRAY" or ref $value eq "HASH"
MC/DC100%2/2
ref $value eq "ARRAY" or ref $value eq "HASH"
ref $value eq "ARRAY"
ref $value eq "HASH"
Truth table100%3/3
A or B
A= ref $value eq "ARRAY"B= ref $value eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 223 | my $problem = $type->check($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 223 | ▶ | return ($problem, $value) if defined $problem; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 214 | $value = $type->coerce($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 214 | ▶ | if (defined $valid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 81 | my @allowed = $self->validValues; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 80 | ▶ | return (sprintf("'%s' is not one of: %s", $value, join(', ', @allowed)), $value) if !grep { $_ eq $value } @allowed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 205 | ▶ | return (sprintf("'%s' is not a valid value", $value), $value) if defined $lazyValid && !$lazyValid->($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $lazyValid and not &$lazyValid($value)
MC/DC50%1/2
defined $lazyValid and not &$lazyValid($value)
defined $lazyValid
not &$lazyValid($value)
Truth table66%2/3
A and not(B)
A= defined $lazyValidB= not &$lazyValid($value)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 204 | return (undef, $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # The Reader value for one parse. %sources maps each Value source to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # raw values it gave, keyed by Primary name; a name missing from a map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # means that source did not set the option. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 209 | ▶ | method readerValue(%sources) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readerValue: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 209 | my @unknown = grep { !$isValueSource{$_} } sort keys %sources; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 209 | ▶ | croak(sprintf("Getopt::Pad: unknown value source(s): %s", join(', ', @unknown))) if @unknown; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 208 | foreach my $source (@valueSources) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 354 | ▶ | my $given = $sources{$source->{key}} // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$sources{$source->{"key"}} // {}
MC/DC100%1/1
$sources{$source->{"key"}} // {}
$sources{$source->{"key"}}
Truth table100%2/2
A
A= $sources{$source->{"key"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 354 | ▶ | next if !exists $given->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 117 | return $self->preparedValue($self->validatedValue($given->{$name}, $source)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 91 | ▶ | return $self->preparedValue($self->copiedDefault) if $hasDefault; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 61 | ▶ | Getopt::Pad::Error->throw("missing required option '--%s'", $name) if $required; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 59 | return $self->emptyValue; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # The effective value after the type prepared every scalar in it, e.g. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # created a path on demand. Only the value a parse settles on gets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # here, never a default the command line overrides. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 115 | ▶ | method preparedValue($value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
preparedValue: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 115 | foreach my $scalar ($self->scalarsOf($value)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 130 | my $problem = $type->prepare($scalar); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 130 | ▶ | Getopt::Pad::Error->throw("option '--%s': %s", $name, $problem) if defined $problem; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 115 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 162 | ▶ | method scalarsOf($value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
scalarsOf: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 162 | ▶ | return map { $self->scalarsOf($_) } $value->@* if ref $value eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 145 | ▶ | return map { $self->scalarsOf($_) } values $value->%* if ref $value eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 130 | return ($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # The value one source gave, in the option's shape, with problems | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # reported in that source's wording. The command line gives a multiple | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # option its words and a pair-taking option a flat mapping of its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # key=value pairs; a config file gives the shape directly. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 117 | ▶ | method validatedValue($value, $source) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validatedValue: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 117 | ▶ | my $report = sub ($problem) { Getopt::Pad::Error->throw($source->{problemFormat}, $name, $problem) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 117 | ▶ | return [map { $self->checkedScalar($_, $report) } $self->listItems($value, $source, $report)] if $multiple; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 103 | ▶ | $value = $self->objectsFromPairs($value, $report) if $objectlist && $source->{givesWords}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$objectlist and $source->{"givesWords"}
MC/DC100%2/2
$objectlist and $source->{"givesWords"}
$objectlist
$source->{"givesWords"}
Truth table100%3/3
A and B
A= $objectlistB= $source->{"givesWords"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 100 | return $self->shapedValue($value, $report); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # The items a multiple option received from $source. A csv option splits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # every word and every lone config value at commas; a config list is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # taken as given. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 14 | ▶ | method listItems($value, $source, $report) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
listItems: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 14 | ▶ | my $isConfigList = ref $value eq 'ARRAY' && !$source->{givesWords}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
ref $value eq 'ARRAY' && !$source->{'givesWords'}
MC/DC100%2/2
ref $value eq 'ARRAY' && !$source->{'givesWords'}
ref $value eq 'ARRAY'
!$source->{'givesWords'}
Truth table100%3/3
A && not(B)
A= ref $value eq 'ARRAY'B= !$source->{'givesWords'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 14 | ▶ | return $value->@* if $isConfigList; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 11 | ▶ | my @scalars = ref $value eq 'ARRAY' ? $value->@* : ($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 11 | ▶ | return @scalars if !$csv; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 7 | return map { $self->csvItems($_, $report) } @scalars; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # Items are trimmed; one trailing comma is tolerated, an empty item is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # not. An undefined value passes through to be reported as missing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 8 | ▶ | method csvItems($word, $report) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
csvItems: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 8 | ▶ | return ($word) if !defined $word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 7 | my $trimmed = $word =~ s/\A\s+|\s+\z//gr =~ s/,\z//r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 7 | my @items = map { s/\A\s+|\s+\z//gr } split /,/, $trimmed, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 7 | ▶ | $report->(sprintf("'%s' contains an empty item", $word)) if !@items || grep { $_ eq '' } @items; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not @items or grep {$_ eq "";} @items
MC/DC100%2/2
not @items or grep {$_ eq "";} @items
not @items
grep {$_ eq "";} @items
Truth table100%3/3
not(A) or B
A= not @itemsB= grep {$_ eq "";} @items
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 5 | return @items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # The objects an objectlist option collects from its INDEX.FIELD=VALUE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # words, handed over as a flat mapping. The indices must form 0..n-1. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 7 | ▶ | method objectsFromPairs($pairs, $report) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
objectsFromPairs: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 7 | my @objects; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 7 | foreach my $key (sort keys $pairs->%*) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 10 | ▶ | my ($index, $field) = $key =~ /\A(\d+)\.([\w-]+)\z/ or $report->(sprintf("invalid key '%s', expected INDEX.FIELD=VALUE", $key)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 8 | $objects[$index]{$field} = $pairs->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 5 | foreach my $index (0 .. $#objects) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 7 | ▶ | $report->(sprintf('missing index %d', $index)) if !defined $objects[$index]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 4 | return \@objects; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # $value in the option's shape with every scalar checked and coerced: a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # list for multiple, a mapping for hash, a list of mappings for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # objectlist, else one scalar. $report is told about a problem, worded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # without the option name, and does not return. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 207 | ▶ | method shapedValue($value, $report) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shapedValue: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 207 | ▶ | return $self->shapedList($value, $report) if $multiple; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 205 | ▶ | return $self->shapedMapping($value, $report) if $hash; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 189 | ▶ | return $self->shapedObjects($value, $report) if $objectlist; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 177 | return $self->checkedScalar($value, $report); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 2 | ▶ | method shapedList($value, $report) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shapedList: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 2 | ▶ | $report->('expected a list of values') if ref $value ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1 | return [map { $self->checkedScalar($_, $report) } $value->@*]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 30 | ▶ | method shapedMapping($value, $report) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shapedMapping: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 30 | ▶ | $report->('expected a mapping of keys to values') if ref $value ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 25 | my %checked; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 25 | foreach my $key (sort keys $value->%*) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 31 | ▶ | $report->('empty key') if $key eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 29 | $checked{$key} = $self->checkedScalar($value->{$key}, $self->reportUnder($report, sprintf("key '%s'", $key))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 19 | return \%checked; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 12 | ▶ | method shapedObjects($value, $report) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shapedObjects: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 12 | ▶ | $report->('expected a list of mappings') if ref $value ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 10 | return [map { $self->shapedMapping($value->[$_], $self->reportUnder($report, sprintf('entry %d', $_))) } 0 .. $#$value]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # A reporter that prefixes where the problem sits, e.g. "key 'os': ...". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 43 | ▶ | method reportUnder($report, $where) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reportUnder: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 43 | ▶ | return sub ($problem) { $report->(sprintf('%s: %s', $where, $problem)) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 230 | ▶ | method checkedScalar($value, $report) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
checkedScalar: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 230 | ▶ | $report->('no value given') if !defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 227 | my ($problem, $coerced) = $self->checkValue($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 226 | ▶ | $report->($problem) if defined $problem; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 204 | return $coerced; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 983 | ▶ | method glSpec() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
glSpec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 983 | return $type->glSpec(join('|', $name, @aliases), optionalValue => $optionalValue, multiple => $multiple, hash => $self->takesPairs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 217 | ▶ | method negatable() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
negatable: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 217 | return $type->negatable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 11 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||