Pad/Spec/Arg.pm

filter: Statementstmt 87.6% 57 / 65 Branchbran n/a Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 78.9% 15 / 19 Podpod 14.2% 2 / 14 totaltotal 76.7% 79 / 103 CC 2 SCAR 1.2
CC
2
Cov
88%
typeLabel
2.0
help
1.1
typehint
1.1
CRAP 1.1
« Pad/Type/Dir.pm ↑ Summary Pad/Result/Generator.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::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 class Getopt::Pad::Spec::Arg :strict(params) {
8 11 ▶ use Getopt::Pad::Util qw(camelize specError isValidName processedWith);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 11 our $VERSION = '0.06';
11  
12 11 field $raw :param;
13 # Where the arg sits in the spec, as the start of a spec error, e.g.
14 # "command 'image resize': ".
15 field $where :param = '';
16  
17 106 ▶ field $short :reader;
Subroutine short: called CC=1 SCAR=0.0
Pod undocumented
18 197 ▶ field $reader :reader;
Subroutine reader: called CC=1 SCAR=0.0
Pod undocumented
19 80 ▶ field $type :reader;
Subroutine type: called CC=1 SCAR=0.0
Pod undocumented
20 1 ▶ field $typeName :reader;
Subroutine typeName: called CC=1 SCAR=0.0
Pod undocumented
21 0 ▶ field $required :reader = 0;
Subroutine required: not called CC=1 SCAR=0.8
Pod undocumented
22 0 ▶ field $multiple :reader = 0;
Subroutine required: called CC=1 SCAR=0.6
Subroutine multiple: not called CC=1 SCAR=0.6
Pod undocumented
Pod undocumented
23 0 ▶ field $help :reader = '';
Subroutine multiple: called CC=1 SCAR=0.6
Subroutine help: not called CC=1 SCAR=0.9
Pod undocumented
Pod undocumented
24 0 ▶ field $typehint :reader;
Subroutine help: called CC=1 SCAR=1.2
Subroutine typehint: not called CC=1 SCAR=1.2
Pod undocumented
Pod undocumented
25 21 ▶ field $processValue :reader;
Subroutine processValue: called CC=1 SCAR=0.0
Pod undocumented
26  
27 ADJUST {
28 specError("%sarg: spec must be a hash reference", $where) if ref $raw ne 'HASH';
29  
30 my %spec = $raw->%*;
31 $short = delete $spec{short};
32 specError("%sarg: missing or invalid 'short' name", $where) if !isValidName($short);
33 $reader = camelize($short);
34 specError("%sarg '%s': reader '%s' collides with a built-in result method", $where, $short, $reader) if Getopt::Pad::Result->reservesReader($reader);
35  
36 ($type, $typeName) = Getopt::Pad::Type::takeFromSpec(\%spec, 'string', sprintf("%sarg '%s'", $where, $short));
37 specError("%sarg '%s': type '%s' cannot be used for a positional arg", $where, $short, $typeName) if !$type->takesValue;
38  
39 $required = delete $spec{required} ? 1 : 0;
40 $multiple = delete $spec{multiple} ? 1 : 0;
41 $help = delete $spec{help} // '';
42 $typehint = delete $spec{typehint};
43 $processValue = delete $spec{processValue};
44  
45 specError("%sarg '%s': unknown key(s): %s", $where, $short, join(', ', sort keys %spec)) if %spec;
46 specError("%sarg '%s': typehint must be a non-empty string", $where, $short) if defined $typehint && (ref $typehint || $typehint eq '');
47 specError("%sarg '%s': processValue must be a code reference", $where, $short) if defined $processValue && ref $processValue ne 'CODE';
48 }
49  
50 # The tag the help output renders after the help text: the spec's
51 # typehint, or what the type calls itself.
52 16 ▶ method typeLabel() {
Subroutine typeLabel: called CC=2 SCAR=6.9
Pod documented
53 16 ▶ return $typehint // $type->label;
Condition100%3/3
$typehint // $type->label
l!l&&r!l&&!r
682
MC/DC100%2/2
$typehint // $type->label
$typehint $type->label
Truth table100%3/3
A // B
A= $typehintB= $type->label
ABresult
1X1
011
000
54 11 }
55  
56 1 ▶ method processedValue($result, $value) {
Subroutine processedValue: called CC=1 SCAR=0.0
Pod documented
57 1 return processedWith($processValue, $result, $value);
58 11 }
59 }
60  
61 11 1;
62  
63 __END__
« Pad/Type/Dir.pm ↑ Summary Pad/Result/Generator.pm »