| 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'} || ''
MC/DC100%1/1
$c->{'name'} || ''
$c->{'name'}
Truth table100%2/2
A
A= $c->{'name'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 144 | ▶ | return if $o->{type} eq 'int' || $o->{type} eq 'bool'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$o->{"type"} eq "int" or $o->{"type"} eq "bool"
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"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 144 | ▶ | $o->{type} = 'int' if $n eq 'int' || $n eq 'uint'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$n eq "int" or $n eq "uint"
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"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 144 | ▶ | $o->{type} = 'bool' if $n eq 'anybool' || $n eq 'undefbool' || $n eq 'jsonbool'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$n eq "anybool" or $n eq "undefbool" or $n eq "jsonbool"
$n eq "anybool" or $n eq "undefbool"
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"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 144 | ▶ | $o->{type} = 'num' if $n eq 'num'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%2/2
$c->{'name'} || ''
MC/DC100%1/1
$c->{'name'} || ''
$c->{'name'}
Truth table100%2/2
A
A= $c->{'name'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 144 | ▶ | $o->{values} = _merge_toplevel($c->{schema}{values}, $o->{values}||{}) if $c->{schema}{values}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$o->{'values'} || {}
MC/DC0%0/1
$o->{'values'} || {}
$o->{'values'}
Truth table50%1/2
A
A= $o->{'values'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 144 | ▶ | if($c->{schema}{keys}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 8 | ▶ | $o->{keys} ||= {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$o->{"keys"} ||= {}
MC/DC0%0/1
$o->{"keys"} ||= {}
$o->{"keys"}
Truth table50%1/2
A
A= $o->{"keys"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 8 | ▶ | $o->{keys}{$_} = _merge_toplevel($c->{schema}{keys}{$_}, $o->{keys}{$_}||{}) for keys %{$c->{schema}{keys}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$o->{'keys'}{$_} || {}
MC/DC0%0/1
$o->{'keys'}{$_} || {}
$o->{'keys'}{$_}
Truth table50%1/2
A
A= $o->{'keys'}{$_}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%3/6
defined $c->{"schema"}{"_analyze_minlength"} and !defined($o->{"minlength"}) || $o->{"minlength"} < $c->{"schema"}{"_analyze_minlength"}
not defined $o->{"minlength"} or $o->{"minlength"} < $c->{"schema"}{"_analyze_minlength"}
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"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%3/6
defined $c->{"schema"}{"_analyze_maxlength"} and !defined($o->{"maxlength"}) || $o->{"maxlength"} > $c->{"schema"}{"_analyze_maxlength"}
not defined $o->{"maxlength"} or $o->{"maxlength"} > $c->{"schema"}{"_analyze_maxlength"}
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"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
defined $c->{"schema"}{"_analyze_min"} and !defined($o->{"min"}) || $o->{"min"} < $c->{"schema"}{"_analyze_min"}
not defined $o->{"min"} or $o->{"min"} < $c->{"schema"}{"_analyze_min"}
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"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%4/6
defined $c->{"schema"}{"_analyze_max"} and !defined($o->{"max"}) || $o->{"max"} > $c->{"schema"}{"_analyze_max"}
not defined $o->{"max"} or $o->{"max"} > $c->{"schema"}{"_analyze_max"}
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"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 144 | ▶ | push @{$o->{regexes}}, $c->{schema}{_analyze_regex} if defined $c->{schema}{_analyze_regex}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"}
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"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 77 | ▶ | $o->{unknown} ||= $c->{schema}{unknown}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$o->{"unknown"} ||= $c->{"schema"}{"unknown"}
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"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 77 | ▶ | $o->{default} = $c->{schema}{default} if exists $c->{schema}{default}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 77 | ▶ | $o->{type} = $c->{schema}{type} if !$o->{type} || $o->{type} eq 'any'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $o->{"type"} or $o->{"type"} eq "any"
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"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 {})
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 {})
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"}
MC/DC0%0/2
$opt{"unknown"} ||= $o->{"unknown"}
$opt{"unknown"}
$o->{"unknown"}
Truth table66%2/3
A ||= B
A= $opt{"unknown"}B= $o->{"unknown"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 35 | ▶ | return undef if !defined $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 29 | ▶ | return $obj+0 if $o->{type} eq 'num'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 27 | ▶ | return int $obj if $o->{type} eq 'int'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 22 | ▶ | return $obj ? \1 : \0 if $o->{type} eq 'bool'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 14 | ▶ | return "$obj" if $o->{type} eq 'scalar'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 13 | ▶ | return [map $o->{values}->coerce_for_json($_, %opt), @$obj] if $o->{type} eq 'array' && $o->{values}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$o->{"type"} eq "array" and $o->{"values"}
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"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | : croak "Unknown key '$_' in hash in coerce_for_json()" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 12 | ▶ | } keys %$obj} if $o->{type} eq 'hash' && $o->{keys}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$o->{"type"} eq "hash" and $o->{"keys"}
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"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 23 | ▶ | return Cpanel::JSON::XS::Type::JSON_TYPE_INT_OR_NULL() if $o->{type} eq 'int'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 19 | ▶ | return Cpanel::JSON::XS::Type::JSON_TYPE_BOOL_OR_NULL() if $o->{type} eq 'bool'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 14 | ▶ | return Cpanel::JSON::XS::Type::JSON_TYPE_STRING_OR_NULL() if $o->{type} eq 'scalar'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$o->{"type"} eq "hash" and $o->{"keys"}
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"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/9
ref $o->{"default"} eq "CODE" || !($o->{"required"} || defined $o->{"default"}) and not $opt{"required"}
ref $o->{"default"} eq "CODE" or not $o->{"required"} || defined $o->{"default"}
$o->{'required'} || defined $o->{'default'}
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"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | delete $opt{required}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | return 'String' if $o->{type} eq 'scalar'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | return 'Bool' if $o->{type} eq 'bool'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | return 'Float' if $o->{type} eq 'num'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | return 'Int' if $o->{type} eq 'int'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | return $opt{any} if $o->{type} eq 'any' && $opt{any}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$o->{"type"} eq "any" and $opt{"any"}
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"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/11
$o->{"type"} eq "array" and $opt{"values"} || $o->{"values"}
$opt{"values"} or $o->{"values"}
$opt{'array'} || 'List'
$opt{'values'} || $o->{'values'}->elm_type(%opt, '_need_parens', 1)
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"}
Truth table0%0/2
A
A= $opt{'array'}
Truth table0%0/3
A || B
A= $opt{'values'}B= $o->{'values'}->elm_type(%opt, '_need_parens', 1)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | if($o->{type} eq 'hash' && ($o->{keys} || $opt{keys})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$o->{"type"} eq "hash" and $o->{"keys"} || $opt{"keys"}
$o->{"keys"} or $opt{"keys"}
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"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | $opt{indent} //= 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opt{"indent"} //= 2
MC/DC0%0/1
$opt{"indent"} //= 2
$opt{"indent"}
Truth table0%0/2
A
A= $opt{"indent"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | $opt{level} //= 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opt{"level"} //= 1
MC/DC0%0/1
$opt{"level"} //= 1
$opt{"level"}
Truth table0%0/2
A
A= $opt{"level"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $len = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | $len = length $_ > $len ? length $_ : $len for keys %{$o->{keys}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
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)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"} //= ""
MC/DC0%0/1
$opt{"json_encode"} //= ""
$opt{"json_encode"}
Truth table0%0/2
A
A= $opt{"json_encode"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | $opt{var_prefix} //= 'e'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opt{"var_prefix"} //= "e"
MC/DC0%0/1
$opt{"var_prefix"} //= "e"
$opt{"var_prefix"}
Truth table0%0/2
A
A= $opt{"var_prefix"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | $opt{var_num} //= 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opt{"var_num"} //= 0
MC/DC0%0/1
$opt{"var_num"} //= 0
$opt{"var_num"}
Truth table0%0/2
A
A= $opt{"var_num"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/12
ref $o->{"default"} eq "CODE" || !($o->{"required"} || defined $o->{"default"}) and not $opt{"required"}
ref $o->{"default"} eq "CODE" or not $o->{"required"} || defined $o->{"default"}
$o->{'required'} || defined $o->{'default'}
$opt{'values'} || $o->elm_encoder(%opt, 'required', 1)
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"}
Truth table0%0/3
A || B
A= $opt{'values'}B= $o->elm_encoder(%opt, 'required', 1)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | delete $opt{required}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | return "$opt{json_encode}string" if $o->{type} eq 'scalar'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | return "$opt{json_encode}bool" if $o->{type} eq 'bool'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | return "$opt{json_encode}float" if $o->{type} eq 'num'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | return "$opt{json_encode}int" if $o->{type} eq 'int'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | return $opt{any} if $o->{type} eq 'any' && $opt{any}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$o->{"type"} eq "any" and $opt{"any"}
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"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/9
$o->{"type"} eq "array" and $opt{"values"} || $o->{"values"}
$opt{"values"} or $o->{"values"}
$opt{'values'} || $o->{'values'}->elm_encoder(%opt)
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"}
Truth table0%0/3
A || B
A= $opt{'values'}B= $o->{'values'}->elm_encoder(%opt)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if($o->{type} eq 'hash' && ($o->{keys} || $opt{keys})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$o->{"type"} eq "hash" and $o->{"keys"} || $opt{"keys"}
$o->{"keys"} or $opt{"keys"}
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"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | $opt{indent} //= 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opt{"indent"} //= 2
MC/DC0%0/1
$opt{"indent"} //= 2
$opt{"indent"}
Truth table0%0/2
A
A= $opt{"indent"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | $opt{level} //= 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opt{"level"} //= 1
MC/DC0%0/1
$opt{"level"} //= 1
$opt{"level"}
Truth table0%0/2
A
A= $opt{"level"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my $len = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | $len = length $_ > $len ? length $_ : $len for keys %{$o->{keys}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
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)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"} //= ""
MC/DC0%0/1
$opt{"json_decode"} //= ""
$opt{"json_decode"}
Truth table0%0/2
A
A= $opt{"json_decode"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | $opt{var_prefix} //= 'd'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opt{"var_prefix"} //= "d"
MC/DC0%0/1
$opt{"var_prefix"} //= "d"
$opt{"var_prefix"}
Truth table0%0/2
A
A= $opt{"var_prefix"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/9
$o->{"required"} or defined $o->{"default"} or $opt{"required"}
$o->{"required"} or defined $o->{"default"}
$opt{'values'} || $o->elm_decoder(%opt, 'required', 1)
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"}
Truth table0%0/3
A || B
A= $opt{'values'}B= $o->elm_decoder(%opt, 'required', 1)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | delete $opt{required}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | return "$opt{json_decode}string" if $o->{type} eq 'scalar'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | return "$opt{json_decode}bool" if $o->{type} eq 'bool'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | return "$opt{json_decode}float" if $o->{type} eq 'num'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | return "$opt{json_decode}int" if $o->{type} eq 'int'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | return $opt{any} if $o->{type} eq 'any' && $opt{any}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$o->{"type"} eq "any" and $opt{"any"}
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"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | return "$opt{json_decode}value" if $o->{type} eq 'any'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/9
$o->{"type"} eq "array" and $opt{"values"} || $o->{"values"}
$opt{"values"} or $o->{"values"}
$opt{'values'} || $o->{'values'}->elm_decoder(%opt)
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"}
Truth table0%0/3
A || B
A= $opt{'values'}B= $o->{'values'}->elm_decoder(%opt)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | if($o->{type} eq 'hash' && ($o->{keys} || $opt{keys})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$o->{"type"} eq "hash" and $o->{"keys"} || $opt{"keys"}
$o->{"keys"} or $opt{"keys"}
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"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | $opt{indent} //= 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opt{"indent"} //= 2
MC/DC0%0/1
$opt{"indent"} //= 2
$opt{"indent"}
Truth table0%0/2
A
A= $opt{"indent"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | $opt{level} //= 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opt{"level"} //= 1
MC/DC0%0/1
$opt{"level"} //= 1
$opt{"level"}
Truth table0%0/2
A
A= $opt{"level"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | my $len = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | $len = length $_ > $len ? length $_ : $len for keys %{$o->{keys}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
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)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
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)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | return $r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | croak "Unknown type '$o->{type}' or missing option"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||