| 1 | package Yote::Spiderpup::SFC; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | our @EXPORT_OK = qw(parse_sfc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # Keys whose values are function expressions (kept as raw strings) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | my %FUNCTION_KEYS = map { $_ => 1 } qw(methods computed lifecycle watch); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # Keys whose values are parsed as Perl data structures | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | my %DATA_KEYS = map { $_ => 1 } qw(vars import routes initial_store); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # Keys whose values are arrays of strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | my %ARRAY_KEYS = map { $_ => 1 } ('import-css', 'import-js', 'include-js'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # Public API | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 28 | ▶ | sub parse_sfc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_sfc: called CC=25 SCAR=37.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 28 | my ($content) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 28 | my $result = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # Strip HTML comments before parsing to avoid false matches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 28 | $content =~ s/<!--.*?-->//gs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # Extract <style> blocks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 28 | ▶ | while ($content =~ /<style([^>]*)>(.*?)<\/style>/gs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | my ($attrs, $body) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | $body =~ s/^\n//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | $body =~ s/\n$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | my $is_less = ($attrs =~ /lang\s*=\s*["']less["']/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | ▶ | my $style_key = $is_less ? 'less' : 'css'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 3 | ▶ | if ($attrs =~ /recipe\s*=\s*["']([^"']+)["']/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $recipe_name = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | $result->{recipes} //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$result->{"recipes"} //= {}
MC/DC0%0/1
$result->{"recipes"} //= {}
$result->{"recipes"}
Truth table0%0/2
A
A= $result->{"recipes"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | $result->{recipes}{$recipe_name} //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$result->{"recipes"}{$recipe_name} //= {}
MC/DC0%0/1
$result->{"recipes"}{$recipe_name} //= {}
$result->{"recipes"}{$recipe_name}
Truth table0%0/2
A
A= $result->{"recipes"}{$recipe_name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | $result->{recipes}{$recipe_name}{$style_key} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | ($result->{recipes}{$recipe_name}{$style_key} // '') . $body; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$result->{"recipes"}{$recipe_name}{$style_key} // ""
MC/DC0%0/1
$result->{"recipes"}{$recipe_name}{$style_key} // ""
$result->{"recipes"}{$recipe_name}{$style_key}
Truth table0%0/2
A
A= $result->{"recipes"}{$recipe_name}{$style_key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | ▶ | $result->{$style_key} = ($result->{$style_key} // '') . $body; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$result->{$style_key} // ""
MC/DC0%0/1
$result->{$style_key} // ""
$result->{$style_key}
Truth table50%1/2
A
A= $result->{$style_key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # Extract <template> blocks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 28 | ▶ | while ($content =~ /<template([^>]*)>(.*?)<\/template>/gs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 6 | my ($attrs, $body) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 6 | $body =~ s/^\n//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 6 | $body =~ s/\n$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 6 | ▶ | if ($attrs =~ /recipe\s*=\s*["']([^"']+)["']/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | my $recipe_name = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | ▶ | $result->{recipes} //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$result->{"recipes"} //= {}
MC/DC0%0/1
$result->{"recipes"} //= {}
$result->{"recipes"}
Truth table50%1/2
A
A= $result->{"recipes"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | ▶ | $result->{recipes}{$recipe_name} //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$result->{"recipes"}{$recipe_name} //= {}
MC/DC0%0/1
$result->{"recipes"}{$recipe_name} //= {}
$result->{"recipes"}{$recipe_name}
Truth table50%1/2
A
A= $result->{"recipes"}{$recipe_name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | $result->{recipes}{$recipe_name}{html} = $body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } elsif ($attrs =~ /name\s*=\s*["']([^"']+)["']/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | my $variant = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | $result->{"html_$variant"} = $body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | $result->{html} = $body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # Extract <script> blocks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 28 | ▶ | while ($content =~ /<script([^>]*)>(.*?)<\/script>/gs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 23 | my ($attrs, $body) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 23 | ▶ | if ($attrs =~ /recipe\s*=\s*["']([^"']+)["']/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | my $recipe_name = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | $result->{recipes} //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$result->{"recipes"} //= {}
MC/DC0%0/1
$result->{"recipes"} //= {}
$result->{"recipes"}
Truth table50%1/2
A
A= $result->{"recipes"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | ▶ | $result->{recipes}{$recipe_name} //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$result->{"recipes"}{$recipe_name} //= {}
MC/DC0%0/1
$result->{"recipes"}{$recipe_name} //= {}
$result->{"recipes"}{$recipe_name}
Truth table50%1/2
A
A= $result->{"recipes"}{$recipe_name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | my $parsed = _parse_top_object($body); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | for my $key (keys %$parsed) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | $result->{recipes}{$recipe_name}{$key} = $parsed->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 22 | my $parsed = _parse_top_object($body); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 22 | for my $key (keys %$parsed) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 27 | ▶ | if ($key eq 'recipes' && ref($result->{$key}) eq 'HASH' && ref($parsed->{$key}) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$key eq "recipes" and ref $result->{$key} eq "HASH" and ref $parsed->{$key} eq "HASH"
$key eq "recipes" and ref $result->{$key} eq "HASH"
MC/DC0%0/3
$key eq "recipes" and ref $result->{$key} eq "HASH" and ref $parsed->{$key} eq "HASH"
$key eq "recipes"
ref $result->{$key} eq "HASH"
ref $parsed->{$key} eq "HASH"
Truth table50%2/4
A and B and C
A= $key eq "recipes"B= ref $result->{$key} eq "HASH"C= ref $parsed->{$key} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # Deep merge: script recipes into existing recipe data (from template blocks) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | for my $rname (keys %{$parsed->{$key}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | $result->{$key}{$rname} //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$result->{$key}{$rname} //= {}
MC/DC0%0/1
$result->{$key}{$rname} //= {}
$result->{$key}{$rname}
Truth table0%0/2
A
A= $result->{$key}{$rname}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | for my $rkey (keys %{$parsed->{$key}{$rname}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $result->{$key}{$rname}{$rkey} = $parsed->{$key}{$rname}{$rkey}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 27 | $result->{$key} = $parsed->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 28 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # Whitespace and comment skipping | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 393 | ▶ | sub _skip_ws { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_skip_ws: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 393 | my ($text, $pos) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 393 | my $len = length($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 393 | ▶ | while ($$pos < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # Skip whitespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 773 | ▶ | if (substr($text, $$pos, 1) =~ /\s/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 379 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 379 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # Skip // line comments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 394 | ▶ | if (substr($text, $$pos, 2) eq '//') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | $$pos += 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | ▶ | while ($$pos < $len && substr($text, $$pos, 1) ne "\n") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$$pos < $len and substr($text, $$pos, 1) ne "\n"
MC/DC50%1/2
$$pos < $len and substr($text, $$pos, 1) ne "\n"
$$pos < $len
substr($text, $$pos, 1) ne "\n"
Truth table66%2/3
A and B
A= $$pos < $lenB= substr($text, $$pos, 1) ne "\n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 16 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # Skip /* block comments */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 393 | ▶ | if (substr($text, $$pos, 2) eq '/*') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | $$pos += 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | ▶ | while ($$pos < $len - 1 && substr($text, $$pos, 2) ne '*/') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$$pos < $len - 1 and substr($text, $$pos, 2) ne "*/"
MC/DC50%1/2
$$pos < $len - 1 and substr($text, $$pos, 2) ne "*/"
$$pos < $len - 1
substr($text, $$pos, 2) ne "*/"
Truth table66%2/3
A and B
A= $$pos < $len - 1B= substr($text, $$pos, 2) ne "*/"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 14 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | ▶ | $$pos += 2 if $$pos < $len - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 392 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # String reading | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 20 | ▶ | sub _read_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_string: called CC=5 SCAR=18.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 20 | my ($text, $pos) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 20 | my $quote = substr($text, $$pos, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 20 | $$pos++; # skip opening quote | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 20 | my $result = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 20 | my $len = length($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 20 | ▶ | while ($$pos < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 181 | my $ch = substr($text, $$pos, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 181 | ▶ | if ($ch eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # Escape sequence | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $result .= $ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | if ($$pos < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | $result .= substr($text, $$pos, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 181 | ▶ | if ($ch eq $quote) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 20 | $$pos++; # skip closing quote | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 20 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 161 | $result .= $ch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 161 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # Key reading (bare identifier or quoted string) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 67 | ▶ | sub _read_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_key: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 67 | my ($text, $pos) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 67 | my $ch = substr($text, $$pos, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 67 | ▶ | if ($ch eq '"' || $ch eq "'") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ch eq "\"" or $ch eq "'"
MC/DC50%1/2
$ch eq "\"" or $ch eq "'"
$ch eq "\""
$ch eq "'"
Truth table66%2/3
A or B
A= $ch eq "\""B= $ch eq "'"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 3 | return _read_string($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # Bare identifier: letters, digits, underscore, dash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 64 | my $start = $$pos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 64 | my $len = length($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 64 | ▶ | while ($$pos < $len && substr($text, $$pos, 1) =~ /[\w\-]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$$pos < $len and substr($text, $$pos, 1) =~ /[\w\-]/
MC/DC50%1/2
$$pos < $len and substr($text, $$pos, 1) =~ /[\w\-]/
$$pos < $len
substr($text, $$pos, 1) =~ /[\w\-]/
Truth table66%2/3
A and B
A= $$pos < $lenB= substr($text, $$pos, 1) =~ /[\w\-]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 355 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 64 | return substr($text, $start, $$pos - $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # Read balanced expression (for function context values) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # Scans until we hit , or } at depth 0, respecting strings and brackets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 16 | ▶ | sub _read_balanced { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_balanced: called CC=25 SCAR=39.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 16 | my ($text, $pos) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 16 | my $start = $$pos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 16 | my $depth = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 16 | my $len = length($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 16 | ▶ | while ($$pos < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 598 | my $ch = substr($text, $$pos, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # Handle strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 598 | ▶ | if ($ch eq '"' || $ch eq "'" || $ch eq '`') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$ch eq "\"" or $ch eq "'" or $ch eq "`"
$ch eq "\"" or $ch eq "'"
MC/DC100%3/3
$ch eq "\"" or $ch eq "'" or $ch eq "`"
$ch eq "\""
$ch eq "'"
$ch eq "`"
Truth table100%4/4
A or B or C
A= $ch eq "\""B= $ch eq "'"C= $ch eq "`"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 10 | _skip_string($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 10 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # Handle line comments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 588 | ▶ | if ($ch eq '/' && $$pos + 1 < $len && substr($text, $$pos + 1, 1) eq '/') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$ch eq "/" and $$pos + 1 < $len and substr($text, $$pos + 1, 1) eq "/"
$ch eq "/" and $$pos + 1 < $len
MC/DC0%0/3
$ch eq "/" and $$pos + 1 < $len and substr($text, $$pos + 1, 1) eq "/"
$ch eq "/"
$$pos + 1 < $len
substr($text, $$pos + 1, 1) eq "/"
Truth table25%1/4
A and B and C
A= $ch eq "/"B= $$pos + 1 < $lenC= substr($text, $$pos + 1, 1) eq "/"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $$pos += 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | while ($$pos < $len && substr($text, $$pos, 1) ne "\n") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$$pos < $len and substr($text, $$pos, 1) ne "\n"
MC/DC0%0/2
$$pos < $len and substr($text, $$pos, 1) ne "\n"
$$pos < $len
substr($text, $$pos, 1) ne "\n"
Truth table0%0/3
A and B
A= $$pos < $lenB= substr($text, $$pos, 1) ne "\n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # Handle block comments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 588 | ▶ | if ($ch eq '/' && $$pos + 1 < $len && substr($text, $$pos + 1, 1) eq '*') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$ch eq "/" and $$pos + 1 < $len and substr($text, $$pos + 1, 1) eq "*"
$ch eq "/" and $$pos + 1 < $len
MC/DC0%0/3
$ch eq "/" and $$pos + 1 < $len and substr($text, $$pos + 1, 1) eq "*"
$ch eq "/"
$$pos + 1 < $len
substr($text, $$pos + 1, 1) eq "*"
Truth table25%1/4
A and B and C
A= $ch eq "/"B= $$pos + 1 < $lenC= substr($text, $$pos + 1, 1) eq "*"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | $$pos += 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | while ($$pos < $len - 1 && substr($text, $$pos, 2) ne '*/') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$$pos < $len - 1 and substr($text, $$pos, 2) ne "*/"
MC/DC0%0/2
$$pos < $len - 1 and substr($text, $$pos, 2) ne "*/"
$$pos < $len - 1
substr($text, $$pos, 2) ne "*/"
Truth table0%0/3
A and B
A= $$pos < $len - 1B= substr($text, $$pos, 2) ne "*/"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | $$pos += 2 if $$pos < $len - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 588 | ▶ | if ($ch eq '{' || $ch eq '[' || $ch eq '(') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$ch eq "{" or $ch eq "[" or $ch eq "("
$ch eq "{" or $ch eq "["
MC/DC66%2/3
$ch eq "{" or $ch eq "[" or $ch eq "("
$ch eq "{"
$ch eq "["
$ch eq "("
Truth table75%3/4
A or B or C
A= $ch eq "{"B= $ch eq "["C= $ch eq "("
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 35 | $depth++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 35 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 35 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 553 | ▶ | if ($ch eq '}' || $ch eq ']' || $ch eq ')') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$ch eq "}" or $ch eq "]" or $ch eq ")"
$ch eq "}" or $ch eq "]"
MC/DC66%2/3
$ch eq "}" or $ch eq "]" or $ch eq ")"
$ch eq "}"
$ch eq "]"
$ch eq ")"
Truth table75%3/4
A or B or C
A= $ch eq "}"B= $ch eq "]"C= $ch eq ")"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 47 | ▶ | if ($depth == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 12 | last; # end of enclosing object/array | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 35 | $depth--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 35 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 35 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 506 | ▶ | if ($ch eq ',' && $depth == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ch eq "," and $depth == 0
MC/DC100%2/2
$ch eq "," and $depth == 0
$ch eq ","
$depth == 0
Truth table100%3/3
A and B
A= $ch eq ","B= $depth == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 4 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 502 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 16 | my $val = substr($text, $start, $$pos - $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 16 | $val =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 16 | $val =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 16 | return $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # Skip over a string without returning its content (for balanced scanning) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 10 | ▶ | sub _skip_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_skip_string: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 10 | my ($text, $pos) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 10 | my $quote = substr($text, $$pos, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 10 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 10 | my $len = length($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 10 | ▶ | while ($$pos < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 103 | my $ch = substr($text, $$pos, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 103 | ▶ | if ($ch eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | $$pos += 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 103 | ▶ | if ($ch eq $quote) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 10 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 10 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 93 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # Read data value (parse JS literal to Perl scalar/hashref/arrayref) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 41 | ▶ | sub _read_data_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_data_value: called CC=17 SCAR=29.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 41 | my ($text, $pos) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 41 | _skip_ws($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 41 | my $len = length($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 41 | ▶ | return undef if $$pos >= $len; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 41 | my $ch = substr($text, $$pos, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # String | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 41 | ▶ | if ($ch eq '"' || $ch eq "'") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ch eq "\"" or $ch eq "'"
MC/DC100%2/2
$ch eq "\"" or $ch eq "'"
$ch eq "\""
$ch eq "'"
Truth table100%3/3
A or B
A= $ch eq "\""B= $ch eq "'"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 17 | return _read_string($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # Backtick template literal - read as string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 24 | ▶ | if ($ch eq '`') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | return _read_string($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # Array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 24 | ▶ | if ($ch eq '[') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 2 | return _read_data_array($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # Object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 22 | ▶ | if ($ch eq '{') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 12 | return _read_data_object($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | # Boolean / null / undefined / number / bare value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 10 | my $start = $$pos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 10 | ▶ | while ($$pos < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 25 | my $c = substr($text, $$pos, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 25 | ▶ | last if $c eq ',' || $c eq '}' || $c eq ']' || $c =~ /\s/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$c eq "," or $c eq "}" or $c eq "]" or $c =~ /\s/
$c eq "," or $c eq "}" or $c eq "]"
$c eq "," or $c eq "}"
MC/DC50%2/4
$c eq "," or $c eq "}" or $c eq "]" or $c =~ /\s/
$c eq ","
$c eq "}"
$c eq "]"
$c =~ /\s/
Truth table60%3/5
A or B or C or D
A= $c eq ","B= $c eq "}"C= $c eq "]"D= $c =~ /\s/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 15 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 10 | my $raw = substr($text, $start, $$pos - $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # Convert JS types to Perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 10 | ▶ | return 1 if $raw eq 'true'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 9 | ▶ | return 0 if $raw eq 'false'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 9 | ▶ | return undef if $raw eq 'null' || $raw eq 'undefined'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$raw eq "null" or $raw eq "undefined"
MC/DC0%0/2
$raw eq "null" or $raw eq "undefined"
$raw eq "null"
$raw eq "undefined"
Truth table33%1/3
A or B
A= $raw eq "null"B= $raw eq "undefined"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | # Numbers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 9 | ▶ | if ($raw =~ /^-?\d+\.?\d*$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 9 | return $raw + 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | return $raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 2 | ▶ | sub _read_data_array { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_data_array: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 2 | my ($text, $pos) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 2 | $$pos++; # skip [ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 2 | my @items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 2 | my $len = length($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 2 | ▶ | while ($$pos < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 7 | _skip_ws($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 7 | ▶ | last if $$pos >= $len; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 7 | ▶ | last if substr($text, $$pos, 1) eq ']'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 5 | push @items, _read_data_value($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 5 | _skip_ws($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 5 | ▶ | if ($$pos < $len && substr($text, $$pos, 1) eq ',') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$$pos < $len and substr($text, $$pos, 1) eq ","
MC/DC50%1/2
$$pos < $len and substr($text, $$pos, 1) eq ","
$$pos < $len
substr($text, $$pos, 1) eq ","
Truth table66%2/3
A and B
A= $$pos < $lenB= substr($text, $$pos, 1) eq ","
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 3 | $$pos++; # skip comma | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 2 | ▶ | $$pos++ if $$pos < $len; # skip ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 2 | return \@items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 12 | ▶ | sub _read_data_object { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_data_object: called CC=9 SCAR=22.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 12 | my ($text, $pos) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 12 | $$pos++; # skip { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 12 | my %obj; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 12 | my $len = length($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 12 | ▶ | while ($$pos < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 31 | _skip_ws($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 31 | ▶ | last if $$pos >= $len; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 31 | ▶ | last if substr($text, $$pos, 1) eq '}'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 19 | my $key = _read_key($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 19 | _skip_ws($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | # skip colon | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 19 | ▶ | if ($$pos < $len && substr($text, $$pos, 1) eq ':') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$$pos < $len and substr($text, $$pos, 1) eq ":"
MC/DC0%0/2
$$pos < $len and substr($text, $$pos, 1) eq ":"
$$pos < $len
substr($text, $$pos, 1) eq ":"
Truth table33%1/3
A and B
A= $$pos < $lenB= substr($text, $$pos, 1) eq ":"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 19 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 19 | _skip_ws($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 19 | $obj{$key} = _read_data_value($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 19 | _skip_ws($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 19 | ▶ | if ($$pos < $len && substr($text, $$pos, 1) eq ',') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$$pos < $len and substr($text, $$pos, 1) eq ","
MC/DC50%1/2
$$pos < $len and substr($text, $$pos, 1) eq ","
$$pos < $len
substr($text, $$pos, 1) eq ","
Truth table66%2/3
A and B
A= $$pos < $lenB= substr($text, $$pos, 1) eq ","
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 8 | $$pos++; # skip comma | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 12 | ▶ | $$pos++ if $$pos < $len; # skip } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 12 | return \%obj; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | # Parse function map: { key: funcExpr, ... } keeping values as raw strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 13 | ▶ | sub _parse_function_map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_function_map: called CC=9 SCAR=22.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 13 | my ($text, $pos) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 13 | $$pos++; # skip opening { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 13 | my %map; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 13 | my $len = length($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 13 | ▶ | while ($$pos < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 29 | _skip_ws($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 29 | ▶ | last if $$pos >= $len; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 29 | ▶ | last if substr($text, $$pos, 1) eq '}'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 16 | my $key = _read_key($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 16 | _skip_ws($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | # skip colon | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 16 | ▶ | if ($$pos < $len && substr($text, $$pos, 1) eq ':') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$$pos < $len and substr($text, $$pos, 1) eq ":"
MC/DC0%0/2
$$pos < $len and substr($text, $$pos, 1) eq ":"
$$pos < $len
substr($text, $$pos, 1) eq ":"
Truth table33%1/3
A and B
A= $$pos < $lenB= substr($text, $$pos, 1) eq ":"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 16 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 16 | _skip_ws($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 16 | $map{$key} = _read_balanced($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 16 | _skip_ws($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 16 | ▶ | if ($$pos < $len && substr($text, $$pos, 1) eq ',') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$$pos < $len and substr($text, $$pos, 1) eq ","
MC/DC50%1/2
$$pos < $len and substr($text, $$pos, 1) eq ","
$$pos < $len
substr($text, $$pos, 1) eq ","
Truth table66%2/3
A and B
A= $$pos < $lenB= substr($text, $$pos, 1) eq ","
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 4 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 13 | ▶ | $$pos++ if $$pos < $len; # skip closing } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 13 | return \%map; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | # Parse recipes map: { name: { ... }, ... } where each value is like a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | # top-level script block but parsed at the object level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 1 | ▶ | sub _parse_recipes_map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_recipes_map: called CC=10 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 1 | my ($text, $pos) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 1 | $$pos++; # skip opening { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 1 | my %recipes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 1 | my $len = length($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 1 | ▶ | while ($$pos < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 2 | _skip_ws($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 2 | ▶ | last if $$pos >= $len; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 2 | ▶ | last if substr($text, $$pos, 1) eq '}'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 1 | my $recipe_name = _read_key($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 1 | _skip_ws($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # skip colon | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 1 | ▶ | if ($$pos < $len && substr($text, $$pos, 1) eq ':') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$$pos < $len and substr($text, $$pos, 1) eq ":"
MC/DC0%0/2
$$pos < $len and substr($text, $$pos, 1) eq ":"
$$pos < $len
substr($text, $$pos, 1) eq ":"
Truth table33%1/3
A and B
A= $$pos < $lenB= substr($text, $$pos, 1) eq ":"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 1 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 1 | _skip_ws($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 1 | ▶ | if (substr($text, $$pos, 1) eq '{') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 1 | $recipes{$recipe_name} = _parse_recipe_object($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 1 | _skip_ws($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 1 | ▶ | if ($$pos < $len && substr($text, $$pos, 1) eq ',') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$$pos < $len and substr($text, $$pos, 1) eq ","
MC/DC0%0/2
$$pos < $len and substr($text, $$pos, 1) eq ","
$$pos < $len
substr($text, $$pos, 1) eq ","
Truth table33%1/3
A and B
A= $$pos < $lenB= substr($text, $$pos, 1) eq ","
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 1 | ▶ | $$pos++ if $$pos < $len; # skip closing } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 1 | return \%recipes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | # Parse a single recipe object (same dispatch as top-level) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 1 | ▶ | sub _parse_recipe_object { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_recipe_object: called CC=9 SCAR=22.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 1 | my ($text, $pos) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 1 | $$pos++; # skip opening { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 1 | my %result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 1 | my $len = length($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 1 | ▶ | while ($$pos < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 3 | _skip_ws($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 3 | ▶ | last if $$pos >= $len; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 3 | ▶ | last if substr($text, $$pos, 1) eq '}'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 2 | my $key = _read_key($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 2 | _skip_ws($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | # skip colon | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 2 | ▶ | if ($$pos < $len && substr($text, $$pos, 1) eq ':') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$$pos < $len and substr($text, $$pos, 1) eq ":"
MC/DC0%0/2
$$pos < $len and substr($text, $$pos, 1) eq ":"
$$pos < $len
substr($text, $$pos, 1) eq ":"
Truth table33%1/3
A and B
A= $$pos < $lenB= substr($text, $$pos, 1) eq ":"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 2 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 2 | _skip_ws($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 2 | $result{$key} = _parse_value_for_key($key, $text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 2 | _skip_ws($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 2 | ▶ | if ($$pos < $len && substr($text, $$pos, 1) eq ',') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$$pos < $len and substr($text, $$pos, 1) eq ","
MC/DC50%1/2
$$pos < $len and substr($text, $$pos, 1) eq ","
$$pos < $len
substr($text, $$pos, 1) eq ","
Truth table66%2/3
A and B
A= $$pos < $lenB= substr($text, $$pos, 1) eq ","
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 1 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 1 | ▶ | $$pos++ if $$pos < $len; # skip closing } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 1 | return \%result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | # Value dispatch based on key name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 31 | ▶ | sub _parse_value_for_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_value_for_key: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 31 | my ($key, $text, $pos) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 31 | ▶ | if ($FUNCTION_KEYS{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 13 | ▶ | if (substr($text, $$pos, 1) eq '{') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 13 | return _parse_function_map($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | return _read_balanced($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 18 | ▶ | if ($DATA_KEYS{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 12 | return _read_data_value($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 6 | ▶ | if ($ARRAY_KEYS{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 1 | return _read_data_value($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 5 | ▶ | if ($key eq 'recipes') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 1 | ▶ | if (substr($text, $$pos, 1) eq '{') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 1 | return _parse_recipes_map($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | return _read_data_value($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | # Default: scalar (string, number, etc) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 4 | return _read_data_value($text, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | # Top-level script parser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 23 | ▶ | sub _parse_top_object { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_top_object: called CC=12 SCAR=25.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 23 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 23 | my $pos = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 23 | my $len = length($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 23 | my %result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 23 | _skip_ws($text, \$pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | # Skip opening { if present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 23 | my $has_braces = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 23 | ▶ | if ($pos < $len && substr($text, $pos, 1) eq '{') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$pos < $len and substr($text, $pos, 1) eq "{"
MC/DC50%1/2
$pos < $len and substr($text, $pos, 1) eq "{"
$pos < $len
substr($text, $pos, 1) eq "{"
Truth table66%2/3
A and B
A= $pos < $lenB= substr($text, $pos, 1) eq "{"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 22 | $has_braces = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 22 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 23 | ▶ | while ($pos < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 51 | _skip_ws($text, \$pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 51 | ▶ | last if $pos >= $len; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 51 | ▶ | last if $has_braces && substr($text, $pos, 1) eq '}'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$has_braces and substr($text, $pos, 1) eq "}"
MC/DC100%2/2
$has_braces and substr($text, $pos, 1) eq "}"
$has_braces
substr($text, $pos, 1) eq "}"
Truth table100%3/3
A and B
A= $has_bracesB= substr($text, $pos, 1) eq "}"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 29 | my $key = _read_key($text, \$pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 29 | ▶ | last unless length($key); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 29 | _skip_ws($text, \$pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | # skip colon | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 29 | ▶ | if ($pos < $len && substr($text, $pos, 1) eq ':') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$pos < $len and substr($text, $pos, 1) eq ":"
MC/DC0%0/2
$pos < $len and substr($text, $pos, 1) eq ":"
$pos < $len
substr($text, $pos, 1) eq ":"
Truth table33%1/3
A and B
A= $pos < $lenB= substr($text, $pos, 1) eq ":"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 29 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 29 | _skip_ws($text, \$pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 29 | $result{$key} = _parse_value_for_key($key, $text, \$pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 29 | _skip_ws($text, \$pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 29 | ▶ | if ($pos < $len && substr($text, $pos, 1) eq ',') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$pos < $len and substr($text, $pos, 1) eq ","
MC/DC100%2/2
$pos < $len and substr($text, $pos, 1) eq ","
$pos < $len
substr($text, $pos, 1) eq ","
Truth table100%3/3
A and B
A= $pos < $lenB= substr($text, $pos, 1) eq ","
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 7 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 23 | return \%result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||