Pad/Spec/Option.pm

filter: Statementstmt 97.3% 299 / 307 Branchbran 98.7% 79 / 80 Conditioncond 88.5% 31 / 35 MC/DCmcdc 80.9% 17 / 21 Subroutinesub 92.7% 51 / 55 Podpod 15.5% 7 / 45 totaltotal 89.1% 484 / 543 CC 58 SCAR 11.8
CC
58
Cov
97%
checkValue
8.0
readerValue
7.0
checkedDefault
5.1
CRAP 3.3
« Pad/Parser.pm ↑ Summary Pad/Spec.pm »
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.04';
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
BranchTrueFalseTotal
unless defined $value or $multiple or $hash or $objectlist 1 107 108
Condition66%6/9
defined $value or $multiple or $hash or $objectlist
l!l&&r!l&&!r
10701
defined $value or $multiple or $hash
l!l&&r!l&&!r
10701
defined $value or $multiple
l!l&&r!l&&!r
10701
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
ABCDresult
1XXX1
01XX1
001X1
00011
00000
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
BranchTrueFalseTotal
if $multiple or $objectlist 16 43 59
Condition100%3/3
$multiple or $objectlist
l!l&&r!l&&!r
15143
MC/DC100%2/2
$multiple or $objectlist
$multiple $objectlist
Truth table100%3/3
A or B
A= $multipleB= $objectlist
ABresult
1X1
011
000
108 43 ▶ return {} if $hash;
Branch: 1 branch
BranchTrueFalseTotal
if $hash 16 27 43
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
BranchTrueFalseTotal
if ref $default eq "ARRAY" 4 26 30
ref $_ eq 'HASH' ? : 2 2 4
115 26 ▶ return { $default->%* } if ref $default eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $default eq "HASH" 2 24 26
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
BranchTrueFalseTotal
$hash || $objectlist ? : 51 948 999
Condition100%3/3
$hash or $objectlist
l!l&&r!l&&!r
4110948
MC/DC100%2/2
$hash or $objectlist
$hash $objectlist
Truth table100%3/3
A or B
A= $hashB= $objectlist
ABresult
1X1
011
000
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
l!l&&r!l&&!r
62073
MC/DC100%2/2
$typehint // $type->label
$typehint $type->label
Truth table100%3/3
A // B
A= $typehintB= $type->label
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless defined $valid 1 95 96
135 95 ▶ return $valid->@* if ref $valid eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $valid eq "ARRAY" 88 7 95
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
BranchTrueFalseTotal
if ref $values ne "ARRAY" 1 6 7
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
BranchTrueFalseTotal
if ref $value eq "ARRAY" or ref $value eq "HASH" 4 223 227
Condition100%3/3
ref $value eq "ARRAY" or ref $value eq "HASH"
l!l&&r!l&&!r
22223
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"
ABresult
1X1
011
000
148  
149 223 my $problem = $type->check($value);
150 223 ▶ return ($problem, $value) if defined $problem;
Branch: 1 branch
BranchTrueFalseTotal
if defined $problem 9 214 223
151  
152 214 $value = $type->coerce($value);
153 214 ▶ if (defined $valid) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $valid) 81 133 214
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
BranchTrueFalseTotal
unless grep {$_ eq $value;} @allowed 8 72 80
156 }
157 205 ▶ return (sprintf("'%s' is not a valid value", $value), $value) if defined $lazyValid && !$lazyValid->($value);
Branch: 1 branch
BranchTrueFalseTotal
if defined $lazyValid and not &$lazyValid($value) 1 204 205
Condition66%2/3
defined $lazyValid and not &$lazyValid($value)
!ll&&!rl&&r
20401
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)
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if @unknown 1 208 209
167  
168 208 foreach my $source (@valueSources) {
169 354 ▶ my $given = $sources{$source->{key}} // {};
Condition100%2/2
$sources{$source->{"key"}} // {}
l!l
32034
MC/DC100%1/1
$sources{$source->{"key"}} // {}
$sources{$source->{"key"}}
Truth table100%2/2
A
A= $sources{$source->{"key"}}
Aresult
11
00
170 354 ▶ next if !exists $given->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $given->{$name} 237 117 354
171 117 return $self->preparedValue($self->validatedValue($given->{$name}, $source));
172 }
173  
174 91 ▶ return $self->preparedValue($self->copiedDefault) if $hasDefault;
Branch: 1 branch
BranchTrueFalseTotal
if $hasDefault 30 61 91
175 61 ▶ Getopt::Pad::Error->throw("missing required option '--%s'", $name) if $required;
Branch: 1 branch
BranchTrueFalseTotal
if $required 2 59 61
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
BranchTrueFalseTotal
if defined $problem 0 130 130
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
BranchTrueFalseTotal
if ref $value eq "ARRAY" 17 145 162
192 145 ▶ return map { $self->scalarsOf($_) } values $value->%* if ref $value eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "HASH" 15 130 145
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
BranchTrueFalseTotal
if $multiple 14 103 117
203 103 ▶ $value = $self->objectsFromPairs($value, $report) if $objectlist && $source->{givesWords};
Branch: 1 branch
BranchTrueFalseTotal
if $objectlist and $source->{"givesWords"} 7 96 103
Condition100%3/3
$objectlist and $source->{"givesWords"}
!ll&&!rl&&r
9337
MC/DC100%2/2
$objectlist and $source->{"givesWords"}
$objectlist $source->{"givesWords"}
Truth table100%3/3
A and B
A= $objectlistB= $source->{"givesWords"}
ABresult
0X0
100
111
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'}
!ll&&!rl&&r
473
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'}
ABresult
0X0
100
111
212 14 ▶ return $value->@* if $isConfigList;
Branch: 1 branch
BranchTrueFalseTotal
if $isConfigList 3 11 14
213  
214 11 ▶ my @scalars = ref $value eq 'ARRAY' ? $value->@* : ($value);
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 7 4 11
215 11 ▶ return @scalars if !$csv;
Branch: 1 branch
BranchTrueFalseTotal
unless $csv 4 7 11
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
BranchTrueFalseTotal
unless defined $word 1 7 8
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
BranchTrueFalseTotal
if not @items or grep {$_ eq "";} @items 2 5 7
Condition100%3/3
not @items or grep {$_ eq "";} @items
l!l&&r!l&&!r
115
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
() = $key =~ /\A(\d+)\.([\w-]+)\z/u or &$report(sprintf(q[invalid key '%s', expected INDEX.FIELD=VALUE], $key)) 8 2 10
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
BranchTrueFalseTotal
unless defined $objects[$index] 1 6 7
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
BranchTrueFalseTotal
if $multiple 2 205 207
250 205 ▶ return $self->shapedMapping($value, $report) if $hash;
Branch: 1 branch
BranchTrueFalseTotal
if $hash 16 189 205
251 189 ▶ return $self->shapedObjects($value, $report) if $objectlist;
Branch: 1 branch
BranchTrueFalseTotal
if $objectlist 12 177 189
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
BranchTrueFalseTotal
if ref $value ne "ARRAY" 1 1 2
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
BranchTrueFalseTotal
if ref $value ne "HASH" 5 25 30
262  
263 25 my %checked;
264 25 foreach my $key (sort keys $value->%*) {
265 31 ▶ $report->('empty key') if $key eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "" 2 29 31
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
BranchTrueFalseTotal
if ref $value ne "ARRAY" 2 10 12
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
BranchTrueFalseTotal
unless defined $value 3 227 230
283  
284 227 my ($problem, $coerced) = $self->checkValue($value);
285 226 ▶ $report->($problem) if defined $problem;
Branch: 1 branch
BranchTrueFalseTotal
if defined $problem 22 204 226
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__
« Pad/Parser.pm ↑ Summary Pad/Spec.pm »