| 1 | package JQ::Lite::Util; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 182 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 182 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 182 | ▶ | use JSON::PP (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 182 | ▶ | use Scalar::Util qw(looks_like_number); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 18 | ▶ | sub _apply_assignment { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_assignment: called CC=13 SCAR=26.3
| |||||||||||||||||||||||||||||||||
| 10 | 18 | my ($self, $item, $path, $value_spec, $operator) = @_; | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 18 | ▶ | return $item unless defined $item; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 13 | 18 | ▶ | return $item unless defined $path && length $path; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $path and length $path
MC/DC50%1/2
defined $path and length $path
defined $path
length $path
Truth table66%2/3
A and B
A= defined $pathB= length $path
| |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 16 | ▶ | $operator //= '='; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$operator //= "="
MC/DC0%0/1
$operator //= "="
$operator
Truth table50%1/2
A
A= $operator
| |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 16 | my $value = _resolve_assignment_value($self, $item, $value_spec); | |||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 16 | ▶ | if ($operator ne '=') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 20 | 6 | my $current = _clone_for_assignment(_get_path_value($item, $path)); | |||||||||||||||||||||||||||||||
| 21 | 6 | my $current_num = _coerce_number($current); | |||||||||||||||||||||||||||||||
| 22 | 6 | my $value_num = _coerce_number($value); | |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 6 | ▶ | return $item unless defined $current_num && defined $value_num; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $current_num and defined $value_num
MC/DC0%0/2
defined $current_num and defined $value_num
defined $current_num
defined $value_num
Truth table33%1/3
A and B
A= defined $current_numB= defined $value_num
| |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 6 | my $result; | |||||||||||||||||||||||||||||||
| 27 | 6 | ▶ | if ($operator eq '+=') { | ||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||
| 28 | 2 | $result = $current_num + $value_num; | |||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||
| 30 | elsif ($operator eq '-=') { | ||||||||||||||||||||||||||||||||
| 31 | 1 | $result = $current_num - $value_num; | |||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||
| 33 | elsif ($operator eq '*=') { | ||||||||||||||||||||||||||||||||
| 34 | 1 | $result = $current_num * $value_num; | |||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||
| 36 | elsif ($operator eq '/=') { | ||||||||||||||||||||||||||||||||
| 37 | 2 | ▶ | return $item if $value_num == 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 38 | 1 | $result = $current_num / $value_num; | |||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||
| 40 | else { | ||||||||||||||||||||||||||||||||
| 41 | 0 | return $item; | |||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 5 | $value = $result; | |||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | 15 | _set_path_value($item, $path, $value); | |||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | 15 | return $item; | |||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | 6 | ▶ | sub _get_path_value { | ||||||||||||||||||||||||||||||
|
Subroutine
_get_path_value: called CC=15 SCAR=38.4
| |||||||||||||||||||||||||||||||||
| 53 | 6 | my ($target, $path) = @_; | |||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 6 | ▶ | return undef unless defined $target; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 56 | 6 | ▶ | return undef unless defined $path && length $path; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $path and length $path
MC/DC0%0/2
defined $path and length $path
defined $path
length $path
Truth table33%1/3
A and B
A= defined $pathB= length $path
| |||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | 6 | my @segments = _parse_path_segments($path); | |||||||||||||||||||||||||||||||
| 59 | 6 | ▶ | return undef unless @segments; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 6 | my $cursor = $target; | |||||||||||||||||||||||||||||||
| 62 | 6 | for my $index (0 .. $#segments) { | |||||||||||||||||||||||||||||||
| 63 | 12 | my $segment = $segments[$index]; | |||||||||||||||||||||||||||||||
| 64 | 12 | my $is_last = ($index == $#segments); | |||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | 12 | ▶ | if ($segment->{type} eq 'key') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 67 | 12 | ▶ | return undef unless ref $cursor eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 68 | 12 | my $key = $segment->{value}; | |||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 12 | ▶ | return $cursor->{$key} if $is_last; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 6 | ▶ | return undef unless exists $cursor->{$key}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 73 | 6 | $cursor = $cursor->{$key}; | |||||||||||||||||||||||||||||||
| 74 | 6 | next; | |||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ($segment->{type} eq 'index') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | return undef unless ref $cursor eq 'ARRAY'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 0 | my $numeric = _normalize_path_array_index($segment->{value}, scalar @$cursor); | |||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | return undef if $numeric < 0 || $numeric > $#$cursor; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$numeric < 0 or $numeric > $cursor->$#*
MC/DC0%0/2
$numeric < 0 or $numeric > $cursor->$#*
$numeric < 0
$numeric > $cursor->$#*
Truth table0%0/3
A or B
A= $numeric < 0B= $numeric > $cursor->$#*
| |||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | return $cursor->[$numeric] if $is_last; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 0 | $cursor = $cursor->[$numeric]; | |||||||||||||||||||||||||||||||
| 87 | 0 | next; | |||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 12 | ▶ | sub _coerce_number { | ||||||||||||||||||||||||||||||
|
Subroutine
_coerce_number: called CC=5 SCAR=19.4
| |||||||||||||||||||||||||||||||||
| 95 | 12 | my ($value) = @_; | |||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | 12 | ▶ | return 0 if !defined $value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | 11 | ▶ | if (JSON::PP::is_bool($value)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | return $value ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | 11 | ▶ | return 0 + $value if looks_like_number($value); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | 16 | ▶ | sub _resolve_assignment_value { | ||||||||||||||||||||||||||||||
|
Subroutine
_resolve_assignment_value: called CC=13 SCAR=32.0
| |||||||||||||||||||||||||||||||||
| 109 | 16 | my ($self, $item, $value_spec) = @_; | |||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | 16 | ▶ | return undef unless defined $value_spec; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | 16 | ▶ | if ($value_spec->{type} && $value_spec->{type} eq 'path') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$value_spec->{"type"} and $value_spec->{"type"} eq "path"
MC/DC50%1/2
$value_spec->{"type"} and $value_spec->{"type"} eq "path"
$value_spec->{"type"}
$value_spec->{"type"} eq "path"
Truth table66%2/3
A and B
A= $value_spec->{"type"}B= $value_spec->{"type"} eq "path"
| |||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | my $path = $value_spec->{value} // ''; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$value_spec->{"value"} // ""
MC/DC0%0/1
$value_spec->{"value"} // ""
$value_spec->{"value"}
Truth table50%1/2
A
A= $value_spec->{"value"}
| |||||||||||||||||||||||||||||||||
| 115 | 1 | $path =~ s/^\.//; | |||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | 1 | my @values = _traverse($item, $path); | |||||||||||||||||||||||||||||||
| 118 | 1 | return _clone_for_assignment($values[0]); | |||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | 15 | ▶ | if ($value_spec->{type} && $value_spec->{type} eq 'expression') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$value_spec->{"type"} and $value_spec->{"type"} eq "expression"
MC/DC50%1/2
$value_spec->{"type"} and $value_spec->{"type"} eq "expression"
$value_spec->{"type"}
$value_spec->{"type"} eq "expression"
Truth table66%2/3
A and B
A= $value_spec->{"type"}B= $value_spec->{"type"} eq "expression"
| |||||||||||||||||||||||||||||||||
| 122 | 1 | ▶ | my $expr = $value_spec->{value} // ''; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$value_spec->{"value"} // ""
MC/DC0%0/1
$value_spec->{"value"} // ""
$value_spec->{"value"}
Truth table50%1/2
A
A= $value_spec->{"value"}
| |||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | 1 | my ($values, $ok) = _evaluate_value_expression($self, $item, $expr); | |||||||||||||||||||||||||||||||
| 125 | 1 | ▶ | if ($ok) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 126 | 1 | ▶ | return _clone_for_assignment(@$values ? $values->[0] : undef); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if (defined $self && $self->can('run_query')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self and $self->can("run_query")
MC/DC0%0/2
defined $self and $self->can("run_query")
defined $self
$self->can("run_query")
Truth table0%0/3
A and B
A= defined $selfB= $self->can("run_query")
| |||||||||||||||||||||||||||||||||
| 130 | 0 | my @outputs = $self->run_query(_encode_json($item), $expr); | |||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | return _clone_for_assignment($outputs[0]) if @outputs; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | 0 | return _clone_for_assignment($expr); | |||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | 14 | return _clone_for_assignment($value_spec->{value}); | |||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | 15 | ▶ | sub _set_path_value { | ||||||||||||||||||||||||||||||
|
Subroutine
_set_path_value: called CC=16 SCAR=32.8
| |||||||||||||||||||||||||||||||||
| 141 | 15 | my ($target, $path, $value) = @_; | |||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | 15 | ▶ | return unless defined $target; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||
| 145 | 15 | my @segments = _parse_path_segments($path); | |||||||||||||||||||||||||||||||
| 146 | 15 | ▶ | return unless @segments; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | 15 | my $cursor = $target; | |||||||||||||||||||||||||||||||
| 149 | 15 | for my $index (0 .. $#segments) { | |||||||||||||||||||||||||||||||
| 150 | 29 | my $segment = $segments[$index]; | |||||||||||||||||||||||||||||||
| 151 | 29 | my $is_last = ($index == $#segments); | |||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | 29 | ▶ | if ($segment->{type} eq 'key') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 154 | 27 | ▶ | return unless ref $cursor eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 155 | 27 | my $key = $segment->{value}; | |||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||
| 157 | 27 | ▶ | if ($is_last) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 158 | 15 | $cursor->{$key} = $value; | |||||||||||||||||||||||||||||||
| 159 | 15 | last; | |||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||
| 162 | 12 | ▶ | if (!exists $cursor->{$key} || !defined $cursor->{$key}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $cursor->{$key} and defined $cursor->{$key}
MC/DC0%0/2
exists $cursor->{$key} and defined $cursor->{$key}
exists $cursor->{$key}
defined $cursor->{$key}
Truth table33%1/3
A and B
A= exists $cursor->{$key}B= defined $cursor->{$key}
| |||||||||||||||||||||||||||||||||
| 163 | 0 | my $next = $segments[$index + 1]; | |||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | $cursor->{$key} = ($next->{type} eq 'index') ? [] : {}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||
| 167 | 12 | $cursor = $cursor->{$key}; | |||||||||||||||||||||||||||||||
| 168 | 12 | next; | |||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||
| 171 | 2 | ▶ | if ($segment->{type} eq 'index') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 172 | 2 | ▶ | return unless ref $cursor eq 'ARRAY'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||
| 174 | 2 | my $numeric = _normalize_path_array_index($segment->{value}, scalar @$cursor); | |||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||
| 176 | 2 | ▶ | return if $numeric < 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | 2 | ▶ | if ($is_last) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 179 | 0 | $cursor->[$numeric] = $value; | |||||||||||||||||||||||||||||||
| 180 | 0 | last; | |||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||
| 183 | 2 | ▶ | if (!defined $cursor->[$numeric]) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 184 | 0 | my $next = $segments[$index + 1]; | |||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | $cursor->[$numeric] = ($next->{type} eq 'index') ? [] : {}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||
| 188 | 2 | $cursor = $cursor->[$numeric]; | |||||||||||||||||||||||||||||||
| 189 | 2 | next; | |||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||
| 193 | 15 | return; | |||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||
| 196 | 2 | ▶ | sub _normalize_path_array_index { | ||||||||||||||||||||||||||||||
|
Subroutine
_normalize_path_array_index: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||
| 197 | 2 | my ($idx, $array_size) = @_; | |||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | 2 | my $numeric = int($idx); | |||||||||||||||||||||||||||||||
| 200 | 2 | ▶ | if ($idx =~ /^-?\d+$/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 201 | 2 | ▶ | $numeric += $array_size if $numeric < 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||
| 204 | 2 | return $numeric; | |||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||
| 207 | 21 | ▶ | sub _parse_path_segments { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_path_segments: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||
| 208 | 21 | my ($path) = @_; | |||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||
| 210 | 21 | ▶ | $path //= ''; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$path //= ""
MC/DC0%0/1
$path //= ""
$path
Truth table50%1/2
A
A= $path
| |||||||||||||||||||||||||||||||||
| 211 | 21 | $path =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||
| 213 | 21 | my @segments; | |||||||||||||||||||||||||||||||
| 214 | 21 | for my $chunk (split /\./, $path) { | |||||||||||||||||||||||||||||||
| 215 | 40 | ▶ | next if $chunk eq ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||
| 217 | 40 | ▶ | while (length $chunk) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 218 | 41 | ▶ | if ($chunk =~ s/^\[(\-?\d+)\]//) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 219 | 2 | push @segments, { type => 'index', value => $1 }; | |||||||||||||||||||||||||||||||
| 220 | 2 | next; | |||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||
| 223 | 39 | ▶ | if ($chunk =~ s/^([^\[]+)//) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 224 | 39 | push @segments, { type => 'key', value => $1 }; | |||||||||||||||||||||||||||||||
| 225 | 39 | next; | |||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||
| 228 | 0 | last; | |||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||
| 232 | 21 | return @segments; | |||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||
| 235 | 22 | ▶ | sub _clone_for_assignment { | ||||||||||||||||||||||||||||||
|
Subroutine
_clone_for_assignment: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||
| 236 | 22 | my ($value) = @_; | |||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||
| 238 | 22 | ▶ | return undef unless defined $value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 239 | 20 | ▶ | return $value unless ref $value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||
| 241 | 0 | my $json = _encode_json($value); | |||||||||||||||||||||||||||||||
| 242 | 0 | return _decode_json($json); | |||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | sub _map { | ||||||||||||||||||||||||||||||
|
Subroutine
_map: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 246 | 0 | my ($self, $data, $filter) = @_; | |||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | if (ref $data ne 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 249 | 0 | warn "_map expects array reference"; | |||||||||||||||||||||||||||||||
| 250 | 0 | return (); | |||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||
| 253 | 0 | my @mapped; | |||||||||||||||||||||||||||||||
| 254 | 0 | for my $item (@$data) { | |||||||||||||||||||||||||||||||
| 255 | 0 | push @mapped, $self->run_query(_encode_json($item), $filter); | |||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||
| 258 | 0 | return @mapped; | |||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||
| 261 | 6 | ▶ | sub _apply_all { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_all: called CC=12 SCAR=27.6
| |||||||||||||||||||||||||||||||||
| 262 | 6 | my ($self, $value, $expr) = @_; | |||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||
| 264 | 6 | ▶ | if (ref $value eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 265 | 5 | ▶ | return JSON::PP::true unless @$value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||
| 267 | 4 | for my $item (@$value) { | |||||||||||||||||||||||||||||||
| 268 | 9 | ▶ | if (defined $expr) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 269 | 4 | my @evaluated = $self->run_query(_encode_json($item), $expr); | |||||||||||||||||||||||||||||||
| 270 | 4 | ▶ | return JSON::PP::false unless @evaluated; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 271 | 4 | ▶ | return JSON::PP::false if grep { !_is_truthy($_) } @evaluated; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||
| 273 | else { | ||||||||||||||||||||||||||||||||
| 274 | 5 | ▶ | return JSON::PP::false unless _is_truthy($item); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||
| 278 | 2 | return JSON::PP::true; | |||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||
| 281 | 1 | ▶ | if (defined $expr) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 282 | 0 | my @evaluated = $self->run_query(_encode_json($value), $expr); | |||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | return JSON::PP::false unless @evaluated; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | return grep { !_is_truthy($_) } @evaluated ? JSON::PP::false : JSON::PP::true; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||
| 287 | 1 | ▶ | return _is_truthy($value) ? JSON::PP::true : JSON::PP::false; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||
| 290 | 6 | ▶ | sub _apply_any { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_any: called CC=10 SCAR=24.1
| |||||||||||||||||||||||||||||||||
| 291 | 6 | my ($self, $value, $expr) = @_; | |||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||
| 293 | 6 | ▶ | if (ref $value eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 294 | 4 | ▶ | return JSON::PP::false unless @$value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||
| 296 | 4 | for my $item (@$value) { | |||||||||||||||||||||||||||||||
| 297 | 9 | ▶ | if (defined $expr) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 298 | 4 | my @evaluated = $self->run_query(_encode_json($item), $expr); | |||||||||||||||||||||||||||||||
| 299 | 4 | ▶ | return JSON::PP::true if grep { _is_truthy($_) } @evaluated; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||
| 301 | else { | ||||||||||||||||||||||||||||||||
| 302 | 5 | ▶ | return JSON::PP::true if _is_truthy($item); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||
| 306 | 2 | return JSON::PP::false; | |||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||
| 309 | 2 | ▶ | if (defined $expr) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 310 | 0 | my @evaluated = $self->run_query(_encode_json($value), $expr); | |||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | return grep { _is_truthy($_) } @evaluated ? JSON::PP::true : JSON::PP::false; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||
| 314 | 2 | ▶ | return _is_truthy($value) ? JSON::PP::true : JSON::PP::false; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||
| 317 | 46 | ▶ | sub _is_truthy { | ||||||||||||||||||||||||||||||
|
Subroutine
_is_truthy: called CC=12 SCAR=25.7
| |||||||||||||||||||||||||||||||||
| 318 | 46 | my ($value) = @_; | |||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||
| 320 | 46 | ▶ | return 0 unless defined $value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||
| 322 | 42 | ▶ | if (JSON::PP::is_bool($value)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 323 | 34 | ▶ | return $value ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||
| 326 | 8 | ▶ | if (ref $value eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 327 | 2 | ▶ | return @$value ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||
| 330 | 6 | ▶ | if (ref $value eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | return scalar(keys %$value) ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||
| 334 | 6 | ▶ | if (!ref $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 335 | 6 | ▶ | return 0 if $value eq ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 336 | 6 | ▶ | if (looks_like_number($value)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 337 | 4 | ▶ | return $value != 0 ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||
| 339 | 2 | return 1; | |||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||
| 342 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||
| 345 | 37 | ▶ | sub _apply_case_transform { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_case_transform: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||
| 346 | 37 | my ($value, $mode) = @_; | |||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||
| 348 | 37 | ▶ | if (!defined $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 349 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||
| 352 | 37 | ▶ | if (ref $value eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 353 | 6 | return [ map { _apply_case_transform($_, $mode) } @$value ]; | |||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||
| 356 | 31 | ▶ | if (!ref $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 357 | 29 | ▶ | return uc $value if $mode eq 'upper'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 358 | 17 | ▶ | return lc $value if $mode eq 'lower'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 359 | 6 | return _to_titlecase($value); | |||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||
| 362 | 2 | return $value; | |||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||
| 365 | 12 | ▶ | sub _apply_ascii_case_transform { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_ascii_case_transform: called CC=6 SCAR=18.5
| |||||||||||||||||||||||||||||||||
| 366 | 12 | my ($value, $mode) = @_; | |||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||
| 368 | 12 | ▶ | if (!defined $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 369 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||
| 372 | 12 | ▶ | if (ref $value eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 373 | 2 | return [ map { _apply_ascii_case_transform($_, $mode) } @$value ]; | |||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||
| 376 | 10 | ▶ | if (!ref $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 377 | 10 | my $copy = $value; | |||||||||||||||||||||||||||||||
| 378 | 10 | ▶ | if ($mode eq 'upper') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 379 | 5 | $copy =~ tr/a-z/A-Z/; | |||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||
| 381 | elsif ($mode eq 'lower') { | ||||||||||||||||||||||||||||||||
| 382 | 5 | $copy =~ tr/A-Z/a-z/; | |||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||
| 384 | 10 | return $copy; | |||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||
| 387 | 0 | return $value; | |||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||
| 390 | 6 | ▶ | sub _to_titlecase { | ||||||||||||||||||||||||||||||
|
Subroutine
_to_titlecase: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 391 | 6 | my ($value) = @_; | |||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||
| 393 | 6 | my $result = lc $value; | |||||||||||||||||||||||||||||||
| 394 | 6 | $result =~ s/(^|[^\p{L}\p{N}])(\p{L})/$1 . uc($2)/ge; | |||||||||||||||||||||||||||||||
| 395 | 6 | return $result; | |||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||
| 398 | 19 | ▶ | sub _apply_trim { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_trim: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 399 | 19 | my ($value) = @_; | |||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||
| 401 | 19 | ▶ | if (!defined $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 402 | 1 | return undef; | |||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||
| 405 | 18 | ▶ | if (!ref $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 406 | 13 | my $copy = $value; | |||||||||||||||||||||||||||||||
| 407 | 13 | $copy =~ s/^\s+//; | |||||||||||||||||||||||||||||||
| 408 | 13 | $copy =~ s/\s+$//; | |||||||||||||||||||||||||||||||
| 409 | 13 | return $copy; | |||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||
| 412 | 5 | ▶ | if (ref $value eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 413 | 4 | return [ map { _apply_trim($_) } @$value ]; | |||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||
| 416 | 1 | return $value; | |||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||
| 419 | 34 | ▶ | sub _apply_trimstr { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_trimstr: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||
| 420 | 34 | my ($value, $needle, $mode) = @_; | |||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||
| 422 | 34 | ▶ | if (!defined $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 423 | 2 | return undef; | |||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||
| 426 | 32 | ▶ | if (ref $value eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 427 | 4 | return [ map { _apply_trimstr($_, $needle, $mode) } @$value ]; | |||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||
| 430 | 28 | ▶ | if (ref $value) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 431 | 5 | return $value; | |||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||
| 434 | 23 | ▶ | return $value if !_is_string_scalar($value); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||
| 436 | 19 | ▶ | $needle = '' unless defined $needle; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 437 | 19 | my $target = "$value"; | |||||||||||||||||||||||||||||||
| 438 | 19 | my $pattern = "$needle"; | |||||||||||||||||||||||||||||||
| 439 | 19 | my $len = length $pattern; | |||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||
| 441 | 19 | ▶ | return $target if $len == 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||
| 443 | 17 | ▶ | if ($mode eq 'left') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 444 | 9 | ▶ | return $target if index($target, $pattern) != 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 445 | 5 | return substr($target, $len); | |||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||
| 448 | 8 | ▶ | if ($mode eq 'right') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 449 | 8 | ▶ | return $target if $len > length($target); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 450 | 6 | ▶ | return $target unless substr($target, -$len) eq $pattern; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 451 | 4 | return substr($target, 0, length($target) - $len); | |||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||
| 454 | 0 | return $target; | |||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||
| 457 | 5 | ▶ | sub _apply_paths { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_paths: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 458 | 5 | my ($value) = @_; | |||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||
| 460 | 5 | ▶ | if (!ref $value || JSON::PP::is_bool($value)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not ref $value or JSON::PP::is_bool($value)
MC/DC50%1/2
not ref $value or JSON::PP::is_bool($value)
not ref $value
JSON::PP::is_bool($value)
Truth table66%2/3
not(A) or B
A= not ref $valueB= JSON::PP::is_bool($value)
| |||||||||||||||||||||||||||||||||
| 461 | 2 | return []; | |||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||
| 464 | 3 | my @paths; | |||||||||||||||||||||||||||||||
| 465 | 3 | _collect_paths($value, [], \@paths); | |||||||||||||||||||||||||||||||
| 466 | 3 | return \@paths; | |||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||
| 469 | 3 | ▶ | sub _apply_scalar_paths { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_scalar_paths: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 470 | 3 | my ($value) = @_; | |||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||
| 472 | 3 | ▶ | return [] if _is_scalar_value($value); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||
| 474 | 1 | my @paths; | |||||||||||||||||||||||||||||||
| 475 | 1 | _collect_scalar_paths($value, [], \@paths); | |||||||||||||||||||||||||||||||
| 476 | 1 | return \@paths; | |||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||
| 479 | 6 | ▶ | sub _apply_leaf_paths { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_leaf_paths: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 480 | 6 | my ($value) = @_; | |||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||
| 482 | 6 | ▶ | if (_is_leaf_value($value)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 483 | 2 | return [ [] ]; | |||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||
| 486 | 4 | my @paths; | |||||||||||||||||||||||||||||||
| 487 | 4 | _collect_leaf_paths($value, [], \@paths); | |||||||||||||||||||||||||||||||
| 488 | 4 | return \@paths; | |||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||
| 491 | 43 | ▶ | sub _validate_path_array { | ||||||||||||||||||||||||||||||
|
Subroutine
_validate_path_array: called CC=8 SCAR=20.9
| |||||||||||||||||||||||||||||||||
| 492 | 43 | my ($path, $caller) = @_; | |||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||
| 494 | 43 | ▶ | $caller //= 'getpath'; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$caller //= "getpath"
MC/DC0%0/1
$caller //= "getpath"
$caller
Truth table50%1/2
A
A= $caller
| |||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||
| 496 | 43 | ▶ | die "$caller(): path must be an array" if ref($path) ne 'ARRAY'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||
| 498 | 43 | for my $segment (@$path) { | |||||||||||||||||||||||||||||||
| 499 | 64 | ▶ | my $is_boolean = ref($segment) && JSON::PP::is_bool($segment); | ||||||||||||||||||||||||||||||
|
Condition100%3/3
ref $segment && JSON::PP::is_bool($segment)
MC/DC100%2/2
ref $segment && JSON::PP::is_bool($segment)
ref $segment
JSON::PP::is_bool($segment)
Truth table100%3/3
A && B
A= ref $segmentB= JSON::PP::is_bool($segment)
| |||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||
| 501 | 64 | ▶ | die "$caller(): path elements must be defined" if !defined $segment; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 502 | 62 | ▶ | die "$caller(): path elements must be scalars" if ref($segment) && !$is_boolean; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $segment and not $is_boolean
MC/DC100%2/2
ref $segment and not $is_boolean
ref $segment
not $is_boolean
Truth table100%3/3
A and not(B)
A= ref $segmentB= not $is_boolean
| |||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||
| 505 | 39 | return [ @$path ]; | |||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||
| 508 | 14 | ▶ | sub _apply_getpath { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_getpath: called CC=19 SCAR=31.1
| |||||||||||||||||||||||||||||||||
| 509 | 14 | my ($self, $value, $expr) = @_; | |||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||
| 511 | 14 | ▶ | return undef unless defined $value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||
| 513 | 14 | ▶ | $expr //= ''; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$expr //= ""
MC/DC0%0/1
$expr //= ""
$expr
Truth table50%1/2
A
A= $expr
| |||||||||||||||||||||||||||||||||
| 514 | 14 | $expr =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||
| 515 | 14 | ▶ | return undef if $expr eq ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||
| 517 | 14 | my @paths; | |||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||
| 519 | 14 | my $decoded = eval { _decode_json($expr) }; | |||||||||||||||||||||||||||||||
| 520 | 14 | ▶ | if (!$@ && defined $decoded) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $@ and defined $decoded
MC/DC50%1/2
not $@ and defined $decoded
not $@
defined $decoded
Truth table66%2/3
not(A) and B
A= not $@B= defined $decoded
| |||||||||||||||||||||||||||||||||
| 521 | 13 | ▶ | if (ref $decoded eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 522 | 12 | ▶ | if (@$decoded && ref $decoded->[0] eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$decoded and ref $decoded->[0] eq "ARRAY"
MC/DC100%2/2
@$decoded and ref $decoded->[0] eq "ARRAY"
@$decoded
ref $decoded->[0] eq "ARRAY"
Truth table100%3/3
A and B
A= @$decodedB= ref $decoded->[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||||
| 523 | 1 | for my $path (@$decoded) { | |||||||||||||||||||||||||||||||
| 524 | 2 | push @paths, _validate_path_array($path, 'getpath'); | |||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||
| 527 | else { | ||||||||||||||||||||||||||||||||
| 528 | 11 | push @paths, _validate_path_array($decoded, 'getpath'); | |||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||
| 531 | else { | ||||||||||||||||||||||||||||||||
| 532 | 1 | die 'getpath(): path must be an array'; | |||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||
| 536 | 13 | ▶ | if (!@paths) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 537 | 1 | my @outputs = $self->run_query(_encode_json($value), $expr); | |||||||||||||||||||||||||||||||
| 538 | 1 | for my $output (@outputs) { | |||||||||||||||||||||||||||||||
| 539 | 7 | ▶ | next unless defined $output; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||
| 541 | 7 | ▶ | if (ref $output eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 542 | 7 | ▶ | if (@$output && ref $output->[0] eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@$output and ref $output->[0] eq "ARRAY"
MC/DC0%0/2
@$output and ref $output->[0] eq "ARRAY"
@$output
ref $output->[0] eq "ARRAY"
Truth table33%1/3
A and B
A= @$outputB= ref $output->[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||||
| 543 | 0 | for my $path (@$output) { | |||||||||||||||||||||||||||||||
| 544 | 0 | push @paths, _validate_path_array($path, 'getpath'); | |||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||
| 547 | else { | ||||||||||||||||||||||||||||||||
| 548 | 7 | push @paths, _validate_path_array($output, 'getpath'); | |||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||
| 551 | else { | ||||||||||||||||||||||||||||||||
| 552 | 0 | die 'getpath(): path must be an array'; | |||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||
| 557 | 13 | ▶ | return undef unless @paths; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||
| 559 | 13 | my @values = map { _traverse_path_array($value, $_) } @paths; | |||||||||||||||||||||||||||||||
| 560 | 13 | ▶ | return @values == 1 ? $values[0] : \@values; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||
| 563 | 10 | ▶ | sub _apply_setpath { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_setpath: called CC=6 SCAR=18.4
| |||||||||||||||||||||||||||||||||
| 564 | 10 | my ($self, $value, $paths_expr, $value_expr) = @_; | |||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||
| 566 | 10 | ▶ | return $value unless defined $value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||
| 568 | 10 | ▶ | $paths_expr //= ''; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$paths_expr //= ""
MC/DC0%0/1
$paths_expr //= ""
$paths_expr
Truth table50%1/2
A
A= $paths_expr
| |||||||||||||||||||||||||||||||||
| 569 | 10 | $paths_expr =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||
| 570 | 10 | ▶ | return $value if $paths_expr eq ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||
| 572 | 10 | my @paths = _resolve_paths_from_expr($self, $value, $paths_expr); | |||||||||||||||||||||||||||||||
| 573 | 7 | ▶ | return $value unless @paths; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||
| 575 | 7 | my $replacement = _evaluate_setpath_value($self, $value, $value_expr); | |||||||||||||||||||||||||||||||
| 576 | 7 | my $result = $value; | |||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||
| 578 | 7 | for my $path (@paths) { | |||||||||||||||||||||||||||||||
| 579 | 11 | $result = _set_value_at_path($result, [@$path], $replacement); | |||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||
| 582 | 7 | return $result; | |||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||
| 585 | 10 | ▶ | sub _resolve_paths_from_expr { | ||||||||||||||||||||||||||||||
|
Subroutine
_resolve_paths_from_expr: called CC=18 SCAR=35.8
| |||||||||||||||||||||||||||||||||
| 586 | 10 | my ($self, $value, $expr) = @_; | |||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||
| 588 | 10 | ▶ | return () unless defined $expr; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||
| 590 | 10 | my $clean = $expr; | |||||||||||||||||||||||||||||||
| 591 | 10 | $clean =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||
| 592 | 10 | ▶ | return () if $clean eq ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||
| 594 | 10 | my @paths; | |||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||
| 596 | 10 | my $decoded = eval { _decode_json($clean) }; | |||||||||||||||||||||||||||||||
| 597 | 10 | ▶ | if (!$@ && defined $decoded) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $@ and defined $decoded
MC/DC50%1/2
not $@ and defined $decoded
not $@
defined $decoded
Truth table66%2/3
not(A) and B
A= not $@B= defined $decoded
| |||||||||||||||||||||||||||||||||
| 598 | 9 | ▶ | if (ref $decoded eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 599 | 8 | ▶ | if (@$decoded && ref $decoded->[0] eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@$decoded and ref $decoded->[0] eq "ARRAY"
MC/DC0%0/2
@$decoded and ref $decoded->[0] eq "ARRAY"
@$decoded
ref $decoded->[0] eq "ARRAY"
Truth table33%1/3
A and B
A= @$decodedB= ref $decoded->[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||||
| 600 | 0 | push @paths, map { _validate_path_array($_, 'setpath') } @$decoded; | |||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||
| 602 | else { | ||||||||||||||||||||||||||||||||
| 603 | 8 | push @paths, _validate_path_array($decoded, 'setpath'); | |||||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||
| 606 | else { | ||||||||||||||||||||||||||||||||
| 607 | 1 | die 'setpath(): path must be an array'; | |||||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||
| 611 | 7 | ▶ | if (!@paths) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 612 | 1 | my @outputs = $self->run_query(_encode_json($value), $clean); | |||||||||||||||||||||||||||||||
| 613 | 1 | for my $output (@outputs) { | |||||||||||||||||||||||||||||||
| 614 | 5 | ▶ | next unless defined $output; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||
| 616 | 5 | ▶ | if (ref $output eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 617 | 5 | ▶ | if (@$output && ref $output->[0] eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
@$output and ref $output->[0] eq "ARRAY"
MC/DC0%0/2
@$output and ref $output->[0] eq "ARRAY"
@$output
ref $output->[0] eq "ARRAY"
Truth table33%1/3
A and B
A= @$outputB= ref $output->[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||||
| 618 | 0 | push @paths, map { _validate_path_array($_, 'setpath') } @$output; | |||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||
| 620 | ▶ | elsif (!@$output || !ref $output->[0]) { | |||||||||||||||||||||||||||||||
|
Condition33%1/3
@$output && ref $output->[0]
MC/DC0%0/2
@$output && ref $output->[0]
@$output
ref $output->[0]
Truth table33%1/3
A && B
A= @$outputB= ref $output->[0]
| |||||||||||||||||||||||||||||||||
| 621 | 5 | push @paths, _validate_path_array($output, 'setpath'); | |||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||
| 624 | ▶ | elsif (!ref $output || JSON::PP::is_bool($output)) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
not ref $output or JSON::PP::is_bool($output)
MC/DC0%0/2
not ref $output or JSON::PP::is_bool($output)
not ref $output
JSON::PP::is_bool($output)
Truth table0%0/3
not(A) or B
A= not ref $outputB= JSON::PP::is_bool($output)
| |||||||||||||||||||||||||||||||||
| 625 | 0 | die 'setpath(): path must be an array'; | |||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||
| 630 | 7 | return @paths; | |||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||
| 633 | 7 | ▶ | sub _evaluate_setpath_value { | ||||||||||||||||||||||||||||||
|
Subroutine
_evaluate_setpath_value: called CC=8 SCAR=24.0
| |||||||||||||||||||||||||||||||||
| 634 | 7 | my ($self, $context, $expr) = @_; | |||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||
| 636 | 7 | ▶ | return undef unless defined $expr; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||
| 638 | 7 | my $clean = $expr; | |||||||||||||||||||||||||||||||
| 639 | 7 | $clean =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||
| 640 | 7 | ▶ | return undef if $clean eq ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||
| 642 | 7 | my $decoded = eval { _decode_json($clean) }; | |||||||||||||||||||||||||||||||
| 643 | 7 | ▶ | if (!$@) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 644 | 6 | return $decoded; | |||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||
| 647 | 1 | ▶ | if ($clean =~ /^'(.*)'$/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 648 | 0 | my $text = $1; | |||||||||||||||||||||||||||||||
| 649 | 0 | $text =~ s/\\'/'/g; | |||||||||||||||||||||||||||||||
| 650 | 0 | return $text; | |||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||
| 653 | 1 | ▶ | if ($clean =~ /^\.(.+)$/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 654 | 1 | my $path = $1; | |||||||||||||||||||||||||||||||
| 655 | 1 | my @values = _traverse($context, $path); | |||||||||||||||||||||||||||||||
| 656 | 1 | ▶ | return @values ? $values[0] : undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||
| 659 | 0 | my @outputs = $self->run_query(_encode_json($context), $clean); | |||||||||||||||||||||||||||||||
| 660 | 0 | ▶ | return @outputs ? $outputs[0] : undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||
| 663 | 26 | ▶ | sub _set_value_at_path { | ||||||||||||||||||||||||||||||
|
Subroutine
_set_value_at_path: called CC=10 SCAR=23.5
| |||||||||||||||||||||||||||||||||
| 664 | 26 | my ($current, $path, $replacement) = @_; | |||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||
| 666 | 26 | ▶ | return _deep_clone($replacement) unless @$path; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||
| 668 | 26 | my ($segment, @rest) = @$path; | |||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||
| 670 | 26 | ▶ | if (ref $current eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 671 | 23 | my $key = _coerce_hash_key($segment); | |||||||||||||||||||||||||||||||
| 672 | 23 | ▶ | return $current unless defined $key; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||
| 674 | 23 | my %copy = %$current; | |||||||||||||||||||||||||||||||
| 675 | 23 | ▶ | if (@rest) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 676 | 12 | ▶ | my $next_value = exists $copy{$key} ? $copy{$key} : _guess_container_for_segment($rest[0]); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 677 | 12 | $copy{$key} = _set_value_at_path($next_value, \@rest, $replacement); | |||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||
| 679 | else { | ||||||||||||||||||||||||||||||||
| 680 | 11 | $copy{$key} = _deep_clone($replacement); | |||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||
| 683 | 23 | return \%copy; | |||||||||||||||||||||||||||||||
| 684 | } | ||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||
| 686 | 3 | ▶ | if (ref $current eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 687 | 1 | my $index = _normalize_array_index_for_set($segment, scalar @$current); | |||||||||||||||||||||||||||||||
| 688 | 1 | ▶ | return $current unless defined $index; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||
| 690 | 1 | my @copy = @$current; | |||||||||||||||||||||||||||||||
| 691 | 1 | _ensure_array_length(\@copy, $index); | |||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||
| 693 | 1 | ▶ | if (@rest) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 694 | 1 | ▶ | my $next_value = defined $copy[$index] ? $copy[$index] : _guess_container_for_segment($rest[0]); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 695 | 1 | $copy[$index] = _set_value_at_path($next_value, \@rest, $replacement); | |||||||||||||||||||||||||||||||
| 696 | } | ||||||||||||||||||||||||||||||||
| 697 | else { | ||||||||||||||||||||||||||||||||
| 698 | 0 | $copy[$index] = _deep_clone($replacement); | |||||||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||
| 701 | 1 | return \@copy; | |||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||
| 704 | 2 | my $container = _guess_container_for_segment($segment); | |||||||||||||||||||||||||||||||
| 705 | 2 | return _set_value_at_path($container, $path, $replacement); | |||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||
| 708 | 45 | ▶ | sub _coerce_hash_key { | ||||||||||||||||||||||||||||||
|
Subroutine
_coerce_hash_key: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||
| 709 | 45 | my ($segment) = @_; | |||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||
| 711 | 45 | ▶ | return undef if !defined $segment; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||
| 713 | 45 | ▶ | if (JSON::PP::is_bool($segment)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 714 | 4 | ▶ | return $segment ? 'true' : 'false'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||
| 717 | 41 | ▶ | return undef if ref $segment; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||||||
| 719 | 41 | return "$segment"; | |||||||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||
| 722 | 3 | ▶ | sub _guess_container_for_segment { | ||||||||||||||||||||||||||||||
|
Subroutine
_guess_container_for_segment: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||
| 723 | 3 | my ($segment) = @_; | |||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||
| 725 | 3 | ▶ | return [] if _is_numeric_segment($segment); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 726 | 3 | return {}; | |||||||||||||||||||||||||||||||
| 727 | } | ||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||
| 729 | 7 | ▶ | sub _is_numeric_segment { | ||||||||||||||||||||||||||||||
|
Subroutine
_is_numeric_segment: called CC=5 SCAR=16.6
| |||||||||||||||||||||||||||||||||
| 730 | 7 | my ($segment) = @_; | |||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||
| 732 | 7 | ▶ | return 0 if !defined $segment; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||
| 734 | 7 | ▶ | if (JSON::PP::is_bool($segment)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 735 | 4 | return 1; | |||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||
| 738 | 3 | ▶ | return 0 if ref $segment; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||
| 740 | 3 | ▶ | return ($segment =~ /^-?\d+$/) ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||
| 743 | 1 | ▶ | sub _normalize_array_index_for_set { | ||||||||||||||||||||||||||||||
|
Subroutine
_normalize_array_index_for_set: called CC=8 SCAR=24.3
| |||||||||||||||||||||||||||||||||
| 744 | 1 | my ($segment, $length) = @_; | |||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||
| 746 | 1 | ▶ | return undef if !defined $segment; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||
| 748 | 1 | ▶ | if (JSON::PP::is_bool($segment)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 749 | 0 | ▶ | $segment = $segment ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 750 | } | ||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||
| 752 | 1 | ▶ | return undef if ref $segment; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 753 | 1 | ▶ | return undef if $segment !~ /^-?\d+$/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||
| 755 | 1 | my $index = int($segment); | |||||||||||||||||||||||||||||||
| 756 | 1 | ▶ | $index += $length if $index < 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||
| 758 | 1 | ▶ | return undef if $index < 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||
| 760 | 1 | return $index; | |||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||
| 763 | 6 | ▶ | sub _normalize_array_index_for_get { | ||||||||||||||||||||||||||||||
|
Subroutine
_normalize_array_index_for_get: called CC=8 SCAR=21.2
| |||||||||||||||||||||||||||||||||
| 764 | 6 | my ($segment, $length) = @_; | |||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||
| 766 | 6 | ▶ | return undef if !defined $segment; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||
| 768 | 6 | ▶ | if (JSON::PP::is_bool($segment)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 769 | 2 | ▶ | $segment = $segment ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||
| 772 | 6 | ▶ | return undef if ref $segment; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 773 | 6 | ▶ | return undef if $segment !~ /^-?\d+$/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||
| 775 | 6 | my $index = int($segment); | |||||||||||||||||||||||||||||||
| 776 | 6 | ▶ | $index += $length if $index < 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||
| 778 | 6 | ▶ | return undef if $index < 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||
| 780 | 6 | return $index; | |||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||
| 783 | 1 | ▶ | sub _ensure_array_length { | ||||||||||||||||||||||||||||||
|
Subroutine
_ensure_array_length: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 784 | 1 | my ($array_ref, $index) = @_; | |||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||
| 786 | 1 | ▶ | return unless ref $array_ref eq 'ARRAY'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||
| 788 | 1 | ▶ | while (@$array_ref <= $index) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 789 | 1 | push @$array_ref, undef; | |||||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||||||
| 791 | } | ||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||
| 793 | 8 | ▶ | sub _collect_paths { | ||||||||||||||||||||||||||||||
|
Subroutine
_collect_paths: called CC=9 SCAR=22.5
| |||||||||||||||||||||||||||||||||
| 794 | 8 | my ($value, $current_path, $paths) = @_; | |||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||
| 796 | 8 | ▶ | if (ref $value eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 797 | 6 | for my $key (sort keys %$value) { | |||||||||||||||||||||||||||||||
| 798 | 11 | my $child = $value->{$key}; | |||||||||||||||||||||||||||||||
| 799 | 11 | my @next = (@$current_path, $key); | |||||||||||||||||||||||||||||||
| 800 | 11 | push @$paths, [@next]; | |||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||
| 802 | 11 | ▶ | if (ref $child eq 'HASH' || ref $child eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $child eq "HASH" or ref $child eq "ARRAY"
MC/DC100%2/2
ref $child eq "HASH" or ref $child eq "ARRAY"
ref $child eq "HASH"
ref $child eq "ARRAY"
Truth table100%3/3
A or B
A= ref $child eq "HASH"B= ref $child eq "ARRAY"
| |||||||||||||||||||||||||||||||||
| 803 | 5 | _collect_paths($child, \@next, $paths); | |||||||||||||||||||||||||||||||
| 804 | } | ||||||||||||||||||||||||||||||||
| 805 | } | ||||||||||||||||||||||||||||||||
| 806 | 6 | return; | |||||||||||||||||||||||||||||||
| 807 | } | ||||||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||||||
| 809 | 2 | ▶ | if (ref $value eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 810 | 2 | for my $index (0 .. $#$value) { | |||||||||||||||||||||||||||||||
| 811 | 4 | my $child = $value->[$index]; | |||||||||||||||||||||||||||||||
| 812 | 4 | my @next = (@$current_path, $index); | |||||||||||||||||||||||||||||||
| 813 | 4 | push @$paths, [@next]; | |||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||
| 815 | 4 | ▶ | if (ref $child eq 'HASH' || ref $child eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $child eq "HASH" or ref $child eq "ARRAY"
MC/DC0%0/2
ref $child eq "HASH" or ref $child eq "ARRAY"
ref $child eq "HASH"
ref $child eq "ARRAY"
Truth table33%1/3
A or B
A= ref $child eq "HASH"B= ref $child eq "ARRAY"
| |||||||||||||||||||||||||||||||||
| 816 | 0 | _collect_paths($child, \@next, $paths); | |||||||||||||||||||||||||||||||
| 817 | } | ||||||||||||||||||||||||||||||||
| 818 | } | ||||||||||||||||||||||||||||||||
| 819 | 2 | return; | |||||||||||||||||||||||||||||||
| 820 | } | ||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||
| 822 | 0 | push @$paths, [@$current_path]; | |||||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||
| 825 | 3 | ▶ | sub _collect_scalar_paths { | ||||||||||||||||||||||||||||||
|
Subroutine
_collect_scalar_paths: called CC=11 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 826 | 3 | my ($value, $current_path, $paths) = @_; | |||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||
| 828 | 3 | ▶ | if (ref $value eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 829 | 2 | for my $key (sort keys %$value) { | |||||||||||||||||||||||||||||||
| 830 | 3 | my $child = $value->{$key}; | |||||||||||||||||||||||||||||||
| 831 | 3 | my @next = (@$current_path, $key); | |||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||
| 833 | 3 | ▶ | if (_is_scalar_value($child)) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 834 | 2 | push @$paths, [@next]; | |||||||||||||||||||||||||||||||
| 835 | } | ||||||||||||||||||||||||||||||||
| 836 | ▶ | elsif (ref $child eq 'HASH' || ref $child eq 'ARRAY') { | |||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $child eq "HASH" or ref $child eq "ARRAY"
MC/DC0%0/2
ref $child eq "HASH" or ref $child eq "ARRAY"
ref $child eq "HASH"
ref $child eq "ARRAY"
Truth table33%1/3
A or B
A= ref $child eq "HASH"B= ref $child eq "ARRAY"
| |||||||||||||||||||||||||||||||||
| 837 | 1 | _collect_scalar_paths($child, \@next, $paths); | |||||||||||||||||||||||||||||||
| 838 | } | ||||||||||||||||||||||||||||||||
| 839 | } | ||||||||||||||||||||||||||||||||
| 840 | 2 | return; | |||||||||||||||||||||||||||||||
| 841 | } | ||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||
| 843 | 1 | ▶ | if (ref $value eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 844 | 1 | for my $index (0 .. $#$value) { | |||||||||||||||||||||||||||||||
| 845 | 2 | my $child = $value->[$index]; | |||||||||||||||||||||||||||||||
| 846 | 2 | my @next = (@$current_path, $index); | |||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||
| 848 | 2 | ▶ | if (_is_scalar_value($child)) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 849 | 1 | push @$paths, [@next]; | |||||||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||||||
| 851 | ▶ | elsif (ref $child eq 'HASH' || ref $child eq 'ARRAY') { | |||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $child eq "HASH" or ref $child eq "ARRAY"
MC/DC0%0/2
ref $child eq "HASH" or ref $child eq "ARRAY"
ref $child eq "HASH"
ref $child eq "ARRAY"
Truth table33%1/3
A or B
A= ref $child eq "HASH"B= ref $child eq "ARRAY"
| |||||||||||||||||||||||||||||||||
| 852 | 1 | _collect_scalar_paths($child, \@next, $paths); | |||||||||||||||||||||||||||||||
| 853 | } | ||||||||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||||||
| 855 | 1 | return; | |||||||||||||||||||||||||||||||
| 856 | } | ||||||||||||||||||||||||||||||||
| 857 | } | ||||||||||||||||||||||||||||||||
| 858 | |||||||||||||||||||||||||||||||||
| 859 | 20 | ▶ | sub _traverse_path_array { | ||||||||||||||||||||||||||||||
|
Subroutine
_traverse_path_array: called CC=12 SCAR=25.4
| |||||||||||||||||||||||||||||||||
| 860 | 20 | my ($value, $path) = @_; | |||||||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||||||
| 862 | 20 | ▶ | return undef unless defined $value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 863 | 20 | ▶ | return $value unless defined $path; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 864 | 20 | ▶ | return $value if ref($path) ne 'ARRAY'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||
| 866 | 20 | my $cursor = $value; | |||||||||||||||||||||||||||||||
| 867 | 20 | for my $segment (@$path) { | |||||||||||||||||||||||||||||||
| 868 | 25 | ▶ | return undef unless defined $cursor; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||
| 870 | 25 | ▶ | if (ref $cursor eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 871 | 18 | my $key = _coerce_hash_key($segment); | |||||||||||||||||||||||||||||||
| 872 | 18 | ▶ | return undef unless defined $key; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 873 | 18 | ▶ | return undef unless exists $cursor->{$key}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 874 | 17 | $cursor = $cursor->{$key}; | |||||||||||||||||||||||||||||||
| 875 | 17 | next; | |||||||||||||||||||||||||||||||
| 876 | } | ||||||||||||||||||||||||||||||||
| 877 | |||||||||||||||||||||||||||||||||
| 878 | 7 | ▶ | if (ref $cursor eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 879 | 6 | my $index = _normalize_array_index_for_get($segment, scalar @$cursor); | |||||||||||||||||||||||||||||||
| 880 | 6 | ▶ | return undef unless defined $index; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||
| 882 | 6 | ▶ | return undef if $index > $#$cursor; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||
| 884 | 6 | $cursor = $cursor->[$index]; | |||||||||||||||||||||||||||||||
| 885 | 6 | next; | |||||||||||||||||||||||||||||||
| 886 | } | ||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||
| 888 | 1 | return undef; | |||||||||||||||||||||||||||||||
| 889 | } | ||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||
| 891 | 18 | return $cursor; | |||||||||||||||||||||||||||||||
| 892 | } | ||||||||||||||||||||||||||||||||
| 893 | |||||||||||||||||||||||||||||||||
| 894 | 9 | ▶ | sub _collect_leaf_paths { | ||||||||||||||||||||||||||||||
|
Subroutine
_collect_leaf_paths: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||
| 895 | 9 | my ($value, $current_path, $paths) = @_; | |||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||
| 897 | 9 | ▶ | if (ref $value eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 898 | 5 | for my $key (sort keys %$value) { | |||||||||||||||||||||||||||||||
| 899 | 7 | my $child = $value->{$key}; | |||||||||||||||||||||||||||||||
| 900 | 7 | my @next = (@$current_path, $key); | |||||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||||||
| 902 | 7 | ▶ | if (_is_leaf_value($child)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 903 | 3 | push @$paths, [@next]; | |||||||||||||||||||||||||||||||
| 904 | } | ||||||||||||||||||||||||||||||||
| 905 | else { | ||||||||||||||||||||||||||||||||
| 906 | 4 | _collect_leaf_paths($child, \@next, $paths); | |||||||||||||||||||||||||||||||
| 907 | } | ||||||||||||||||||||||||||||||||
| 908 | } | ||||||||||||||||||||||||||||||||
| 909 | 5 | return; | |||||||||||||||||||||||||||||||
| 910 | } | ||||||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||||||
| 912 | 4 | ▶ | if (ref $value eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 913 | 4 | for my $index (0 .. $#$value) { | |||||||||||||||||||||||||||||||
| 914 | 6 | my $child = $value->[$index]; | |||||||||||||||||||||||||||||||
| 915 | 6 | my @next = (@$current_path, $index); | |||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||
| 917 | 6 | ▶ | if (_is_leaf_value($child)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 918 | 5 | push @$paths, [@next]; | |||||||||||||||||||||||||||||||
| 919 | } | ||||||||||||||||||||||||||||||||
| 920 | else { | ||||||||||||||||||||||||||||||||
| 921 | 1 | _collect_leaf_paths($child, \@next, $paths); | |||||||||||||||||||||||||||||||
| 922 | } | ||||||||||||||||||||||||||||||||
| 923 | } | ||||||||||||||||||||||||||||||||
| 924 | 4 | return; | |||||||||||||||||||||||||||||||
| 925 | } | ||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||
| 927 | 0 | push @$paths, [@$current_path]; | |||||||||||||||||||||||||||||||
| 928 | } | ||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||
| 930 | 27 | ▶ | sub _is_leaf_value { | ||||||||||||||||||||||||||||||
|
Subroutine
_is_leaf_value: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||
| 931 | 27 | my ($value) = @_; | |||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||
| 933 | 27 | ▶ | return 1 unless ref $value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 934 | 17 | ▶ | return 1 if JSON::PP::is_bool($value); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 935 | 12 | ▶ | return 0 if ref($value) eq 'ARRAY'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 936 | 7 | ▶ | return 0 if ref($value) eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 937 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 938 | } | ||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||
| 940 | 8 | ▶ | sub _is_scalar_value { | ||||||||||||||||||||||||||||||
|
Subroutine
_is_scalar_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 941 | 8 | return _is_leaf_value(@_); | |||||||||||||||||||||||||||||||
| 942 | } | ||||||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||||||
| 944 | 182 | 1; | |||||||||||||||||||||||||||||||