| 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 | 182 | ▶ | use Encode qw(encode is_utf8); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 182 | ▶ | use JQ::Lite::Expression (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 182 | our $JSON_DECODER = _build_json_decoder(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 182 | our $FROMJSON_DECODER = _build_json_decoder(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 182 | our $TOJSON_ENCODER = JSON::PP->new->utf8->allow_nonref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 364 | ▶ | sub _build_json_decoder { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_json_decoder: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 364 | my $decoder = JSON::PP->new->utf8->allow_nonref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 364 | ▶ | if ($decoder->can('boolean_values')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 364 | $decoder->boolean_values(JSON::PP::false, JSON::PP::true); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 364 | return $decoder; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 245 | ▶ | sub _encode_json { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_json: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 245 | my ($value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 245 | return $TOJSON_ENCODER->encode($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 7113 | ▶ | sub _decode_json { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_json: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 7113 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 7113 | ▶ | if (defined $text && is_utf8($text, 1)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $text and &is_utf8($text, 1)
MC/DC50%1/2
defined $text and &is_utf8($text, 1)
defined $text
&is_utf8($text, 1)
Truth table66%2/3
A and B
A= defined $textB= &is_utf8($text, 1)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | $text = encode('UTF-8', $text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 7113 | return $JSON_DECODER->decode($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 45 | ▶ | sub _are_brackets_balanced { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_are_brackets_balanced: called CC=15 SCAR=28.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 45 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 45 | ▶ | return 1 unless defined $text && length $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $text and length $text
MC/DC0%0/2
defined $text and length $text
defined $text
length $text
Truth table33%1/3
A and B
A= defined $textB= length $text
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 45 | my %pairs = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | '(' => ')', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | '[' => ']', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | '{' => '}', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 45 | my %closing = reverse %pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 45 | my @stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | my $string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 45 | my $escape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 45 | for my $char (split //, $text) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 460 | ▶ | if (defined $string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 27 | ▶ | if ($escape) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $escape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 27 | ▶ | if ($char eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $escape = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 27 | ▶ | if ($char eq $string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 6 | undef $string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 27 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 433 | ▶ | if ($char eq "'" || $char eq '"') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$char eq "'" or $char eq "\""
MC/DC50%1/2
$char eq "'" or $char eq "\""
$char eq "'"
$char eq "\""
Truth table66%2/3
A or B
A= $char eq "'"B= $char eq "\""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 6 | $string = $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 427 | ▶ | if (exists $pairs{$char}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 10 | push @stack, $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 10 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 417 | ▶ | if (exists $closing{$char}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 24 | ▶ | return 0 unless @stack; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 10 | my $open = pop @stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 10 | ▶ | return 0 unless $pairs{$open} eq $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 10 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 31 | ▶ | return !@stack && !defined $string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
@stack || defined $string
MC/DC0%0/2
@stack || defined $string
@stack
defined $string
Truth table33%1/3
A || B
A= @stackB= defined $string
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 6667 | ▶ | sub _strip_wrapping_parens { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_strip_wrapping_parens: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 6667 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 6667 | ▶ | return '' unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 6667 | my $copy = $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 6667 | $copy =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 6667 | ▶ | while ($copy =~ /^\((.*)\)$/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 45 | my $inner = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 45 | ▶ | last unless _are_brackets_balanced($inner); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 31 | $inner =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 31 | $copy = $inner; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 6667 | return $copy; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 8 | ▶ | sub _split_top_level_semicolons { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split_top_level_semicolons: called CC=16 SCAR=32.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 8 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 8 | ▶ | return unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 8 | my %pairs = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | '(' => ')', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | '[' => ']', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | '{' => '}', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 8 | my %closing = reverse %pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 8 | my @stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | my $string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 8 | my $escape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 8 | my @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 8 | my $start = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 8 | ▶ | for (my $i = 0; $i < length $text; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 103 | my $char = substr($text, $i, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 103 | ▶ | if (defined $string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | ▶ | if ($escape) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $escape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | ▶ | if ($char eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $escape = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | ▶ | if ($char eq $string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | undef $string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 102 | ▶ | if ($char eq "'" || $char eq '"') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$char eq "'" or $char eq "\""
MC/DC50%1/2
$char eq "'" or $char eq "\""
$char eq "'"
$char eq "\""
Truth table66%2/3
A or B
A= $char eq "'"B= $char eq "\""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | $string = $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 101 | ▶ | if (exists $pairs{$char}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | push @stack, $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 101 | ▶ | if (exists $closing{$char}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | return unless @stack; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | my $open = pop @stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | return unless $pairs{$open} eq $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 101 | ▶ | next unless $char eq ';'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 9 | ▶ | if (!@stack) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 9 | my $chunk = substr($text, $start, $i - $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 9 | push @parts, $chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 9 | $start = $i + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 8 | ▶ | push @parts, substr($text, $start) if $start <= length $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 8 | return @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 3015 | ▶ | sub _split_top_level_pipes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split_top_level_pipes: called CC=26 SCAR=32.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 3015 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 3015 | ▶ | return unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 3015 | my %pairs = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | '(' => ')', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | '[' => ']', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | '{' => '}', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 3015 | my %closing = reverse %pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 3015 | my @stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | my $string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 3015 | my $escape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 3015 | my @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 3015 | my $start = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 3015 | my $length = length $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 3015 | my $in_try = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 3015 | ▶ | for (my $i = 0; $i < $length; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 40546 | my $char = substr($text, $i, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 40546 | ▶ | if (defined $string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 3163 | ▶ | if ($escape) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 14 | $escape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 14 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 3149 | ▶ | if ($char eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 14 | $escape = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 14 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 3135 | ▶ | if ($char eq $string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 670 | undef $string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 3135 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 37383 | ▶ | if ($char eq "'" || $char eq '"') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$char eq "'" or $char eq "\""
MC/DC100%2/2
$char eq "'" or $char eq "\""
$char eq "'"
$char eq "\""
Truth table100%3/3
A or B
A= $char eq "'"B= $char eq "\""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 670 | $string = $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 670 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 36713 | ▶ | if (exists $pairs{$char}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 1610 | push @stack, $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 1610 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 35103 | ▶ | if (!$in_try && !@stack && !defined $string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$in_try or @stack or defined $string
$in_try or @stack
MC/DC66%2/3
$in_try or @stack or defined $string
$in_try
@stack
defined $string
Truth table75%3/4
A or B or C
A= $in_tryB= @stackC= defined $string
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 28567 | ▶ | if (substr($text, $i) =~ /^try\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 28 | $in_try = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 28 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 35075 | ▶ | if ($in_try && !@stack && !defined $string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$in_try and not @stack and not defined $string
$in_try and not @stack
MC/DC66%2/3
$in_try and not @stack and not defined $string
$in_try
not @stack
not defined $string
Truth table75%3/4
A and not(B) and not(C)
A= $in_tryB= not @stackC= not defined $string
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 202 | ▶ | if (substr($text, $i) =~ /^catch\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 20 | $in_try = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 20 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 35055 | ▶ | if (exists $closing{$char}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 1610 | ▶ | return unless @stack; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 1610 | my $open = pop @stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1610 | ▶ | return unless $pairs{$open} eq $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 1610 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 33445 | ▶ | next unless $char eq '|'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1004 | ▶ | next if $in_try; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1000 | ▶ | if (substr($text, $i, 2) eq '||') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1000 | ▶ | if (!@stack) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 984 | my $chunk = substr($text, $start, $i - $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 984 | push @parts, $chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 984 | $start = $i + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 3015 | ▶ | push @parts, substr($text, $start) if $start <= $length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 3015 | return @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 4688 | ▶ | sub _split_top_level_commas { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split_top_level_commas: called CC=16 SCAR=27.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 4688 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 4688 | ▶ | return unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 4688 | my %pairs = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | '(' => ')', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | '[' => ']', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | '{' => '}', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 4688 | my %closing = reverse %pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 4688 | my @stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | my $string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 4688 | my $escape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 4688 | my @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 4688 | my $start = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 4688 | ▶ | for (my $i = 0; $i < length $text; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 49708 | my $char = substr($text, $i, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 49708 | ▶ | if (defined $string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 4788 | ▶ | if ($escape) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 20 | $escape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 20 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 4768 | ▶ | if ($char eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 20 | $escape = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 20 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 4748 | ▶ | if ($char eq $string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 986 | undef $string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 4748 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 44920 | ▶ | if ($char eq "'" || $char eq '"') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$char eq "'" or $char eq "\""
MC/DC100%2/2
$char eq "'" or $char eq "\""
$char eq "'"
$char eq "\""
Truth table100%3/3
A or B
A= $char eq "'"B= $char eq "\""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 986 | $string = $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 986 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 43934 | ▶ | if (exists $pairs{$char}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 2267 | push @stack, $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 2267 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 41667 | ▶ | if (exists $closing{$char}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 2267 | ▶ | return unless @stack; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 2267 | my $open = pop @stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 2267 | ▶ | return unless $pairs{$open} eq $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 2267 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 39400 | ▶ | next unless $char eq ','; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 386 | ▶ | if (!@stack) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 83 | my $chunk = substr($text, $start, $i - $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 83 | push @parts, $chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 83 | $start = $i + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 4688 | ▶ | push @parts, substr($text, $start) if $start <= length $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 4688 | return @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 2116 | ▶ | sub _split_top_level_operator { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split_top_level_operator: called CC=24 SCAR=32.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 2116 | my ($text, $operator) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 2116 | ▶ | return unless defined $text && defined $operator && length($operator) == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $text and defined $operator and length $operator == 1
defined $text and defined $operator
MC/DC0%0/3
defined $text and defined $operator and length $operator == 1
defined $text
defined $operator
length $operator == 1
Truth table25%1/4
A and B and C
A= defined $textB= defined $operatorC= length $operator == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 2116 | my %pairs = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | '(' => ')', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | '[' => ']', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | '{' => '}', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 2116 | my %closing = reverse %pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 2116 | my @stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | my $string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 2116 | my $escape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 2116 | ▶ | for (my $i = 0; $i < length $text; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 18332 | my $char = substr($text, $i, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 18332 | ▶ | if (defined $string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 1574 | ▶ | if ($escape) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 6 | $escape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 1568 | ▶ | if ($char eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 6 | $escape = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 1562 | ▶ | if ($char eq $string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 340 | undef $string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 1562 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 16758 | ▶ | if ($char eq "'" || $char eq '"') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$char eq "'" or $char eq "\""
MC/DC100%2/2
$char eq "'" or $char eq "\""
$char eq "'"
$char eq "\""
Truth table100%3/3
A or B
A= $char eq "'"B= $char eq "\""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 340 | $string = $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 340 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 16418 | ▶ | if (exists $pairs{$char}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 781 | push @stack, $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 781 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 15637 | ▶ | if (exists $closing{$char}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 781 | ▶ | return if !@stack; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 781 | my $open = pop @stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 781 | ▶ | return if $pairs{$open} ne $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 781 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 14856 | ▶ | next if $char ne $operator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 74 | ▶ | if (!@stack) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 56 | ▶ | if ($operator eq '+' || $operator eq '-') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$operator eq "+" or $operator eq "-"
MC/DC0%0/2
$operator eq "+" or $operator eq "-"
$operator eq "+"
$operator eq "-"
Truth table33%1/3
A or B
A= $operator eq "+"B= $operator eq "-"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 56 | ▶ | my $prev = $i > 0 ? substr($text, $i - 1, 1) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 56 | ▶ | my $next = $i + 1 < length $text ? substr($text, $i + 1, 1) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 56 | ▶ | if ($prev =~ /[eE]/ && $next =~ /[0-9]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$prev =~ /[eE]/ and $next =~ /[0-9]/
MC/DC0%0/2
$prev =~ /[eE]/ and $next =~ /[0-9]/
$prev =~ /[eE]/
$next =~ /[0-9]/
Truth table33%1/3
A and B
A= $prev =~ /[eE]/B= $next =~ /[0-9]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 56 | ▶ | if ($next eq '=') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 54 | my $lhs = substr($text, 0, $i); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 54 | my $rhs = substr($text, $i + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 54 | return ($lhs, $rhs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 2062 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 1481 | ▶ | sub _split_top_level_comparison { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split_top_level_comparison: called CC=19 SCAR=29.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 1481 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 1481 | ▶ | return unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 1481 | my %close = ('(' => ')', '[' => ']', '{' => '}'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 1481 | my %open = reverse %close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 1481 | my (@stack, $quote, $escape, @comparison); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 1481 | ▶ | for (my $i = 0; $i < length($text); $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 14723 | my $char = substr($text, $i, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 14723 | ▶ | if (defined $quote) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 1466 | ▶ | if ($escape) { $escape = 0; next; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 1460 | ▶ | if ($char eq '\\') { $escape = 1; next; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 1454 | ▶ | undef $quote if $char eq $quote; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 1454 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 13257 | ▶ | if ($char eq q{"} || $char eq q{'}) { $quote = $char; next; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$char eq "\"" or $char eq "'"
MC/DC100%2/2
$char eq "\"" or $char eq "'"
$char eq "\""
$char eq "'"
Truth table100%3/3
A or B
A= $char eq "\""B= $char eq "'"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 12953 | ▶ | if (exists $close{$char}) { push @stack, $char; next; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 12245 | ▶ | if (exists $open{$char}) { pop @stack if @stack; next; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 11537 | ▶ | next if @stack; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 9413 | my $tail = substr($text, $i); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 9413 | ▶ | my $previous = $i > 0 ? substr($text, $i - 1, 1) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 9413 | ▶ | if (($i == 0 || $previous =~ /\s/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$i == 0 || $previous =~ /\s/ and $tail =~ /^(?:and|or)(?=\s|$)/
$i == 0 or $previous =~ /\s/
MC/DC66%2/3
$i == 0 || $previous =~ /\s/ and $tail =~ /^(?:and|or)(?=\s|$)/
$i == 0
$previous =~ /\s/
$tail =~ /^(?:and|or)(?=\s|$)/
Truth table80%4/5
A or B and C
A= $i == 0B= $previous =~ /\s/C= $tail =~ /^(?:and|or)(?=\s|$)/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | && $tail =~ /^(?:and|or)(?=\s|$)/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | # Compound boolean expressions are handled by the condition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | # evaluator, which applies jq's logical precedence. Splitting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | # only their first comparison would make the rest an operand. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 9 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 9404 | ▶ | if (!@comparison && $tail =~ /^(==|!=|>=|<=|>|<)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not @comparison and $tail =~ /^(==|!=|>=|<=|>|<)/
MC/DC100%2/2
not @comparison and $tail =~ /^(==|!=|>=|<=|>|<)/
not @comparison
$tail =~ /^(==|!=|>=|<=|>|<)/
Truth table100%3/3
not(A) and B
A= not @comparisonB= $tail =~ /^(==|!=|>=|<=|>|<)/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 48 | my $operator = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 48 | @comparison = (substr($text, 0, $i), $operator, substr($text, $i + length($operator))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 1472 | return @comparison; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 165 | ▶ | sub _split_top_level_keyword { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split_top_level_keyword: called CC=22 SCAR=33.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 165 | my ($text, $keyword) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 165 | ▶ | return ($text) unless defined $text && defined $keyword && length $keyword; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $text and defined $keyword and length $keyword
defined $text and defined $keyword
MC/DC0%0/3
defined $text and defined $keyword and length $keyword
defined $text
defined $keyword
length $keyword
Truth table25%1/4
A and B and C
A= defined $textB= defined $keywordC= length $keyword
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 165 | my %close = ('(' => ')', '[' => ']', '{' => '}'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 165 | my %open = reverse %close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 165 | my (@stack, $quote, $escape, @parts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 165 | my $start = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 165 | ▶ | for (my $i = 0; $i < length($text); $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 1988 | my $char = substr($text, $i, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 1988 | ▶ | if (defined $quote) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | if ($escape) { $escape = 0; next; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | ▶ | if ($char eq '\\') { $escape = 1; next; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 248 | ▶ | undef $quote if $char eq $quote; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 248 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 1740 | ▶ | if ($char eq q{"} || $char eq q{'}) { $quote = $char; next; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$char eq "\"" or $char eq "'"
MC/DC50%1/2
$char eq "\"" or $char eq "'"
$char eq "\""
$char eq "'"
Truth table66%2/3
A or B
A= $char eq "\""B= $char eq "'"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 1686 | ▶ | if (exists $close{$char}) { push @stack, $char; next; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 1664 | ▶ | if (exists $open{$char}) { pop @stack if @stack; next; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 1642 | ▶ | next if @stack; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 1550 | ▶ | my $before = $i > 0 ? substr($text, $i - 1, 1) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 1550 | my $after_pos = $i + length($keyword); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 1550 | ▶ | my $after = $after_pos < length($text) ? substr($text, $after_pos, 1) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 1550 | ▶ | next unless substr($text, $i, length($keyword)) eq $keyword; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 10 | ▶ | next unless ($i == 0 || $before =~ /\s/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$i == 0 or $before =~ /\s/
MC/DC0%0/2
$i == 0 or $before =~ /\s/
$i == 0
$before =~ /\s/
Truth table33%1/3
A or B
A= $i == 0B= $before =~ /\s/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 10 | ▶ | next unless ($after_pos == length($text) || $after =~ /\s/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$after_pos == length $text or $after =~ /\s/
MC/DC0%0/2
$after_pos == length $text or $after =~ /\s/
$after_pos == length $text
$after =~ /\s/
Truth table33%1/3
A or B
A= $after_pos == length $textB= $after =~ /\s/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 10 | push @parts, substr($text, $start, $i - $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 10 | $start = $after_pos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 10 | $i = $after_pos - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 165 | push @parts, substr($text, $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 165 | return @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 58 | ▶ | sub _split_top_level_colon { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split_top_level_colon: called CC=15 SCAR=31.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 58 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 58 | ▶ | return unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 58 | my %pairs = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | '(' => ')', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | '[' => ']', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | '{' => '}', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 58 | my %closing = reverse %pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 58 | my @stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | my $string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 58 | my $escape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 58 | ▶ | for (my $i = 0; $i < length $text; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 363 | my $char = substr($text, $i, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 363 | ▶ | if (defined $string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 151 | ▶ | if ($escape) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | $escape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 151 | ▶ | if ($char eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | $escape = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 151 | ▶ | if ($char eq $string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 29 | undef $string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 151 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 212 | ▶ | if ($char eq "'" || $char eq '"') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$char eq "'" or $char eq "\""
MC/DC50%1/2
$char eq "'" or $char eq "\""
$char eq "'"
$char eq "\""
Truth table66%2/3
A or B
A= $char eq "'"B= $char eq "\""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 29 | $string = $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 29 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 183 | ▶ | if (exists $pairs{$char}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | push @stack, $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 183 | ▶ | if (exists $closing{$char}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | ▶ | return unless @stack; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | my $open = pop @stack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | ▶ | return unless $pairs{$open} eq $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 183 | ▶ | next if $char ne ':'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 54 | ▶ | if (!@stack) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 54 | my $lhs = substr($text, 0, $i); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 54 | my $rhs = substr($text, $i + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 54 | return ($lhs, $rhs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 16 | ▶ | sub _interpret_object_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_interpret_object_key: called CC=6 SCAR=19.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 16 | my ($raw) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 16 | ▶ | return unless defined $raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 16 | my $text = $raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 16 | $text =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 16 | ▶ | return if $text eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 16 | my $decoded = eval { $FROMJSON_DECODER->decode($text) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 16 | ▶ | if (!$@ && !ref $decoded) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$@ or ref $decoded
MC/DC50%1/2
$@ or ref $decoded
$@
ref $decoded
Truth table66%2/3
A or B
A= $@B= ref $decoded
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 3 | return $decoded; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 13 | ▶ | if ($text =~ /^'(.*)'$/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | my $inner = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | $inner =~ s/\\'/'/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | return $inner; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 13 | return $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | ▶ | sub _split_top_level_semicolon { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split_top_level_semicolon: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | my @parts = _split_top_level_semicolons($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | ▶ | return unless @parts == 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | return @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 2202 | ▶ | sub _matches_keyword { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_matches_keyword: called CC=9 SCAR=22.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 2202 | my ($text, $pos, $keyword) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 2202 | ▶ | return 0 unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 2202 | ▶ | return 0 if $pos < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 2202 | my $kw_len = length $keyword; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 2202 | ▶ | return 0 if $pos + $kw_len > length $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 2172 | ▶ | return 0 if substr($text, $pos, $kw_len) ne $keyword; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 49 | ▶ | my $before = $pos == 0 ? '' : substr($text, $pos - 1, 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 49 | ▶ | my $after = ($pos + $kw_len) < length $text ? substr($text, $pos + $kw_len, 1) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 49 | ▶ | return 0 if $before =~ /[A-Za-z0-9_]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 49 | ▶ | return 0 if $after =~ /[A-Za-z0-9_]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 49 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 1362 | ▶ | sub _parse_if_expression { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_if_expression: called CC=47 SCAR=44.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 1362 | my ($expr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 1362 | ▶ | return undef unless defined $expr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 1362 | my $copy = _strip_wrapping_parens($expr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 1362 | $copy =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 1362 | ▶ | return undef unless $copy =~ /^if\b/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 10 | my $len = length $copy; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 10 | my $pos = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 10 | ▶ | return undef unless _matches_keyword($copy, $pos, 'if'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 10 | $pos += 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 10 | my $depth = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 10 | my $state = 'condition'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 10 | my $current = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 10 | my $condition; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | my @branches; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 10 | my $else_expr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 10 | my $in_single = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 10 | my $in_double = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 10 | my $escape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 10 | ▶ | while ($pos < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 353 | my $char = substr($copy, $pos, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 353 | ▶ | if ($escape) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | $current .= $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | $escape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 353 | ▶ | if ($in_single) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | ▶ | if ($char eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | $escape = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | elsif ($char eq "'") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | $in_single = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | $current .= $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 353 | ▶ | if ($in_double) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 43 | ▶ | if ($char eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | $escape = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | elsif ($char eq '"') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 16 | $in_double = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 43 | $current .= $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 43 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 43 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 310 | ▶ | if ($char eq "'") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | $in_single = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | $current .= $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 310 | ▶ | if ($char eq '"') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 16 | $in_double = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 16 | $current .= $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 16 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 16 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 294 | ▶ | if (_matches_keyword($copy, $pos, 'if')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 1 | $depth++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 1 | $current .= 'if'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 1 | $pos += 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 293 | ▶ | if (_matches_keyword($copy, $pos, 'then') && $depth == 1 && $state eq 'condition') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
_matches_keyword($copy, $pos, "then") and $depth == 1 and $state eq "condition"
_matches_keyword($copy, $pos, "then") and $depth == 1
MC/DC66%2/3
_matches_keyword($copy, $pos, "then") and $depth == 1 and $state eq "condition"
_matches_keyword($copy, $pos, "then")
$depth == 1
$state eq "condition"
Truth table75%3/4
A and B and C
A= _matches_keyword($copy, $pos, "then")B= $depth == 1C= $state eq "condition"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 12 | $condition = $current; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 12 | $condition =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 12 | ▶ | return undef unless defined $condition && length $condition; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $condition and length $condition
MC/DC0%0/2
defined $condition and length $condition
defined $condition
length $condition
Truth table33%1/3
A and B
A= defined $conditionB= length $condition
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 12 | $current = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 12 | $state = 'then'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 12 | $pos += 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 12 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 281 | ▶ | if (_matches_keyword($copy, $pos, 'elif') && $depth == 1 && $state eq 'then') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
_matches_keyword($copy, $pos, "elif") and $depth == 1 and $state eq "then"
_matches_keyword($copy, $pos, "elif") and $depth == 1
MC/DC33%1/3
_matches_keyword($copy, $pos, "elif") and $depth == 1 and $state eq "then"
_matches_keyword($copy, $pos, "elif")
$depth == 1
$state eq "then"
Truth table50%2/4
A and B and C
A= _matches_keyword($copy, $pos, "elif")B= $depth == 1C= $state eq "then"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 2 | my $then_expr = $current; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 2 | $then_expr =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 2 | ▶ | $then_expr = '.' if !length $then_expr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 2 | ▶ | return undef unless defined $condition; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 2 | push @branches, { condition => $condition, then => $then_expr }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 2 | $condition = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 2 | $current = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 2 | $state = 'condition'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 2 | $pos += 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 279 | ▶ | if (_matches_keyword($copy, $pos, 'else') && $depth == 1 && $state eq 'then') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
_matches_keyword($copy, $pos, "else") and $depth == 1 and $state eq "then"
_matches_keyword($copy, $pos, "else") and $depth == 1
MC/DC66%2/3
_matches_keyword($copy, $pos, "else") and $depth == 1 and $state eq "then"
_matches_keyword($copy, $pos, "else")
$depth == 1
$state eq "then"
Truth table75%3/4
A and B and C
A= _matches_keyword($copy, $pos, "else")B= $depth == 1C= $state eq "then"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 9 | my $then_expr = $current; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 9 | $then_expr =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 9 | ▶ | $then_expr = '.' if !length $then_expr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 9 | ▶ | return undef unless defined $condition; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 9 | push @branches, { condition => $condition, then => $then_expr }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 9 | $condition = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 9 | $current = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 9 | $state = 'else'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 9 | $pos += 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 9 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 270 | ▶ | if (_matches_keyword($copy, $pos, 'end')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 11 | ▶ | if ($depth == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 10 | ▶ | if ($state eq 'then') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 1 | my $then_expr = $current; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 1 | $then_expr =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 1 | ▶ | $then_expr = '.' if !length $then_expr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 1 | ▶ | return undef unless defined $condition; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 1 | push @branches, { condition => $condition, then => $then_expr }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | elsif ($state eq 'else') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 9 | my $else = $current; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 9 | $else =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 9 | ▶ | $else_expr = length $else ? $else : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | elsif ($state eq 'condition') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 10 | $depth = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 10 | $pos += 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 10 | $current = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 10 | $state = 'done'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 10 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 1 | $depth--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 1 | $current .= 'end'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 1 | $pos += 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 259 | ▶ | if (_matches_keyword($copy, $pos, 'then') && $depth > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
_matches_keyword($copy, $pos, "then") and $depth > 1
MC/DC50%1/2
_matches_keyword($copy, $pos, "then") and $depth > 1
_matches_keyword($copy, $pos, "then")
$depth > 1
Truth table66%2/3
A and B
A= _matches_keyword($copy, $pos, "then")B= $depth > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 1 | $current .= 'then'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 1 | $pos += 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 258 | ▶ | if (_matches_keyword($copy, $pos, 'elif') && $depth > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
_matches_keyword($copy, $pos, "elif") and $depth > 1
MC/DC0%0/2
_matches_keyword($copy, $pos, "elif") and $depth > 1
_matches_keyword($copy, $pos, "elif")
$depth > 1
Truth table33%1/3
A and B
A= _matches_keyword($copy, $pos, "elif")B= $depth > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 0 | $current .= 'elif'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | $pos += 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 258 | ▶ | if (_matches_keyword($copy, $pos, 'else') && $depth > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
_matches_keyword($copy, $pos, "else") and $depth > 1
MC/DC50%1/2
_matches_keyword($copy, $pos, "else") and $depth > 1
_matches_keyword($copy, $pos, "else")
$depth > 1
Truth table66%2/3
A and B
A= _matches_keyword($copy, $pos, "else")B= $depth > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 1 | $current .= 'else'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 1 | $pos += 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 257 | $current .= $char; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 257 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 10 | ▶ | return undef unless @branches; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 10 | ▶ | if ($pos < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | my $remaining = substr($copy, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 0 | $remaining =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 0 | ▶ | return undef if $remaining =~ /\S/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 10 | branches => \@branches, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | else => $else_expr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 1352 | ▶ | sub _parse_reduce_expression { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_reduce_expression: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 1352 | my ($expr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 1352 | ▶ | return undef unless defined $expr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 1352 | my $copy = _strip_wrapping_parens($expr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 1352 | ▶ | return undef unless $copy =~ /^reduce\s+(.+?)\s+as\s+\$(\w+)\s*\((.*)\)$/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 4 | my ($generator, $var_name, $body) = ($1, $2, $3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 4 | my @parts = _split_top_level_semicolons($body); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 4 | ▶ | return undef unless @parts == 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 4 | my ($init_expr, $update_expr) = @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 4 | $generator =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 4 | $init_expr =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 4 | $update_expr =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 4 | generator => $generator, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | var_name => $var_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | init_expr => $init_expr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | update_expr => $update_expr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 1366 | ▶ | sub _parse_foreach_expression { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_foreach_expression: called CC=8 SCAR=21.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 1366 | my ($expr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 1366 | ▶ | return undef unless defined $expr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 1366 | my $copy = _strip_wrapping_parens($expr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 1366 | ▶ | return undef unless $copy =~ /^foreach\s+(.+?)\s+as\s+\$(\w+)\s*\((.*)\)$/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 4 | my ($generator, $var_name, $body) = ($1, $2, $3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 4 | my @parts = _split_top_level_semicolons($body); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 4 | ▶ | return undef unless @parts >= 2 && @parts <= 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@parts >= 2 and @parts <= 3
MC/DC0%0/2
@parts >= 2 and @parts <= 3
@parts >= 2
@parts <= 3
Truth table33%1/3
A and B
A= @parts >= 2B= @parts <= 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 4 | my ($init_expr, $update_expr, $extract_expr) = @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 4 | for ($generator, $init_expr, $update_expr) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 12 | ▶ | next unless defined $_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 12 | s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 4 | ▶ | if (defined $extract_expr) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 1 | $extract_expr =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 4 | generator => $generator, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | var_name => $var_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | init_expr => $init_expr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | update_expr => $update_expr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | extract_expr => $extract_expr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 48 | ▶ | sub _resolve_variable_reference { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_variable_reference: called CC=7 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 48 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 48 | ▶ | return (undef, 0) unless defined $self && ref($self) eq 'JQ::Lite'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self and ref $self eq "JQ::Lite"
MC/DC0%0/2
defined $self and ref $self eq "JQ::Lite"
defined $self
ref $self eq "JQ::Lite"
Truth table33%1/3
A and B
A= defined $selfB= ref $self eq "JQ::Lite"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 48 | ▶ | return (undef, 0) unless defined $name && length $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $name and length $name
MC/DC0%0/2
defined $name and length $name
defined $name
length $name
Truth table33%1/3
A and B
A= defined $nameB= length $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 48 | ▶ | my $vars = $self->{_vars} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'_vars'} || {}
MC/DC0%0/1
$self->{'_vars'} || {}
$self->{'_vars'}
Truth table50%1/2
A
A= $self->{'_vars'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 48 | ▶ | return (undef, 0) unless exists $vars->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 47 | return ($vars->{$name}, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | 48 | ▶ | sub _evaluate_variable_reference { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_evaluate_variable_reference: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 48 | my ($self, $name, $suffix) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 48 | my ($value, $exists) = _resolve_variable_reference($self, $name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 48 | ▶ | return () unless $exists; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 47 | ▶ | return ($value) if !defined $suffix || $suffix !~ /\S/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $suffix and $suffix =~ /\S/
MC/DC50%1/2
defined $suffix and $suffix =~ /\S/
defined $suffix
$suffix =~ /\S/
Truth table66%2/3
A and B
A= defined $suffixB= $suffix =~ /\S/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 9 | my $expr = $suffix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 9 | $expr =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 9 | my ($values, $ok) = _evaluate_value_expression($self, $value, $expr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 9 | ▶ | return $ok ? @$values : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 901 | ▶ | sub _evaluate_value_expression { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_evaluate_value_expression: called CC=35 SCAR=38.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 901 | my ($self, $context, $expr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 901 | ▶ | return ([], 0) unless defined $expr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 901 | my $copy = _strip_wrapping_parens($expr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 901 | $copy =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 901 | ▶ | return ([], 0) if $copy eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 901 | ▶ | if (_looks_like_expression($copy)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | my %builtins = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 0 | ▶ | floor => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 0 | my ($value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 0 | my $numeric = _coerce_number_strict($value, 'floor() argument'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 0 | return _floor($numeric); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 0 | ▶ | ceil => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 0 | my ($value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 0 | my $numeric = _coerce_number_strict($value, 'ceil() argument'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 0 | return _ceil($numeric); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 0 | ▶ | round => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 0 | my ($value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 0 | my $numeric = _coerce_number_strict($value, 'round() argument'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 0 | return _round($numeric); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 1 | ▶ | tonumber => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | 1 | my ($value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 1 | return _tonumber($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 66 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | my ($ok, $value) = JQ::Lite::Expression::evaluate( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | expr => $copy, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | context => $context, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | 18 | ▶ | resolve_path => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=15.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 18 | my ($ctx, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 18 | ▶ | return $ctx if !defined $path || $path eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $path or $path eq ""
MC/DC0%0/2
not defined $path or $path eq ""
not defined $path
$path eq ""
Truth table33%1/3
not(A) or B
A= not defined $pathB= $path eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 18 | my @values = _traverse($ctx, $path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 18 | ▶ | return @values ? $values[0] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | 66 | coerce_number => \&_coerce_number_strict, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | builtins => \%builtins, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | 58 | ▶ | if ($ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 9 | return ([ $value ], 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 884 | my @pipeline_parts = _split_top_level_pipes($copy); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 884 | ▶ | if (@pipeline_parts > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 7 | ▶ | if (defined $self && $self->can('run_query')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/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 table33%1/3
A and B
A= defined $selfB= $self->can("run_query")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 7 | my $json = _encode_json($context); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 7 | my @outputs = $self->run_query($json, $copy); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 7 | return ([ @outputs ], 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 877 | ▶ | if ($copy =~ /^\$(\w+)(.*)$/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 32 | ▶ | my ($var, $suffix) = ($1, $2 // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$2 // ""
MC/DC0%0/1
$2 // ""
$2
Truth table50%1/2
A
A= $2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 32 | my @values = _evaluate_variable_reference($self, $var, $suffix); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 32 | return (\@values, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 845 | ▶ | if ($copy =~ /^\[(.*)$/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | 3 | $copy = ".$copy"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 845 | ▶ | if ($copy eq '.') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 38 | return ([ $context ], 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | 807 | ▶ | if ($copy =~ /^\.(.*)$/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | 155 | my $path = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 155 | $path =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 155 | my $is_bracket_slice = $path =~ /\[[^\]]*:[^\]]*\]/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 155 | ▶ | if (($path !~ /\s/ || $is_bracket_slice) && $path !~ /[+\-*\/]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
!($path =~ /\s/) || $is_bracket_slice and not $path =~ m[[+\-*/]]
not $path =~ /\s/ or $is_bracket_slice
MC/DC33%1/3
!($path =~ /\s/) || $is_bracket_slice and not $path =~ m[[+\-*/]]
not $path =~ /\s/
$is_bracket_slice
not $path =~ m[[+\-*/]]
Truth table40%2/5
not(A) or B and not(C)
A= not $path =~ /\s/B= $is_bracket_sliceC= not $path =~ m[[+\-*/]]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 100 | ▶ | return ([], 1) unless defined $context; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | 100 | ▶ | return ([], 1) if $path eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | 100 | my @values = _traverse($context, $path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | 100 | return (\@values, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 707 | my ($lhs_expr, $rhs_expr) = _split_top_level_operator($copy, '+'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 707 | ▶ | if (defined $lhs_expr && defined $rhs_expr) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $lhs_expr and defined $rhs_expr
MC/DC50%1/2
defined $lhs_expr and defined $rhs_expr
defined $lhs_expr
defined $rhs_expr
Truth table66%2/3
A and B
A= defined $lhs_exprB= defined $rhs_expr
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | 39 | $lhs_expr =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 39 | $rhs_expr =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 39 | ▶ | if (length $lhs_expr && length $rhs_expr) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
length $lhs_expr and length $rhs_expr
MC/DC0%0/2
length $lhs_expr and length $rhs_expr
length $lhs_expr
length $rhs_expr
Truth table33%1/3
A and B
A= length $lhs_exprB= length $rhs_expr
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | 39 | my ($lhs_values, $lhs_ok) = _evaluate_value_expression($self, $context, $lhs_expr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | 39 | my $lhs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 39 | ▶ | if ($lhs_ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 37 | ▶ | $lhs = @$lhs_values ? $lhs_values->[0] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 2 | my @outputs = $self->run_query(_encode_json($context), $lhs_expr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | 2 | ▶ | $lhs = @outputs ? $outputs[0] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | 39 | my ($rhs_values, $rhs_ok) = _evaluate_value_expression($self, $context, $rhs_expr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | 39 | my $rhs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | 39 | ▶ | if ($rhs_ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | 38 | ▶ | $rhs = @$rhs_values ? $rhs_values->[0] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | 1 | my @outputs = $self->run_query(_encode_json($context), $rhs_expr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | 1 | ▶ | $rhs = @outputs ? $outputs[0] : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | 39 | my $combined = _apply_addition($lhs, $rhs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | 37 | return ([ $combined ], 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | 668 | my $decoded = eval { _decode_json($copy) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 668 | ▶ | if (!$@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 93 | return ([ $decoded ], 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 575 | ▶ | if ($copy =~ /^'(.*)'$/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 0 | my $text = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 0 | $text =~ s/\\'/'/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 0 | return ([ $text ], 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | 575 | ▶ | if ($copy !~ /\bthen\b/i | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
not $copy =~ /\bthen\b/i || $copy =~ /\belse\b/i || $copy =~ /\bend\b/i and $copy =~ /(?:==|!=|>=|<=|>|<|\band\b|\bor\b|\bcontains\b|\bhas\b|\bmatch\b)/
$copy =~ /\bthen\b/i || $copy =~ /\belse\b/i || $copy =~ /\bend\b/i
$copy =~ /\bthen\b/i or $copy =~ /\belse\b/i
MC/DC50%2/4
not $copy =~ /\bthen\b/i || $copy =~ /\belse\b/i || $copy =~ /\bend\b/i and $copy =~ /(?:==|!=|>=|<=|>|<|\band\b|\bor\b|\bcontains\b|\bhas\b|\bmatch\b)/
$copy =~ /\bthen\b/i
$copy =~ /\belse\b/i
$copy =~ /\bend\b/i
$copy =~ /(?:==|!=|>=|<=|>|<|\band\b|\bor\b|\bcontains\b|\bhas\b|\bmatch\b)/
Truth table60%3/5
not(A or B || C) and D
A= $copy =~ /\bthen\b/iB= $copy =~ /\belse\b/iC= $copy =~ /\bend\b/iD= $copy =~ /(?:==|!=|>=|<=|>|<|\band\b|\bor\b|\bcontains\b|\bhas\b|\bmatch\b)/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | && $copy !~ /\belse\b/i | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | && $copy !~ /\bend\b/i | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | && $copy =~ /(?:==|!=|>=|<=|>|<|\band\b|\bor\b|\bcontains\b|\bhas\b|\bmatch\b)/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | 11 | my $bool = _evaluate_condition($context, $copy); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | 11 | ▶ | my $json_bool = $bool ? JSON::PP::true : JSON::PP::false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | 11 | return ([ $json_bool ], 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 564 | return ([], 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | 52 | ▶ | sub _apply_addition { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_apply_addition: called CC=27 SCAR=44.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | 52 | my ($left, $right) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | 52 | ▶ | return $right if !defined $left; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | 51 | ▶ | return $left if !defined $right; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | 51 | ▶ | if (ref($left) eq 'JSON::PP::Boolean') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | 1 | ▶ | $left = $left ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 51 | ▶ | if (ref($right) eq 'JSON::PP::Boolean') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 0 | ▶ | $right = $right ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 51 | ▶ | if (!ref $left && !ref $right) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $left or ref $right
MC/DC50%1/2
ref $left or ref $right
ref $left
ref $right
Truth table66%2/3
A or B
A= ref $leftB= ref $right
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 50 | my $left_is_string = _is_string_scalar($left); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 50 | my $right_is_string = _is_string_scalar($right); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 50 | ▶ | if ($left_is_string || $right_is_string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$left_is_string or $right_is_string
MC/DC50%1/2
$left_is_string or $right_is_string
$left_is_string
$right_is_string
Truth table66%2/3
A or B
A= $left_is_stringB= $right_is_string
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 13 | ▶ | die 'addition operands must both be strings' if !$left_is_string || !$right_is_string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$left_is_string and $right_is_string
MC/DC50%1/2
$left_is_string and $right_is_string
$left_is_string
$right_is_string
Truth table66%2/3
A and B
A= $left_is_stringB= $right_is_string
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 10 | ▶ | $left = '' unless defined $left; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | 10 | ▶ | $right = '' unless defined $right; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | 10 | return "$left$right"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 37 | ▶ | if (looks_like_number($left) && looks_like_number($right)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
&looks_like_number($left) and &looks_like_number($right)
MC/DC0%0/2
&looks_like_number($left) and &looks_like_number($right)
&looks_like_number($left)
&looks_like_number($right)
Truth table33%1/3
A and B
A= &looks_like_number($left)B= &looks_like_number($right)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | 37 | return 0 + $left + $right; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | 0 | die 'addition operands must both be numbers or both be strings'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | 1 | ▶ | if (ref $left eq 'ARRAY' && ref $right eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $left eq "ARRAY" and ref $right eq "ARRAY"
MC/DC0%0/2
ref $left eq "ARRAY" and ref $right eq "ARRAY"
ref $left eq "ARRAY"
ref $right eq "ARRAY"
Truth table33%1/3
A and B
A= ref $left eq "ARRAY"B= ref $right eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 0 | return [ @$left, @$right ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | 1 | ▶ | if (ref $left eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | 0 | return [ @$left, $right ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 1 | ▶ | if (ref $right eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 0 | return [ $left, @$right ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 1 | ▶ | if (ref $left eq 'HASH' && ref $right eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $left eq "HASH" and ref $right eq "HASH"
MC/DC0%0/2
ref $left eq "HASH" and ref $right eq "HASH"
ref $left eq "HASH"
ref $right eq "HASH"
Truth table33%1/3
A and B
A= ref $left eq "HASH"B= ref $right eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 1 | return { %$left, %$right }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 0 | ▶ | return $right if !ref $left && ref $right eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not ref $left and ref $right eq "HASH"
MC/DC0%0/2
not ref $left and ref $right eq "HASH"
not ref $left
ref $right eq "HASH"
Truth table0%0/3
not(A) and B
A= not ref $leftB= ref $right eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 0 | ▶ | return $left if ref $left eq 'HASH' && !ref $right; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $left eq "HASH" and not ref $right
MC/DC0%0/2
ref $left eq "HASH" and not ref $right
ref $left eq "HASH"
not ref $right
Truth table0%0/3
A and not(B)
A= ref $left eq "HASH"B= not ref $right
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 34 | ▶ | sub _coerce_number_strict { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_coerce_number_strict: called CC=7 SCAR=23.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | 34 | my ($value, $label) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | 34 | ▶ | $label ||= 'value'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$label ||= "value"
MC/DC0%0/1
$label ||= "value"
$label
Truth table50%1/2
A
A= $label
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | 34 | ▶ | die "$label must be a number" unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | 34 | ▶ | if (ref($value) eq 'JSON::PP::Boolean') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | 0 | ▶ | return $value ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | 34 | ▶ | die "$label must be a number" if ref $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | 34 | ▶ | die "$label must be a number" unless looks_like_number($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 34 | return 0 + $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | 3 | ▶ | sub _tonumber { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tonumber: called CC=7 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | 3 | my ($value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | 3 | ▶ | return undef unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | 3 | ▶ | if (ref($value) eq 'JSON::PP::Boolean') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | 0 | ▶ | return $value ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 3 | ▶ | if (ref $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | 0 | die 'tonumber(): argument must be a string or number'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | 3 | my $text = "$value"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 3 | $text =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | 3 | ▶ | die 'tonumber(): not a numeric string' unless length $text && looks_like_number($text); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
length $text and &looks_like_number($text)
MC/DC0%0/2
length $text and &looks_like_number($text)
length $text
&looks_like_number($text)
Truth table33%1/3
A and B
A= length $textB= &looks_like_number($text)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | 3 | return 0 + $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | 2349 | ▶ | sub _looks_like_expression { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_looks_like_expression: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | 2349 | my ($expr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | 2349 | ▶ | return 0 unless defined $expr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | 2349 | ▶ | return 1 if $expr =~ /\b(?:floor|ceil|round|tonumber)\b/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | 2312 | ▶ | return 0 if $expr =~ /^\s*[\{\[]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | 2281 | ▶ | return 0 if $expr =~ /^[A-Za-z_]\w*\s*\(/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | 1839 | ▶ | return 1 if $expr =~ /[\-*\/%]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | 1788 | ▶ | return 1 if $expr =~ /(?:==|!=|>=|<=|>|<|\band\b|\bor\b)/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | 1748 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | 876 | ▶ | sub _looks_like_assignment { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_looks_like_assignment: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | 876 | my ($expr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | 876 | ▶ | return 0 unless defined $expr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | 876 | ▶ | return 0 if $expr =~ /[()]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | 612 | ▶ | return 0 if $expr =~ /(?:==|!=|>=|<=|=>|=<)/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | 612 | return ($expr =~ /=/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | 18 | ▶ | sub _parse_assignment_expression { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_assignment_expression: called CC=5 SCAR=16.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | 18 | my ($expr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | 18 | ▶ | $expr //= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$expr //= ""
MC/DC0%0/1
$expr //= ""
$expr
Truth table50%1/2
A
A= $expr
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | 18 | my ($lhs, $op, $rhs) = ($expr =~ /^(.*?)\s*([+\-*\/]?=)\s*(.*)$/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | 18 | ▶ | $lhs //= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$lhs //= ""
MC/DC0%0/1
$lhs //= ""
$lhs
Truth table50%1/2
A
A= $lhs
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | 18 | ▶ | $rhs //= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$rhs //= ""
MC/DC0%0/1
$rhs //= ""
$rhs
Truth table50%1/2
A
A= $rhs
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | 18 | ▶ | $op //= '='; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$op //= "="
MC/DC0%0/1
$op //= "="
$op
Truth table50%1/2
A
A= $op
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | 18 | $lhs =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | 18 | $rhs =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | 18 | $lhs =~ s/^\.//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | 18 | my $value_spec = _parse_assignment_value($rhs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | 18 | return ($lhs, $value_spec, $op); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | 18 | ▶ | sub _parse_assignment_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_assignment_value: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | 18 | my ($raw) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | 18 | ▶ | $raw //= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$raw //= ""
MC/DC0%0/1
$raw //= ""
$raw
Truth table50%1/2
A
A= $raw
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | 18 | $raw =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | 18 | ▶ | if ($raw =~ /^\.(.+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | 1 | return { type => 'path', value => $1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | 17 | my $decoded = eval { _decode_json($raw) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | 17 | ▶ | if (!$@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | 12 | return { type => 'literal', value => $decoded }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | 5 | ▶ | if ($raw =~ /^'(.*)'$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | 2 | my $text = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | 2 | $text =~ s/\\'/'/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | 2 | return { type => 'literal', value => $text }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | 3 | return { type => 'expression', value => $raw }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | 182 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||