TUWF/Validate/Interop.pm

filter: Statementstmt 45.8% 82 / 179 Branchbran 52.0% 76 / 146 Conditioncond 25.2% 48 / 190 MC/DCmcdc 18.1% 19 / 105 Subroutinesub 70.0% 14 / 20 Podpod 0.0% 0 / 7 totaltotal 36.9% 239 / 647 CC 150 SCAR 61.1
CC
150
Cov
40%
elm_decoder
1056.0
elm_encoder
812.0
elm_type
702.0
CRAP 449.2
↑ Summary TUWF.pm »
1 package TUWF::Validate::Interop;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use TUWF::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our @EXPORT_OK = ('analyze');
10 1 our $VERSION = '1.6';
11  
12  
13 # Analyzed ("flattened") object:
14 # { type => scalar | bool | num | int | array | hash | any
15 # , min, max, minlength, maxlength, required, regexes
16 # , keys, values, unknown
17 # }
18  
19 144 ▶sub _merge_type {
Subroutine _merge_type: called CC=10 SCAR=23.3
20 144 my($c, $o) = @_;
21 144 ▶ my $n = $c->{name}||'';
Condition100%2/2
$c->{'name'} || ''
l!l
6777
MC/DC100%1/1
$c->{'name'} || ''
$c->{'name'}
Truth table100%2/2
A
A= $c->{'name'}
Aresult
11
00
22  
23 144 ▶ return if $o->{type} eq 'int' || $o->{type} eq 'bool';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "int" or $o->{"type"} eq "bool" 0 144 144
Condition33%1/3
$o->{"type"} eq "int" or $o->{"type"} eq "bool"
l!l&&r!l&&!r
00144
MC/DC0%0/2
$o->{"type"} eq "int" or $o->{"type"} eq "bool"
$o->{"type"} eq "int" $o->{"type"} eq "bool"
Truth table33%1/3
A or B
A= $o->{"type"} eq "int"B= $o->{"type"} eq "bool"
ABresult
1X1
011
000
24 144 ▶ $o->{type} = 'int' if $n eq 'int' || $n eq 'uint';
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "int" or $n eq "uint" 12 132 144
Condition100%3/3
$n eq "int" or $n eq "uint"
l!l&&r!l&&!r
84132
MC/DC100%2/2
$n eq "int" or $n eq "uint"
$n eq "int" $n eq "uint"
Truth table100%3/3
A or B
A= $n eq "int"B= $n eq "uint"
ABresult
1X1
011
000
25 144 ▶ $o->{type} = 'bool' if $n eq 'anybool' || $n eq 'undefbool' || $n eq 'jsonbool';
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "anybool" or $n eq "undefbool" or $n eq "jsonbool" 12 132 144
Condition83%5/6
$n eq "anybool" or $n eq "undefbool" or $n eq "jsonbool"
l!l&&r!l&&!r
84132
$n eq "anybool" or $n eq "undefbool"
l!l&&r!l&&!r
80136
MC/DC66%2/3
$n eq "anybool" or $n eq "undefbool" or $n eq "jsonbool"
$n eq "anybool" $n eq "undefbool" $n eq "jsonbool"
Truth table75%3/4
A or B or C
A= $n eq "anybool"B= $n eq "undefbool"C= $n eq "jsonbool"
ABCresult
1XX1
01X1
0011
0000
26 144 ▶ $o->{type} = 'num' if $n eq 'num';
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "num" 19 125 144
27 }
28  
29  
30 144 ▶sub _merge {
Subroutine _merge: called CC=23 SCAR=32.5
31 144 my($c, $o) = @_;
32  
33 144 _merge_type $c, $o;
34  
35 144 ▶ $o->{required} = 1 if ($c->{name}||'') eq 'anybool';
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"name"} || "") eq "anybool" 8 136 144
Condition100%2/2
$c->{'name'} || ''
l!l
6777
MC/DC100%1/1
$c->{'name'} || ''
$c->{'name'}
Truth table100%2/2
A
A= $c->{'name'}
Aresult
11
00
36  
37 144 ▶ $o->{values} = _merge_toplevel($c->{schema}{values}, $o->{values}||{}) if $c->{schema}{values};
Branch: 1 branch
BranchTrueFalseTotal
if $c->{"schema"}{"values"} 2 142 144
Condition50%1/2
$o->{'values'} || {}
l!l
02
MC/DC0%0/1
$o->{'values'} || {}
$o->{'values'}
Truth table50%1/2
A
A= $o->{'values'}
Aresult
11
00
38  
39 144 ▶ if($c->{schema}{keys}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"schema"}{"keys"}) 8 136 144
40 8 ▶ $o->{keys} ||= {};
Condition50%1/2
$o->{"keys"} ||= {}
l!l
08
MC/DC0%0/1
$o->{"keys"} ||= {}
$o->{"keys"}
Truth table50%1/2
A
A= $o->{"keys"}
Aresult
11
00
41 8 ▶ $o->{keys}{$_} = _merge_toplevel($c->{schema}{keys}{$_}, $o->{keys}{$_}||{}) for keys %{$c->{schema}{keys}};
Condition50%1/2
$o->{'keys'}{$_} || {}
l!l
010
MC/DC0%0/1
$o->{'keys'}{$_} || {}
$o->{'keys'}{$_}
Truth table50%1/2
A
A= $o->{'keys'}{$_}
Aresult
11
00
42 }
43  
44 144 ▶ $o->{minlength} = $c->{schema}{_analyze_minlength} if defined $c->{schema}{_analyze_minlength} && (!defined $o->{minlength} || $o->{minlength} < $c->{schema}{_analyze_minlength});
Branch: 1 branch
BranchTrueFalseTotal
if defined $c->{"schema"}{"_analyze_minlength"} and !defined($o->{"minlength"}) || $o->{"minlength"} < $c->{"schema"}{"_analyze_minlength"} 3 141 144
Condition50%3/6
defined $c->{"schema"}{"_analyze_minlength"} and !defined($o->{"minlength"}) || $o->{"minlength"} < $c->{"schema"}{"_analyze_minlength"}
!ll&&!rl&&r
14103
not defined $o->{"minlength"} or $o->{"minlength"} < $c->{"schema"}{"_analyze_minlength"}
l!l&&r!l&&!r
300
MC/DC33%1/3
defined $c->{"schema"}{"_analyze_minlength"} and !defined($o->{"minlength"}) || $o->{"minlength"} < $c->{"schema"}{"_analyze_minlength"}
defined $c->{"schema"}{"_analyze_minlength"} not defined $o->{"minlength"} $o->{"minlength"} < $c->{"schema"}{"_analyze_minlength"}
Truth table50%2/4
A and not(B) or C
A= defined $c->{"schema"}{"_analyze_minlength"}B= not defined $o->{"minlength"}C= $o->{"minlength"} < $c->{"schema"}{"_analyze_minlength"}
ABCresult
0XX0
1000
11X1
1011
45 144 ▶ $o->{maxlength} = $c->{schema}{_analyze_maxlength} if defined $c->{schema}{_analyze_maxlength} && (!defined $o->{maxlength} || $o->{maxlength} > $c->{schema}{_analyze_maxlength});
Branch: 1 branch
BranchTrueFalseTotal
if defined $c->{"schema"}{"_analyze_maxlength"} and !defined($o->{"maxlength"}) || $o->{"maxlength"} > $c->{"schema"}{"_analyze_maxlength"} 4 140 144
Condition50%3/6
defined $c->{"schema"}{"_analyze_maxlength"} and !defined($o->{"maxlength"}) || $o->{"maxlength"} > $c->{"schema"}{"_analyze_maxlength"}
!ll&&!rl&&r
14004
not defined $o->{"maxlength"} or $o->{"maxlength"} > $c->{"schema"}{"_analyze_maxlength"}
l!l&&r!l&&!r
400
MC/DC33%1/3
defined $c->{"schema"}{"_analyze_maxlength"} and !defined($o->{"maxlength"}) || $o->{"maxlength"} > $c->{"schema"}{"_analyze_maxlength"}
defined $c->{"schema"}{"_analyze_maxlength"} not defined $o->{"maxlength"} $o->{"maxlength"} > $c->{"schema"}{"_analyze_maxlength"}
Truth table50%2/4
A and not(B) or C
A= defined $c->{"schema"}{"_analyze_maxlength"}B= not defined $o->{"maxlength"}C= $o->{"maxlength"} > $c->{"schema"}{"_analyze_maxlength"}
ABCresult
0XX0
1000
11X1
1011
46 144 ▶ $o->{min} = $c->{schema}{_analyze_min} if defined $c->{schema}{_analyze_min} && (!defined $o->{min} || $o->{min} < $c->{schema}{_analyze_min} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $c->{"schema"}{"_analyze_min"} and !defined($o->{"min"}) || $o->{"min"} < $c->{"schema"}{"_analyze_min"} 6 138 144
Condition100%6/6
defined $c->{"schema"}{"_analyze_min"} and !defined($o->{"min"}) || $o->{"min"} < $c->{"schema"}{"_analyze_min"}
!ll&&!rl&&r
13716
not defined $o->{"min"} or $o->{"min"} < $c->{"schema"}{"_analyze_min"}
l!l&&r!l&&!r
511
MC/DC100%3/3
defined $c->{"schema"}{"_analyze_min"} and !defined($o->{"min"}) || $o->{"min"} < $c->{"schema"}{"_analyze_min"}
defined $c->{"schema"}{"_analyze_min"} not defined $o->{"min"} $o->{"min"} < $c->{"schema"}{"_analyze_min"}
Truth table100%4/4
A and not(B) or C
A= defined $c->{"schema"}{"_analyze_min"}B= not defined $o->{"min"}C= $o->{"min"} < $c->{"schema"}{"_analyze_min"}
ABCresult
0XX0
1000
11X1
1011
47 144 ▶ $o->{max} = $c->{schema}{_analyze_max} if defined $c->{schema}{_analyze_max} && (!defined $o->{max} || $o->{max} > $c->{schema}{_analyze_max} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $c->{"schema"}{"_analyze_max"} and !defined($o->{"max"}) || $o->{"max"} > $c->{"schema"}{"_analyze_max"} 6 138 144
Condition66%4/6
defined $c->{"schema"}{"_analyze_max"} and !defined($o->{"max"}) || $o->{"max"} > $c->{"schema"}{"_analyze_max"}
!ll&&!rl&&r
13806
not defined $o->{"max"} or $o->{"max"} > $c->{"schema"}{"_analyze_max"}
l!l&&r!l&&!r
510
MC/DC33%1/3
defined $c->{"schema"}{"_analyze_max"} and !defined($o->{"max"}) || $o->{"max"} > $c->{"schema"}{"_analyze_max"}
defined $c->{"schema"}{"_analyze_max"} not defined $o->{"max"} $o->{"max"} > $c->{"schema"}{"_analyze_max"}
Truth table75%3/4
A and not(B) or C
A= defined $c->{"schema"}{"_analyze_max"}B= not defined $o->{"max"}C= $o->{"max"} > $c->{"schema"}{"_analyze_max"}
ABCresult
0XX0
1000
11X1
1011
48 144 ▶ push @{$o->{regexes}}, $c->{schema}{_analyze_regex} if defined $c->{schema}{_analyze_regex};
Branch: 1 branch
BranchTrueFalseTotal
if defined $c->{"schema"}{"_analyze_regex"} 33 111 144
49  
50 144 _merge($_, $o) for @{$c->{validations}};
51 }
52  
53  
54 77 ▶sub _merge_toplevel {
Subroutine _merge_toplevel: called CC=6 SCAR=19.4
55 77 my($c, $o) = @_;
56 77 ▶ $o->{required} ||= !exists $c->{schema}{default};
Condition66%2/3
$o->{"required"} ||= !exists $c->{"schema"}{"default"}
l!l&&r!l&&!r
05423
MC/DC50%1/2
$o->{"required"} ||= !exists $c->{"schema"}{"default"}
$o->{"required"} !exists $c->{"schema"}{"default"}
Truth table66%2/3
A ||= not(B)
A= $o->{"required"}B= !exists $c->{"schema"}{"default"}
ABresult
1X1
011
000
57 77 ▶ $o->{unknown} ||= $c->{schema}{unknown};
Condition33%1/3
$o->{"unknown"} ||= $c->{"schema"}{"unknown"}
l!l&&r!l&&!r
0770
MC/DC0%0/2
$o->{"unknown"} ||= $c->{"schema"}{"unknown"}
$o->{"unknown"} $c->{"schema"}{"unknown"}
Truth table33%1/3
A ||= B
A= $o->{"unknown"}B= $c->{"schema"}{"unknown"}
ABresult
1X1
011
000
58 77 ▶ $o->{default} = $c->{schema}{default} if exists $c->{schema}{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $c->{"schema"}{"default"} 23 54 77
59 77 ▶ $o->{type} = $c->{schema}{type} if !$o->{type} || $o->{type} eq 'any';
Branch: 1 branch
BranchTrueFalseTotal
if not $o->{"type"} or $o->{"type"} eq "any" 77 0 77
Condition33%1/3
not $o->{"type"} or $o->{"type"} eq "any"
l!l&&r!l&&!r
7700
MC/DC0%0/2
not $o->{"type"} or $o->{"type"} eq "any"
not $o->{"type"} $o->{"type"} eq "any"
Truth table33%1/3
not(A) or B
A= not $o->{"type"}B= $o->{"type"} eq "any"
ABresult
1X1
011
000
60  
61 77 _merge $c, $o;
62 77 bless $o, __PACKAGE__;
63 }
64  
65  
66 65 ▶sub analyze {
Subroutine analyze: called CC=2 SCAR=7.6
Pod undocumented
67 65 my $c = shift;
68 65 ▶ $c->{analysis} ||= _merge_toplevel $c, {};
Condition33%1/3
$c->{"analysis"} ||= _merge_toplevel($c, scalar {})
l!l&&r!l&&!r
0650
MC/DC0%0/2
$c->{"analysis"} ||= _merge_toplevel($c, scalar {})
$c->{"analysis"} _merge_toplevel($c, scalar {})
Truth table33%1/3
A ||= B
A= $c->{"analysis"}B= _merge_toplevel($c, scalar {})
ABresult
1X1
011
000
69 $c->{analysis}
70 65 }
71  
72  
73 # Assumes that $obj already has the required format/structure, odd things may
74 # happen if this is not the case.
75 # unknown => remove|reject|pass
76 35 ▶sub coerce_for_json {
Subroutine coerce_for_json: called CC=15 SCAR=27.1
Pod undocumented
77 35 my($o, $obj, %opt) = @_;
78 35 ▶ $opt{unknown} ||= $o->{unknown};
Condition66%2/3
$opt{"unknown"} ||= $o->{"unknown"}
l!l&&r!l&&!r
11240
MC/DC0%0/2
$opt{"unknown"} ||= $o->{"unknown"}
$opt{"unknown"} $o->{"unknown"}
Truth table66%2/3
A ||= B
A= $opt{"unknown"}B= $o->{"unknown"}
ABresult
1X1
011
000
79 35 ▶ return undef if !defined $obj;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $obj 6 29 35
80 29 ▶ return $obj+0 if $o->{type} eq 'num';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "num" 2 27 29
81 27 ▶ return int $obj if $o->{type} eq 'int';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "int" 5 22 27
82 22 ▶ return $obj ? \1 : \0 if $o->{type} eq 'bool';
Branch: 2 branches
BranchTrueFalseTotal
if $o->{"type"} eq "bool" 8 14 22
$obj ? : 7 1 8
83 14 ▶ return "$obj" if $o->{type} eq 'scalar';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "scalar" 1 13 14
84 13 ▶ return [map $o->{values}->coerce_for_json($_, %opt), @$obj] if $o->{type} eq 'array' && $o->{values};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "array" and $o->{"values"} 1 12 13
Condition100%3/3
$o->{"type"} eq "array" and $o->{"values"}
!ll&&!rl&&r
1021
MC/DC100%2/2
$o->{"type"} eq "array" and $o->{"values"}
$o->{"type"} eq "array" $o->{"values"}
Truth table100%3/3
A and B
A= $o->{"type"} eq "array"B= $o->{"values"}
ABresult
0X0
100
111
85 return {map {
86 $o->{keys}{$_} ? ($_, $o->{keys}{$_}->coerce_for_json($obj->{$_}, %opt)) :
87 $opt{unknown} eq 'pass' ? ($_, $obj->{$_}) :
88 10 ▶ $opt{unknown} eq 'remove' ? ()
Branch: 3 branches
BranchTrueFalseTotal
$o->{'keys'}{$_} ? : 6 4 10
$opt{'unknown'} eq 'pass' ? : 2 2 4
$opt{'unknown'} eq 'remove' ? : 1 1 2
89 : croak "Unknown key '$_' in hash in coerce_for_json()"
90 12 ▶ } keys %$obj} if $o->{type} eq 'hash' && $o->{keys};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "hash" and $o->{"keys"} 6 6 12
Condition100%3/3
$o->{"type"} eq "hash" and $o->{"keys"}
!ll&&!rl&&r
426
MC/DC100%2/2
$o->{"type"} eq "hash" and $o->{"keys"}
$o->{"type"} eq "hash" $o->{"keys"}
Truth table100%3/3
A and B
A= $o->{"type"} eq "hash"B= $o->{"keys"}
ABresult
0X0
100
111
91 6 $obj
92 }
93  
94  
95 # Returns a Cpanel::JSON::XS::Type; Behavior is subtly different compared to coerce_for_json():
96 # - Unknown keys in hashes will cause Cpanel::JSON::XS to die()
97 # - Numbers are always formatted as floats (e.g. 10.0) even if it's a round nunmber
98 26 ▶sub json_type {
Subroutine json_type: called CC=10 SCAR=23.0
Pod undocumented
99 26 my $o = shift;
100 26 require Cpanel::JSON::XS::Type;
101 26 ▶ return Cpanel::JSON::XS::Type::JSON_TYPE_FLOAT_OR_NULL() if $o->{type} eq 'num';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "num" 3 23 26
102 23 ▶ return Cpanel::JSON::XS::Type::JSON_TYPE_INT_OR_NULL() if $o->{type} eq 'int';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "int" 4 19 23
103 19 ▶ return Cpanel::JSON::XS::Type::JSON_TYPE_BOOL_OR_NULL() if $o->{type} eq 'bool';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "bool" 5 14 19
104 14 ▶ return Cpanel::JSON::XS::Type::JSON_TYPE_STRING_OR_NULL() if $o->{type} eq 'scalar';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "scalar" 3 11 14
105 11 ▶ return Cpanel::JSON::XS::Type::json_type_null_or_anyof(Cpanel::JSON::XS::Type::json_type_arrayof($o->{values} ? $o->{values}->json_type : undef)) if $o->{type} eq 'array';
Branch: 2 branches
BranchTrueFalseTotal
if $o->{"type"} eq "array" 4 7 11
$o->{'values'} ? : 1 3 4
106 7 ▶ return Cpanel::JSON::XS::Type::json_type_null_or_anyof({ map +($_, $o->{keys}{$_}->json_type), keys %{$o->{keys}} }) if $o->{type} eq 'hash' && $o->{keys};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "hash" and $o->{"keys"} 2 5 7
Condition100%3/3
$o->{"type"} eq "hash" and $o->{"keys"}
!ll&&!rl&&r
232
MC/DC100%2/2
$o->{"type"} eq "hash" and $o->{"keys"}
$o->{"type"} eq "hash" $o->{"keys"}
Truth table100%3/3
A and B
A= $o->{"type"} eq "hash"B= $o->{"keys"}
ABresult
0X0
100
111
107 5 ▶ return Cpanel::JSON::XS::Type::json_type_null_or_anyof(Cpanel::JSON::XS::Type::json_type_hashof(undef)) if $o->{type} eq 'hash';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "hash" 3 2 5
108 undef
109 2 }
110  
111  
112 # Attempts to convert a stringified Perl regex into something that is compatible with JS.
113 # - @ should not be escaped
114 # - (?^: is a perl alias for (?d-imnsx:
115 # - Javascript doesn't officially support embedded modifiers in the first place, so these are removed
116 # Regexes compiled with any of /imsx will not work properly.
117 17 ▶sub _re_compat {
Subroutine _re_compat: called CC=1 SCAR=0.0
118 17 local $_ = $_[0];
119 17 s/\\@/@/g;
120 17 s{\(\?\^?[alupimnsx]*(?:-[imnsx]+)?(?=[:\)])}{(?}g;
121 17 $_
122 }
123  
124  
125 9 ▶sub _join_regexes {
Subroutine _join_regexes: called CC=1 SCAR=0.0
126 9 my %r = map +($_,1), @{$_[0]};
127 9 my @r = sort keys %r;
128 9 _re_compat join('', map "(?=$_)", @r[0..$#r-1]).$r[$#r]
129 }
130  
131  
132 # Returns a few HTML5 validation properties. Doesn't include the 'type'
133 17 ▶sub html5_validation {
Subroutine html5_validation: called CC=7 SCAR=19.5
Pod undocumented
134 17 my $o = shift;
135 +(
136 $o->{required} ? (required => 'required') : (),
137 defined $o->{minlength} ? (minlength => $o->{minlength}) : (),
138 defined $o->{maxlength} ? (maxlength => $o->{maxlength}) : (),
139 defined $o->{min} ? (min => $o->{min} ) : (),
140 defined $o->{max} ? (max => $o->{max} ) : (),
141 17 ▶ $o->{regexes} ? (pattern => _join_regexes $o->{regexes}) : (),
Branch: 6 branches
BranchTrueFalseTotal
$o->{'required'} ? : 14 3 17
defined $o->{'minlength'} ? : 3 14 17
defined $o->{'maxlength'} ? : 4 13 17
defined $o->{'min'} ? : 5 12 17
defined $o->{'max'} ? : 5 12 17
$o->{'regexes'} ? : 9 8 17
142 );
143 }
144  
145  
146  
147 # The elm_ are experimental, unstable, not very well-tested and for Elm 0.19
148  
149 # Options: required any array values keys indent level
150 0 ▶sub elm_type {
Subroutine elm_type: not called CC=26 SCAR=65.5
Pod undocumented
151 0 my($o, %opt) = @_;
152 0 ▶ my $par = delete $opt{_need_parens} ? sub { "($_[0])" } : sub { $_[0] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
delete $opt{'_need_parens'} ? : 0 0 0
153 0 ▶ return $par->('Maybe ' . $o->elm_type(%opt, required => 1, _need_parens => 1)) if (ref $o->{default} eq 'CODE' || (!$o->{required} && !defined $o->{default})) && !$opt{required};
Branch: 1 branch
BranchTrueFalseTotal
if ref $o->{"default"} eq "CODE" || !($o->{"required"} || defined $o->{"default"}) and not $opt{"required"} 0 0 0
Condition0%0/9
ref $o->{"default"} eq "CODE" || !($o->{"required"} || defined $o->{"default"}) and not $opt{"required"}
!ll&&!rl&&r
000
ref $o->{"default"} eq "CODE" or not $o->{"required"} || defined $o->{"default"}
l!l&&r!l&&!r
000
$o->{'required'} || defined $o->{'default'}
l!l&&r!l&&!r
000
MC/DC0%0/4
ref $o->{"default"} eq "CODE" || !($o->{"required"} || defined $o->{"default"}) and not $opt{"required"}
ref $o->{"default"} eq "CODE" $o->{'required'} defined $o->{'default'} not $opt{"required"}
Truth table0%0/6
A or not(B || C) and not(D)
A= ref $o->{"default"} eq "CODE"B= $o->{'required'}C= defined $o->{'default'}D= not $opt{"required"}
ABCDresult
01XX0
001X0
1XX00
00000
1XX11
00011
154 0 delete $opt{required};
155 0 ▶ return 'String' if $o->{type} eq 'scalar';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "scalar" 0 0 0
156 0 ▶ return 'Bool' if $o->{type} eq 'bool';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "bool" 0 0 0
157 0 ▶ return 'Float' if $o->{type} eq 'num';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "num" 0 0 0
158 0 ▶ return 'Int' if $o->{type} eq 'int';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "int" 0 0 0
159 0 ▶ return $opt{any} if $o->{type} eq 'any' && $opt{any};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "any" and $opt{"any"} 0 0 0
Condition0%0/3
$o->{"type"} eq "any" and $opt{"any"}
!ll&&!rl&&r
000
MC/DC0%0/2
$o->{"type"} eq "any" and $opt{"any"}
$o->{"type"} eq "any" $opt{"any"}
Truth table0%0/3
A and B
A= $o->{"type"} eq "any"B= $opt{"any"}
ABresult
0X0
100
111
160 return $par->( ($opt{array} || 'List') . ' ' . ($opt{values} || $o->{values}->elm_type(%opt, _need_parens => 1)) )
161 0 ▶ if $o->{type} eq 'array' && ($opt{values} || $o->{values});
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "array" and $opt{"values"} || $o->{"values"} 0 0 0
Condition0%0/11
$o->{"type"} eq "array" and $opt{"values"} || $o->{"values"}
!ll&&!rl&&r
000
$opt{"values"} or $o->{"values"}
l!l&&r!l&&!r
000
$opt{'array'} || 'List'
l!l
00
$opt{'values'} || $o->{'values'}->elm_type(%opt, '_need_parens', 1)
l!l&&r!l&&!r
000
MC/DC0%0/3
$o->{"type"} eq "array" and $opt{"values"} || $o->{"values"}
$o->{"type"} eq "array" $opt{"values"} $o->{"values"}
MC/DC0%0/1
$opt{'array'} || 'List'
$opt{'array'}
MC/DC0%0/2
$opt{'values'} || $o->{'values'}->elm_type(%opt, '_need_parens', 1)
$opt{'values'} $o->{'values'}->elm_type(%opt, '_need_parens', 1)
Truth table0%0/4
A and B or C
A= $o->{"type"} eq "array"B= $opt{"values"}C= $o->{"values"}
ABCresult
0XX0
1000
11X1
1011
Truth table0%0/2
A
A= $opt{'array'}
Aresult
11
00
Truth table0%0/3
A || B
A= $opt{'values'}B= $o->{'values'}->elm_type(%opt, '_need_parens', 1)
ABresult
1X1
011
000
162  
163 0 ▶ if($o->{type} eq 'hash' && ($o->{keys} || $opt{keys})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"type"} eq "hash" and $o->{"keys"} || $opt{"keys"}) 0 0 0
Condition0%0/6
$o->{"type"} eq "hash" and $o->{"keys"} || $opt{"keys"}
!ll&&!rl&&r
000
$o->{"keys"} or $opt{"keys"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$o->{"type"} eq "hash" and $o->{"keys"} || $opt{"keys"}
$o->{"type"} eq "hash" $o->{"keys"} $opt{"keys"}
Truth table0%0/4
A and B or C
A= $o->{"type"} eq "hash"B= $o->{"keys"}C= $opt{"keys"}
ABCresult
0XX0
1000
11X1
1011
164 0 ▶ $opt{indent} //= 2;
Condition0%0/2
$opt{"indent"} //= 2
l!l
00
MC/DC0%0/1
$opt{"indent"} //= 2
$opt{"indent"}
Truth table0%0/2
A
A= $opt{"indent"}
Aresult
11
00
165 0 ▶ $opt{level} //= 1;
Condition0%0/2
$opt{"level"} //= 1
l!l
00
MC/DC0%0/1
$opt{"level"} //= 1
$opt{"level"}
Truth table0%0/2
A
A= $opt{"level"}
Aresult
11
00
166 0 my $len = 0;
167 0 ▶ $len = length $_ > $len ? length $_ : $len for keys %{$o->{keys}};
Branch: 1 branch
BranchTrueFalseTotal
length $_ > $len ? : 0 0 0
168  
169 my $r = "\n{ " . join("\n, ", map {
170 0 ▶ sprintf "%-*s : %s", $len, $_, $opt{keys}{$_} || $o->{keys}{$_}->elm_type(%opt, level => $opt{level}+1);
Condition0%0/3
$opt{'keys'}{$_} || $o->{'keys'}{$_}->elm_type(%opt, 'level', $opt{'level'} + 1)
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt{'keys'}{$_} || $o->{'keys'}{$_}->elm_type(%opt, 'level', $opt{'level'} + 1)
$opt{'keys'}{$_} $o->{'keys'}{$_}->elm_type(%opt, 'level', $opt{'level'} + 1)
Truth table0%0/3
A || B
A= $opt{'keys'}{$_}B= $o->{'keys'}{$_}->elm_type(%opt, 'level', $opt{'level'} + 1)
ABresult
1X1
011
000
171 0 } sort keys %{$o->{keys}}) . "\n}";;
172  
173 0 ▶ $r =~ s/\n/$opt{indent} ? "\n" . (' 'x($opt{indent}*$opt{level})) : ''/eg;
Branch: 1 branch
BranchTrueFalseTotal
$opt{'indent'} ? : 0 0 0
174 0 return $r;
175 }
176  
177 0 croak "Unknown type '$o->{type}' or missing option";
178 }
179  
180  
181 # Elm JSON encoder for values of elm_type()
182 # options: elm_type() options + json_encode var_prefix
183 0 ▶sub elm_encoder {
Subroutine elm_encoder: not called CC=28 SCAR=67.0
Pod undocumented
184 0 my($o, %opt) = @_;
185 0 ▶ $opt{json_encode} //= '';
Condition0%0/2
$opt{"json_encode"} //= ""
l!l
00
MC/DC0%0/1
$opt{"json_encode"} //= ""
$opt{"json_encode"}
Truth table0%0/2
A
A= $opt{"json_encode"}
Aresult
11
00
186 0 ▶ $opt{var_prefix} //= 'e';
Condition0%0/2
$opt{"var_prefix"} //= "e"
l!l
00
MC/DC0%0/1
$opt{"var_prefix"} //= "e"
$opt{"var_prefix"}
Truth table0%0/2
A
A= $opt{"var_prefix"}
Aresult
11
00
187 0 ▶ $opt{var_num} //= 0;
Condition0%0/2
$opt{"var_num"} //= 0
l!l
00
MC/DC0%0/1
$opt{"var_num"} //= 0
$opt{"var_num"}
Truth table0%0/2
A
A= $opt{"var_num"}
Aresult
11
00
188  
189 return sprintf '(Maybe.withDefault %snull << Maybe.map %s)',
190 $opt{json_encode}, $opt{values} || $o->elm_encoder(%opt, required => 1)
191 0 ▶ if (ref $o->{default} eq 'CODE' || (!$o->{required} && !defined $o->{default})) && !$opt{required};
Branch: 1 branch
BranchTrueFalseTotal
if ref $o->{"default"} eq "CODE" || !($o->{"required"} || defined $o->{"default"}) and not $opt{"required"} 0 0 0
Condition0%0/12
ref $o->{"default"} eq "CODE" || !($o->{"required"} || defined $o->{"default"}) and not $opt{"required"}
!ll&&!rl&&r
000
ref $o->{"default"} eq "CODE" or not $o->{"required"} || defined $o->{"default"}
l!l&&r!l&&!r
000
$o->{'required'} || defined $o->{'default'}
l!l&&r!l&&!r
000
$opt{'values'} || $o->elm_encoder(%opt, 'required', 1)
l!l&&r!l&&!r
000
MC/DC0%0/4
ref $o->{"default"} eq "CODE" || !($o->{"required"} || defined $o->{"default"}) and not $opt{"required"}
ref $o->{"default"} eq "CODE" $o->{'required'} defined $o->{'default'} not $opt{"required"}
MC/DC0%0/2
$opt{'values'} || $o->elm_encoder(%opt, 'required', 1)
$opt{'values'} $o->elm_encoder(%opt, 'required', 1)
Truth table0%0/6
A or not(B || C) and not(D)
A= ref $o->{"default"} eq "CODE"B= $o->{'required'}C= defined $o->{'default'}D= not $opt{"required"}
ABCDresult
01XX0
001X0
1XX00
00000
1XX11
00011
Truth table0%0/3
A || B
A= $opt{'values'}B= $o->elm_encoder(%opt, 'required', 1)
ABresult
1X1
011
000
192  
193 0 delete $opt{required};
194 0 ▶ return "$opt{json_encode}string" if $o->{type} eq 'scalar';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "scalar" 0 0 0
195 0 ▶ return "$opt{json_encode}bool" if $o->{type} eq 'bool';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "bool" 0 0 0
196 0 ▶ return "$opt{json_encode}float" if $o->{type} eq 'num';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "num" 0 0 0
197 0 ▶ return "$opt{json_encode}int" if $o->{type} eq 'int';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "int" 0 0 0
198 0 ▶ return $opt{any} if $o->{type} eq 'any' && $opt{any};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "any" and $opt{"any"} 0 0 0
Condition0%0/3
$o->{"type"} eq "any" and $opt{"any"}
!ll&&!rl&&r
000
MC/DC0%0/2
$o->{"type"} eq "any" and $opt{"any"}
$o->{"type"} eq "any" $opt{"any"}
Truth table0%0/3
A and B
A= $o->{"type"} eq "any"B= $opt{"any"}
ABresult
0X0
100
111
199 return sprintf '(%slist %s)', $opt{json_encode}, $opt{values} || $o->{values}->elm_encoder(%opt)
200 0 ▶ if $o->{type} eq 'array' && ($opt{values} || $o->{values});
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "array" and $opt{"values"} || $o->{"values"} 0 0 0
Condition0%0/9
$o->{"type"} eq "array" and $opt{"values"} || $o->{"values"}
!ll&&!rl&&r
000
$opt{"values"} or $o->{"values"}
l!l&&r!l&&!r
000
$opt{'values'} || $o->{'values'}->elm_encoder(%opt)
l!l&&r!l&&!r
000
MC/DC0%0/3
$o->{"type"} eq "array" and $opt{"values"} || $o->{"values"}
$o->{"type"} eq "array" $opt{"values"} $o->{"values"}
MC/DC0%0/2
$opt{'values'} || $o->{'values'}->elm_encoder(%opt)
$opt{'values'} $o->{'values'}->elm_encoder(%opt)
Truth table0%0/4
A and B or C
A= $o->{"type"} eq "array"B= $opt{"values"}C= $o->{"values"}
ABCresult
0XX0
1000
11X1
1011
Truth table0%0/3
A || B
A= $opt{'values'}B= $o->{'values'}->elm_encoder(%opt)
ABresult
1X1
011
000
201  
202 0 ▶ if($o->{type} eq 'hash' && ($o->{keys} || $opt{keys})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"type"} eq "hash" and $o->{"keys"} || $opt{"keys"}) 0 0 0
Condition0%0/6
$o->{"type"} eq "hash" and $o->{"keys"} || $opt{"keys"}
!ll&&!rl&&r
000
$o->{"keys"} or $opt{"keys"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$o->{"type"} eq "hash" and $o->{"keys"} || $opt{"keys"}
$o->{"type"} eq "hash" $o->{"keys"} $opt{"keys"}
Truth table0%0/4
A and B or C
A= $o->{"type"} eq "hash"B= $o->{"keys"}C= $opt{"keys"}
ABCresult
0XX0
1000
11X1
1011
203 0 ▶ $opt{indent} //= 2;
Condition0%0/2
$opt{"indent"} //= 2
l!l
00
MC/DC0%0/1
$opt{"indent"} //= 2
$opt{"indent"}
Truth table0%0/2
A
A= $opt{"indent"}
Aresult
11
00
204 0 ▶ $opt{level} //= 1;
Condition0%0/2
$opt{"level"} //= 1
l!l
00
MC/DC0%0/1
$opt{"level"} //= 1
$opt{"level"}
Truth table0%0/2
A
A= $opt{"level"}
Aresult
11
00
205 0 my $len = 0;
206 0 ▶ $len = length $_ > $len ? length $_ : $len for keys %{$o->{keys}};
Branch: 1 branch
BranchTrueFalseTotal
length $_ > $len ? : 0 0 0
207  
208 0 my $var = $opt{var_prefix}.$opt{var_num};
209 my $r = sprintf "(\\%s -> %sobject\n[ %s\n])", $var, $opt{json_encode}, join "\n, ", map {
210 sprintf '("%s",%s %s %s.%1$s)', $_,
211 ' 'x($len-(length $_)),
212 0 ▶ $opt{keys}{$_} || $o->{keys}{$_}->elm_encoder(%opt, level => $opt{level}+1, var_num => $opt{var_num}+1),
Condition0%0/3
$opt{'keys'}{$_} || $o->{'keys'}{$_}->elm_encoder(%opt, 'level', $opt{'level'} + 1, 'var_num', $opt{'var_num'} + 1)
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt{'keys'}{$_} || $o->{'keys'}{$_}->elm_encoder(%opt, 'level', $opt{'level'} + 1, 'var_num', $opt{'var_num'} + 1)
$opt{'keys'}{$_} $o->{'keys'}{$_}->elm_encoder(%opt, 'level', $opt{'level'} + 1, 'var_num', $opt{'var_num'} + 1)
Truth table0%0/3
A || B
A= $opt{'keys'}{$_}B= $o->{'keys'}{$_}->elm_encoder(%opt, 'level', $opt{'level'} + 1, 'var_num', $opt{'var_num'} + 1)
ABresult
1X1
011
000
213 $var;
214 0 } sort keys %{$o->{keys}};
215  
216 0 ▶ $r =~ s/\n/$opt{indent} ? "\n" . (' 'x($opt{indent}*$opt{level})) : ''/eg;
Branch: 1 branch
BranchTrueFalseTotal
$opt{'indent'} ? : 0 0 0
217 0 return $r;
218 }
219  
220 0 croak "Unknown type '$o->{type}' or missing option";
221 }
222  
223  
224 # Elm JSON decoder for values of elm_type()
225 # options: elm_type() options + json_decode var_prefix
226 0 ▶sub elm_decoder {
Subroutine elm_decoder: not called CC=32 SCAR=69.6
Pod undocumented
227 0 my($o, %opt) = @_;
228 0 ▶ $opt{json_decode} //= '';
Condition0%0/2
$opt{"json_decode"} //= ""
l!l
00
MC/DC0%0/1
$opt{"json_decode"} //= ""
$opt{"json_decode"}
Truth table0%0/2
A
A= $opt{"json_decode"}
Aresult
11
00
229 0 ▶ $opt{var_prefix} //= 'd';
Condition0%0/2
$opt{"var_prefix"} //= "d"
l!l
00
MC/DC0%0/1
$opt{"var_prefix"} //= "d"
$opt{"var_prefix"}
Truth table0%0/2
A
A= $opt{"var_prefix"}
Aresult
11
00
230  
231 return sprintf '(%snullable %s)',
232 $opt{json_decode}, $opt{values} || $o->elm_decoder(%opt, required => 1)
233 0 ▶ if !$o->{required} && !defined $o->{default} && !$opt{required};
Branch: 1 branch
BranchTrueFalseTotal
unless $o->{"required"} or defined $o->{"default"} or $opt{"required"} 0 0 0
Condition0%0/9
$o->{"required"} or defined $o->{"default"} or $opt{"required"}
l!l&&r!l&&!r
000
$o->{"required"} or defined $o->{"default"}
l!l&&r!l&&!r
000
$opt{'values'} || $o->elm_decoder(%opt, 'required', 1)
l!l&&r!l&&!r
000
MC/DC0%0/3
$o->{"required"} or defined $o->{"default"} or $opt{"required"}
$o->{"required"} defined $o->{"default"} $opt{"required"}
MC/DC0%0/2
$opt{'values'} || $o->elm_decoder(%opt, 'required', 1)
$opt{'values'} $o->elm_decoder(%opt, 'required', 1)
Truth table0%0/4
A or B or C
A= $o->{"required"}B= defined $o->{"default"}C= $opt{"required"}
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/3
A || B
A= $opt{'values'}B= $o->elm_decoder(%opt, 'required', 1)
ABresult
1X1
011
000
234  
235 0 delete $opt{required};
236 0 ▶ return "$opt{json_decode}string" if $o->{type} eq 'scalar';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "scalar" 0 0 0
237 0 ▶ return "$opt{json_decode}bool" if $o->{type} eq 'bool';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "bool" 0 0 0
238 0 ▶ return "$opt{json_decode}float" if $o->{type} eq 'num';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "num" 0 0 0
239 0 ▶ return "$opt{json_decode}int" if $o->{type} eq 'int';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "int" 0 0 0
240 0 ▶ return $opt{any} if $o->{type} eq 'any' && $opt{any};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "any" and $opt{"any"} 0 0 0
Condition0%0/3
$o->{"type"} eq "any" and $opt{"any"}
!ll&&!rl&&r
000
MC/DC0%0/2
$o->{"type"} eq "any" and $opt{"any"}
$o->{"type"} eq "any" $opt{"any"}
Truth table0%0/3
A and B
A= $o->{"type"} eq "any"B= $opt{"any"}
ABresult
0X0
100
111
241 0 ▶ return "$opt{json_decode}value" if $o->{type} eq 'any';
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "any" 0 0 0
242 return sprintf '(%slist %s)', $opt{json_decode}, $opt{values} || $o->{values}->elm_decoder(%opt)
243 0 ▶ if $o->{type} eq 'array' && ($opt{values} || $o->{values});
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"type"} eq "array" and $opt{"values"} || $o->{"values"} 0 0 0
Condition0%0/9
$o->{"type"} eq "array" and $opt{"values"} || $o->{"values"}
!ll&&!rl&&r
000
$opt{"values"} or $o->{"values"}
l!l&&r!l&&!r
000
$opt{'values'} || $o->{'values'}->elm_decoder(%opt)
l!l&&r!l&&!r
000
MC/DC0%0/3
$o->{"type"} eq "array" and $opt{"values"} || $o->{"values"}
$o->{"type"} eq "array" $opt{"values"} $o->{"values"}
MC/DC0%0/2
$opt{'values'} || $o->{'values'}->elm_decoder(%opt)
$opt{'values'} $o->{'values'}->elm_decoder(%opt)
Truth table0%0/4
A and B or C
A= $o->{"type"} eq "array"B= $opt{"values"}C= $o->{"values"}
ABCresult
0XX0
1000
11X1
1011
Truth table0%0/3
A || B
A= $opt{'values'}B= $o->{'values'}->elm_decoder(%opt)
ABresult
1X1
011
000
244  
245 0 ▶ if($o->{type} eq 'hash' && ($o->{keys} || $opt{keys})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"type"} eq "hash" and $o->{"keys"} || $opt{"keys"}) 0 0 0
Condition0%0/6
$o->{"type"} eq "hash" and $o->{"keys"} || $opt{"keys"}
!ll&&!rl&&r
000
$o->{"keys"} or $opt{"keys"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$o->{"type"} eq "hash" and $o->{"keys"} || $opt{"keys"}
$o->{"type"} eq "hash" $o->{"keys"} $opt{"keys"}
Truth table0%0/4
A and B or C
A= $o->{"type"} eq "hash"B= $o->{"keys"}C= $opt{"keys"}
ABCresult
0XX0
1000
11X1
1011
246 0 ▶ $opt{indent} //= 2;
Condition0%0/2
$opt{"indent"} //= 2
l!l
00
MC/DC0%0/1
$opt{"indent"} //= 2
$opt{"indent"}
Truth table0%0/2
A
A= $opt{"indent"}
Aresult
11
00
247 0 ▶ $opt{level} //= 1;
Condition0%0/2
$opt{"level"} //= 1
l!l
00
MC/DC0%0/1
$opt{"level"} //= 1
$opt{"level"}
Truth table0%0/2
A
A= $opt{"level"}
Aresult
11
00
248 0 my $len = 0;
249 0 ▶ $len = length $_ > $len ? length $_ : $len for keys %{$o->{keys}};
Branch: 1 branch
BranchTrueFalseTotal
length $_ > $len ? : 0 0 0
250  
251 0 my $r;
252 0 my $num = keys %{$o->{keys}};
253 0 my $varnum = 1;
254 0 ▶ my $getvar = sub { $opt{var_prefix}.($varnum++) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
255  
256 # For 8 members or less we can use the simple Json.Decode.map* functions.
257 0 ▶ if($num <= 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num <= 8) { } 0 0 0
258 0 my(@fnarg, @assign, @fetch);
259 0 for (sort keys %{$o->{keys}}) {
260 0 my $var = $getvar->();
261 0 push @fnarg, $var;
262 0 push @assign, "$_ = $var";
263 push @fetch, sprintf '(%sfield "%s"%s %s)', $opt{json_decode}, $_,
264 ' 'x($len-(length $_)),
265 0 ▶ $opt{keys}{$_} || $o->{keys}{$_}->elm_decoder(%opt, var_prefix => $var, level => $opt{level}+1);
Condition0%0/3
$opt{'keys'}{$_} || $o->{'keys'}{$_}->elm_decoder(%opt, 'var_prefix', $var, 'level', $opt{'level'} + 1)
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt{'keys'}{$_} || $o->{'keys'}{$_}->elm_decoder(%opt, 'var_prefix', $var, 'level', $opt{'level'} + 1)
$opt{'keys'}{$_} $o->{'keys'}{$_}->elm_decoder(%opt, 'var_prefix', $var, 'level', $opt{'level'} + 1)
Truth table0%0/3
A || B
A= $opt{'keys'}{$_}B= $o->{'keys'}{$_}->elm_decoder(%opt, 'var_prefix', $var, 'level', $opt{'level'} + 1)
ABresult
1X1
011
000
266 }
267 $r = sprintf "(%smap%s\n(\\%s -> { %s })\n%s)",
268 0 ▶ $opt{json_decode}, $num == 1 ? '' : $num, join(' ', @fnarg), join(', ', @assign), join("\n", @fetch);
Branch: 1 branch
BranchTrueFalseTotal
$num == 1 ? : 0 0 0
269  
270 # For larger hashes we go through Json.Decode.dict and a little custom decoding logic.
271 # Json.Decode only allows failing with an error string, so the error messages aren't as good.
272 } else {
273 0 my($dict, $fn, $name, $dec, $next, $cap) = map $getvar->(), 1..6;
274 0 my(@assign, @fn);
275 0 for (sort keys %{$o->{keys}}) {
276 0 my $var = $getvar->();
277 0 push @assign, "$_ = $var";
278 push @fn, sprintf '%s "%s"%s %s (\%s ->', $fn, $_,
279 ' 'x($len-(length $_)),
280 0 ▶ $opt{keys}{$_} || $o->{keys}{$_}->elm_decoder(%opt, var_prefix => "${var}_", level => $opt{level}+1),
Condition0%0/3
$opt{'keys'}{$_} || $o->{'keys'}{$_}->elm_decoder(%opt, 'var_prefix', "${var}_", 'level', $opt{'level'} + 1)
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt{'keys'}{$_} || $o->{'keys'}{$_}->elm_decoder(%opt, 'var_prefix', "${var}_", 'level', $opt{'level'} + 1)
$opt{'keys'}{$_} $o->{'keys'}{$_}->elm_decoder(%opt, 'var_prefix', "${var}_", 'level', $opt{'level'} + 1)
Truth table0%0/3
A || B
A= $opt{'keys'}{$_}B= $o->{'keys'}{$_}->elm_decoder(%opt, 'var_prefix', "${var}_", 'level', $opt{'level'} + 1)
ABresult
1X1
011
000
281 $var;
282 }
283 0 my $spc = ' 'x(12 + length($fn) + length($name) + length($dec) + length($next));
284 0 $r = "($opt{json_decode}andThen (\\$dict -> \n"
285 ."let $fn $name $dec $next = case Maybe.map ($opt{json_decode}decodeValue $dec) (Dict.get $name $dict) of\n"
286 ."${spc}Nothing -> $opt{json_decode}fail (\"Missing key '\"++$name++\"'\")\n"
287 ."${spc}Just (Err $cap) -> $opt{json_decode}fail (\"Error decoding value of '\"++$name++\"': \"++($opt{json_decode}errorToString $cap))\n"
288 ."${spc}Just (Ok $cap) -> $next $cap\n"
289 ."in ".join("\n ", @fn)."\n"
290 ." $opt{json_decode}succeed { ".join(', ', @assign)." }\n"
291 .')'.(')'x@fn)." ($opt{json_decode}dict $opt{json_decode}value))";
292 }
293  
294 0 ▶ $r =~ s/\n/$opt{indent} ? "\n" . (' 'x($opt{indent}*$opt{level})) : ''/eg;
Branch: 1 branch
BranchTrueFalseTotal
$opt{'indent'} ? : 0 0 0
295 0 return $r;
296 }
297  
298 0 croak "Unknown type '$o->{type}' or missing option";
299 }
300  
301  
302 1 1;
↑ Summary TUWF.pm »