| 1 | # Copyright (C) 2025 Scott Baker <scott@perturb.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # This program is free software: you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # the Free Software Foundation, either version 3 of the License, or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # (at your option) any later version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # GNU General Public License for more details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # You should have received a copy of the GNU General Public License | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | package Template::Sluz; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 18 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 16 | ▶ | use 5.016; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 16 | ▶ | use File::Basename qw(dirname basename); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 15 | ▶ | use autouse 'Carp' => qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 14 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 14 | ▶ | use constant SLUZ_INLINE => 'INLINE_TEMPLATE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 14 | our @EXPORT = qw(SLUZ_INLINE); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 14 | our $VERSION = 'v0.9.8'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # Template used to emit a single variable value into a compiled foreach | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # body. It mirrors the interpreter's output rules exactly: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # ARRAY ref -> "ARRAY", HASH ref -> "HASH", undef -> "", anything else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # -> the value itself (HTML-escaped when auto_escape is on). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 14 | my $VAL_TMPL = q[{ my $v = %s; $ret .= (!ref($v) ? ($ae ? Template::Sluz::escape($v // '') : ($v // '')) : (ref($v) eq 'ARRAY' ? 'ARRAY' : (ref($v) eq 'HASH' ? 'HASH' : $v))); }]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # Comparison operators are dispatched by integer code in the hot paths | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # so that no string comparison is needed at render time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 14 | my %OP_CODE = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 'eq' => 0, 'ne' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | '==' => 2, '!=' => 3, '>' => 4, '<' => 5, '>=' => 6, '<=' => 7, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ################################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # Built-in Sluz functions that can be used in templates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | ################################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 9 | ▶ | sub count { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
count: called CC=4 SCAR=14.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 9 | my $v = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 9 | ▶ | if (ref $v eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | return scalar @$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 6 | ▶ | if (ref $v eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | return scalar(keys %$v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 6 | ▶ | if (defined $v) { return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | ▶ | sub join { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
join: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 4 | my $arr = shift(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 4 | ▶ | my $glue = shift() // ', '; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() // ", "
MC/DC100%1/1
shift() // ", "
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | return CORE::join($glue, @$arr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ################################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ################################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 34 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 34 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 34 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | my $self = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | version => $VERSION, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | tpl_file => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | inc_tpl_file => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | debug => $args{debug} // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 34 | ▶ | auto_escape => $args{auto_escape} // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition75%3/4
$args{"debug"} // 0
$args{"auto_escape"} // 0
MC/DC0%0/1
$args{"debug"} // 0
$args{"debug"}
MC/DC100%1/1
$args{"auto_escape"} // 0
$args{"auto_escape"}
Truth table50%1/2
A
A= $args{"debug"}
Truth table100%2/2
A
A= $args{"auto_escape"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | tpl_vars => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | parent_tpl => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | var_prefix => 'sluz_pfx', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | perl_file => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | perl_file_dir => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | fetch_called => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | char_pos => -1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | open_delim => '{', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | close_delim => '}', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | _sub_cache => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | __S => {}, # Cached prefixed var hash used by _peval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | _convert_cache => {}, # Cached _convert_vars results (avoids re-running regex on repeated expressions) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | _blocks_cache => {}, # Cached _get_blocks results (avoids re-tokenizing if payloads in loops) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | _if_rules_cache => {}, # Cached parsed {if} rules (avoids re-parsing same if block in loops) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | _if_payload_cache => {}, # Cached {if} branch payloads (condition + payload, no shape) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | _verified_sub_cache => {}, # Cached subs that succeeded once — skip eval/SIG overhead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | _mod_cache => {}, # Cached resolved modifier coderefs keyed by func name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | _micro_cache => {}, # Cached _micro_optimize shape classification (skips regex on repeat calls) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | _src_shape_cache => {}, # Cached foreach source expression shapes (avoids _peval per render) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | _mod_chain_cache => {}, # Cached parsed modifier chains (crefs + literal params resolved once) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | _inline_cache => {}, # Cached _get_inline_content results keyed by perl_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | _foreach_plans => {}, # Cached foreach plans (blocks + compiled renderer) keyed by loop vars + payload | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 34 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 34 | $self->_precompute_tags(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 34 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 649 | ▶ | sub assign { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
assign: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 649 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 649 | my $pfx = $self->{var_prefix}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # Accept either a hashref: assign($hash_ref) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 649 | ▶ | if (@_ == 1 && ref $_[0] eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC100%2/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table100%3/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 23 | my $h = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 23 | @{$self->{tpl_vars}}{keys %$h} = values %$h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 23 | foreach my $k (keys %$h) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 66 | $self->{__S}{"${pfx}_$k"} = $h->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # Or a key-value list: assign(name => 'Scott', age => 42) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } elsif (@_ % 2 == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 625 | my %h = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 625 | @{$self->{tpl_vars}}{keys %h} = values %h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 625 | foreach my $k (keys %h) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 701 | $self->{__S}{"${pfx}_$k"} = $h{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | $self->_error_out("Invalid assign. Must be a key/value or hash", 18956); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 15 | ▶ | sub fetch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 15 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 15 | ▶ | my $tpl_file = shift // SLUZ_INLINE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() // "INLINE_TEMPLATE"
MC/DC100%1/1
shift() // "INLINE_TEMPLATE"
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 15 | my $parent = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 15 | ▶ | if (!$self->{perl_file}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 4 | $self->{perl_file} = $self->_get_perl_file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 4 | $self->{perl_file_dir} = dirname($self->{perl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 15 | my $parent_tpl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 15 | ▶ | if (defined $parent) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | $parent_tpl = $parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 14 | $parent_tpl = $self->{parent_tpl}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 15 | ▶ | if ($parent_tpl) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 2 | $self->assign('__CHILD_TPL', $tpl_file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | $tpl_file = $parent_tpl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 15 | my $str = $self->_get_tpl_content($tpl_file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 12 | my $blocks = $self->_get_blocks_ref($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 12 | my $html = $self->_process_blocks($blocks); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 10 | $self->{fetch_called} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 10 | return $html; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | return $self->fetch(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | sub display { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
display: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | print $self->fetch(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # Parse a string instead of a file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 387 | ▶ | sub parse_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_string: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 387 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 387 | ▶ | my $tpl_str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 387 | my $blocks = $self->_get_blocks_ref($tpl_str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 377 | return $self->_process_blocks($blocks); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # Getter/setter for parent TPL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 2 | ▶ | sub parent_tpl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parent_tpl: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 2 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 2 | $self->{parent_tpl} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 2 | return $self->{parent_tpl}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 6 | ▶ | sub set_delimiters { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_delimiters: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 6 | my $open = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 6 | my $close = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 6 | ▶ | if (!defined $open || !defined $close) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $open and defined $close
MC/DC100%2/2
defined $open and defined $close
defined $open
defined $close
Truth table100%3/3
A and B
A= defined $openB= defined $close
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 2 | $self->_error_out("set_delimiters requires both open and close delimiter arguments", 51234); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 4 | ▶ | if (length($open) != 1 || length($close) != 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $open != 1 or length $close != 1
MC/DC50%1/2
length $open != 1 or length $close != 1
length $open != 1
length $close != 1
Truth table66%2/3
A or B
A= length $open != 1B= length $close != 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1 | $self->_error_out("Delimiters must be single characters", 51235); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 3 | ▶ | if ($open eq $close) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 1 | $self->_error_out("Open and close delimiters must be different characters", 51236); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | $self->{open_delim} = $open; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 2 | $self->{close_delim} = $close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 2 | $self->_precompute_tags(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # Clear all caches since results are delimiter-dependent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 2 | $self->{_blocks_cache} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 2 | $self->{_if_rules_cache} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 2 | $self->{_if_payload_cache} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 2 | $self->{_convert_cache} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 2 | $self->{_sub_cache} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 2 | $self->{_verified_sub_cache} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 2 | $self->{_mod_cache} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 2 | $self->{_src_shape_cache} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 2 | $self->{_mod_chain_cache} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 2 | $self->{_foreach_plans} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # Dive down an array or hashref using our dotted syntax | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 42 | ▶ | sub array_dive { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
array_dive: called CC=18 SCAR=32.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 42 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 42 | my $needle = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 42 | my $haystack = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | if (!defined $needle || !defined $haystack) { return undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $needle and defined $haystack
MC/DC0%0/2
defined $needle and defined $haystack
defined $needle
defined $haystack
Truth table33%1/3
A and B
A= defined $needleB= defined $haystack
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # Quick path: needle is a direct key in the hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 42 | ▶ | if (exists $haystack->{$needle}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | return $haystack->{$needle}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # Split parts are cached per needle, so the dotted path is only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # scanned once per distinct name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | my $parts = $self->{_dive_parts_cache}{$needle} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 42 | ▶ | // ($self->{_dive_parts_cache}{$needle} = [split /\./, $needle]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"_dive_parts_cache"}{$needle} // ($self->{"_dive_parts_cache"}{$needle} = [split(/\./u, $needle, 0)])
MC/DC100%1/1
$self->{"_dive_parts_cache"}{$needle} // ($self->{"_dive_parts_cache"}{$needle} = [split(/\./u, $needle, 0)])
$self->{"_dive_parts_cache"}{$needle}
Truth table100%2/2
A
A= $self->{"_dive_parts_cache"}{$needle}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # Fast path: exactly one dot and a hash -> hash walk (the common | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # case, e.g. "config.theme"). Missing keys yield undef exactly like | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # the generic walk below. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 42 | ▶ | if (@$parts == 2 && length $parts->[0] && length $parts->[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
@$parts == 2 and length $parts->[0] and length $parts->[1] and ref $haystack eq "HASH"
@$parts == 2 and length $parts->[0] and length $parts->[1]
@$parts == 2 and length $parts->[0]
MC/DC25%1/4
@$parts == 2 and length $parts->[0] and length $parts->[1] and ref $haystack eq "HASH"
@$parts == 2
length $parts->[0]
length $parts->[1]
ref $haystack eq "HASH"
Truth table40%2/5
A and B and C and D
A= @$parts == 2B= length $parts->[0]C= length $parts->[1]D= ref $haystack eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | && ref $haystack eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 37 | my $mid = $haystack->{$parts->[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 37 | ▶ | if (ref $mid eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 27 | return $mid->{$parts->[1]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | if (!defined $mid) { return undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # ARRAY or scalar first level: fall through to the generic walk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | # Walk dotted path (e.g. "user.address.city") through nested | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # structures. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 15 | my $arr = $haystack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 15 | foreach my $elem (@$parts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | if (!defined $arr) { return undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 38 | ▶ | if (ref $arr eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if (!($elem =~ /^\d+$/ && $elem < @$arr)) { return undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$elem =~ /^\d+$/u and $elem < @$arr
MC/DC0%0/2
$elem =~ /^\d+$/u and $elem < @$arr
$elem =~ /^\d+$/u
$elem < @$arr
Truth table33%1/3
A and B
A= $elem =~ /^\d+$/uB= $elem < @$arr
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 10 | $arr = $arr->[$elem]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } elsif (ref $arr eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 28 | ▶ | if (!exists $arr->{$elem}) { return undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 26 | $arr = $arr->{$elem}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 13 | return $arr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | # HTML-escape a string for safe output. Encodes & < > " ' to entities. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # Usable as a modifier: {$var|escape} or as a callable: {escape($var)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 42 | ▶ | sub escape { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
escape: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 42 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 42 | ▶ | if (ref $str eq 'ARRAY') { return 'ARRAY' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | if (ref $str eq 'HASH') { return 'HASH' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # Most values carry no special characters; one detection scan skips | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # all five substitution passes in the common case. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 41 | ▶ | if ($str =~ /[<>&"']/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 29 | $str =~ s/&/&/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 29 | $str =~ s/</</g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 29 | $str =~ s/>/>/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 29 | $str =~ s/"/"/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 29 | $str =~ s/'/'/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 41 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | # Bypass auto-escaping when auto_escape is on: {$var|noescape} or {$var|raw} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 10 | ▶ | sub noescape { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
noescape: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 10 | return shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 2 | ▶ | sub raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
raw: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 2 | return shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | # Apply auto-escaping if enabled, otherwise return value unchanged. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # Ref types (ARRAY/HASH) pass through unescaped. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | sub _esc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_esc: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my ($self, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | if (!$self->{auto_escape}) { return $val } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | if (ref $val) { return $val } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | return escape($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 213 | ▶ | sub ltrim_one { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ltrim_one: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 213 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 213 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 213 | my $char = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 213 | ▶ | if (length $str && substr($str, 0, 1) eq $char) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $str and substr($str, 0, 1) eq $char
MC/DC100%2/2
length $str and substr($str, 0, 1) eq $char
length $str
substr($str, 0, 1) eq $char
Truth table100%3/3
A and B
A= length $strB= substr($str, 0, 1) eq $char
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 18 | return substr($str, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 195 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 34 | ▶ | sub find_ending_tag { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_ending_tag: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 34 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 34 | ▶ | my $haystack = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 34 | my $open_tag = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 34 | my $close_tag = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | # Find the first close tag; if there's only one open tag before it, we're done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 34 | my $pos = index($haystack, $close_tag); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 34 | ▶ | if ($pos < 0) { return undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 33 | my $substr = substr($haystack, 0, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | # () = forces list context so $open_count is the match count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 33 | my $open_count = () = $substr =~ /\Q$open_tag\E/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 33 | ▶ | if ($open_count == 1) { return $pos } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | # Nested tags: scan forward through subsequent close tags until | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | # open/close counts balance (max 5 nesting levels) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 5 | my $close_len = length $close_tag; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 5 | my $offset = $pos + $close_len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 5 | foreach (0 .. 4) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 13 | $pos = index($haystack, $close_tag, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | if ($pos < 0) { return undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 13 | $substr = substr($haystack, 0, $pos + 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | # () = forces list context so $open_count is the match count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 13 | $open_count = () = $substr =~ /\Q$open_tag\E/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 13 | my $close_count = () = $substr =~ /\Q$close_tag\E/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 13 | ▶ | if ($open_count == $close_count) { return $pos } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 8 | $offset = $pos + $close_len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 40 | ▶ | sub get_tokens { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_tokens: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 40 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 40 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 40 | my $o = quotemeta($self->{open_delim}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 40 | my $c = quotemeta($self->{close_delim}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | # split into text/block tokens; capture keeps the {..} blocks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 40 | my @tokens = split /($o[^$c]+$c)/, $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 40 | ▶ | @tokens = grep { defined && length } @tokens; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $_ && length $_
MC/DC50%1/2
defined $_ && length $_
defined $_
length $_
Truth table66%2/3
A && B
A= defined $_B= length $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 40 | return @tokens; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 308 | ▶ | sub is_if_token { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_if_token: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 308 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 308 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 308 | ▶ | if ($str eq $self->{_tag_else}) { return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 244 | ▶ | if ($str eq $self->{_tag_if_close}) { return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # Token starts with '{if ' or '{elseif ', i.e. an opening conditional tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 197 | ▶ | if (index($str, $self->{_tag_if}) == 0 || index($str, $self->{_tag_elseif}) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
index($str, $self->{"_tag_if"}) == 0 or index($str, $self->{"_tag_elseif"}) == 0
MC/DC100%2/2
index($str, $self->{"_tag_if"}) == 0 or index($str, $self->{"_tag_elseif"}) == 0
index($str, $self->{"_tag_if"}) == 0
index($str, $self->{"_tag_elseif"}) == 0
Truth table100%3/3
A or B
A= index($str, $self->{"_tag_if"}) == 0B= index($str, $self->{"_tag_elseif"}) == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 114 | my $inner = substr($str, length($self->{open_delim})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 114 | $inner =~ s/^\S+\s+//; # strip 'if ' or 'elseif ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 114 | $inner =~ s/\Q$self->{close_delim}\E$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 114 | return $inner; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 83 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # Private methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 36 | ▶ | sub _precompute_tags { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_precompute_tags: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 36 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 36 | my $o = $self->{open_delim}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 36 | my $c = $self->{close_delim}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | # Tag strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 36 | $self->{_tag_if} = "${o}if "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 36 | $self->{_tag_if_close} = "${o}/if${c}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 36 | $self->{_tag_else} = "${o}else${c}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 36 | $self->{_tag_elseif} = "${o}elseif "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 36 | $self->{_tag_foreach} = "${o}foreach "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 36 | $self->{_tag_foreach_close} = "${o}/foreach${c}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 36 | $self->{_tag_include} = "${o}include "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 36 | $self->{_tag_literal} = "${o}literal${c}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 36 | $self->{_tag_literal_close} = "${o}/literal${c}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 36 | $self->{_tag_comment_open} = "${o}*"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 36 | $self->{_tag_comment_close} = "*${c}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # Precomputed tag lengths (avoids repeated length() calls in hot loops) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 36 | $self->{_tag_if_len} = length($self->{_tag_if}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 36 | $self->{_tag_if_close_len} = length($self->{_tag_if_close}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 36 | $self->{_tag_foreach_len} = length($self->{_tag_foreach}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 36 | $self->{_tag_include_len} = length($self->{_tag_include}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 36 | $self->{_tag_literal_len} = length($self->{_tag_literal}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 36 | $self->{_tag_literal_close_len} = length($self->{_tag_literal_close}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # Precomputed quotemeta values (avoids per-call quotemeta in _get_blocks) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 36 | $self->{_od_qr} = quotemeta($o); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 36 | $self->{_cd_qr} = quotemeta($c); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | # Precompiled space-guard regex (avoids per-open-delimiter regex compile) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 36 | my $od_qr = $self->{_od_qr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 36 | my $cd_qr = $self->{_cd_qr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 36 | $self->{_space_guard_re} = qr/\s[$od_qr$cd_qr]\s/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | # Precompiled variable regex: {$var} or {$var.dot.path} or {$var|modifiers...}. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | # A variable name is word chars and dots, optionally followed by a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | # modifier chain. Anything else (e.g. {$x - 3}) is an expression block. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 36 | $self->{_re_var_simple} = qr/^\Q$o\E\$(\w[\w.]*)\Q$c\E$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 36 | $self->{_re_var_full} = qr/^\Q$o\E\$(\w[\w.]*(?:\|.*)?)\Q$c\E$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | # Precompiled foreach regex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 36 | $self->{_re_foreach} = qr/^\Q$o\Eforeach (\$\w[\w.]*) as \$(\w+)(?: => \$(\w+))?\Q$c\E(.+)\Q$o\E\/foreach\Q$c\E$/s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | # Precompiled literal regex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 36 | $self->{_re_literal} = qr/^\Q$o\Eliteral\Q$c\E(.+)\Q$o\E\/literal\Q$c\E$/s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | # Precompiled expression catch-all regex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 36 | $self->{_re_expr} = qr/^\Q$o\E(.+)\Q$c\E$/s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # Precompiled comparison against a dotted path, e.g. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | # $__S->{sluz_pfx_user}->{role} eq "admin" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 36 | my $pfx_qr = quotemeta($self->{var_prefix}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 36 | $self->{_re_cmp_dotted} = qr/^\$__S->\{${pfx_qr}_(\w+)\}->\{(\w+)\}\s*(==|!=|eq|ne|>=|<=|>|<)\s*(?:"([^"]*)"|'([^']*)'|(-?\d+(?:\.\d+)?))$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | # Key prefix used to look a variable up in the __S hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 36 | $self->{_prefix} = $self->{var_prefix} . '_'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | # Precompiled simple if regex (no else/elseif) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 36 | $self->{_re_if_simple} = qr/\Q$o\Eif (.+?)\Q$c\E(.+)\Q$o\E\/if\Q$c\E/s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | # Precomputed ord values for fast single-character delimiter checks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 36 | $self->{_od_ord} = ord($o); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 36 | $self->{_cd_ord} = ord($c); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 36 | $self->{_dollar_ord} = ord('$'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | # Precompiled modifier-split regexes (avoids per-modifier-call recompile) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 36 | $self->{_pipe_re} = qr/\|(?![^"]*"(?:(?:[^"]*"){2})*[^"]*$)(?![^']*'(?:(?:[^']*'){2})*[^']*$)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 36 | $self->{_comma_re} = qr/,(?=(?:[^"]*"[^"]*")*[^"]*$)(?=(?:[^']*'[^']*')*[^']*$)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 36 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 4 | ▶ | sub _get_perl_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_perl_file: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 4 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 4 | my $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 4 | ▶ | while (caller($i)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 10 | $file = (caller($i))[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 10 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 4 | ▶ | return $file || __FILE__; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$file || __FILE__
MC/DC0%0/1
$file || __FILE__
$file
Truth table50%1/2
A
A= $file
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 21 | ▶ | sub _get_tpl_content { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_tpl_content: called CC=11 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 21 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 21 | ▶ | my $tpl_file = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 21 | $self->{tpl_file} = $tpl_file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 21 | my $tf = $tpl_file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 21 | ▶ | if ($self->{perl_file_dir}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 14 | $tf = $self->{perl_file_dir} . "/$tf"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 21 | ▶ | if (!length($tpl_file)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 1 | $self->_error_out("Template file name is empty", 86801); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 20 | ▶ | if ($tpl_file eq SLUZ_INLINE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 9 | my ($c, $line_offset) = $self->_get_inline_content($self->{perl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 9 | ▶ | if (defined $c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 9 | $self->{tpl_file_display} = $self->{perl_file}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 9 | $self->{tpl_line_offset} = $line_offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 9 | return $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | delete $self->{tpl_file_display}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | delete $self->{tpl_line_offset}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 11 | delete $self->{tpl_file_display}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 11 | delete $self->{tpl_line_offset}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 11 | ▶ | if ($tf && !-r $tf) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$tf and not -r $tf
MC/DC50%1/2
$tf and not -r $tf
$tf
not -r $tf
Truth table66%2/3
A and not(B)
A= $tfB= not -r $tf
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 2 | $self->_error_out("Unable to load template file `$tf`", 42280); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 9 | ▶ | if ($tf) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 9 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 9 | ▶ | open my $fh, '<', $tf or $self->_error_out("Cannot open `$tf`: $!", 13983); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 9 | my $str = <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 9 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 9 | ▶ | return $str // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$str // ""
MC/DC0%0/1
$str // ""
$str
Truth table50%1/2
A
A= $str
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 15 | ▶ | sub _get_inline_content { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_inline_content: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 15 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 15 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | # Check if it's cached | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 15 | ▶ | if (exists $self->{_inline_cache}{$file}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 5 | return @{ $self->{_inline_cache}{$file} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | # Slurp in the whole file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 10 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 10 | ▶ | open my $fh, '<:raw', $file or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 10 | my $str = <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 10 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | # Look for a __DATA__ marker at the start of a line. A mention inside a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | # comment or string (e.g. "# __DATA__ is below") must not match. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 10 | ▶ | if ($str !~ /^__DATA__/m) { return undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 9 | my $idx = $-[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | # Find first \n after the marker (handles both LF and CRLF files) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 9 | my $nl = index($str, "\n", $idx); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 9 | my $before; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | my $content; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 9 | ▶ | if ($nl < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | # No newline after marker: data runs to EOF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 1 | $before = $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 1 | $content = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 8 | $before = substr($str, 0, $nl + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 8 | $content = substr($str, $nl + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 9 | my $line_offset = $before =~ tr/\n//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 9 | $self->{_inline_cache}{$file} = [$content, $line_offset]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 9 | return @{ $self->{_inline_cache}{$file} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | # Tokenizer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 522 | ▶ | sub _get_blocks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_blocks: called CC=80 SCAR=43.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 522 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 522 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | # Check blocks cache — avoids re-tokenizing the same payload string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | # (e.g. an {if} payload re-parsed on every iteration of a {foreach} loop) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 522 | ▶ | if (exists $self->{_blocks_cache}{$str}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 6 | return @{$self->{_blocks_cache}{$str}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 516 | my $od = $self->{open_delim}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 516 | my $cd = $self->{close_delim}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 516 | my $tag_if = $self->{_tag_if}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 516 | my $tag_foreach = $self->{_tag_foreach}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 516 | my $tag_literal = $self->{_tag_literal}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 516 | my $slen = length $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 516 | my $start = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 516 | my $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | my @blocks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 516 | my $z = index($str, $od); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 516 | ▶ | if ($z < 0) { $z = $slen } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 516 | ▶ | for ($i = $z; $i < $slen; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 1450 | my $char = substr($str, $i, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 1450 | my $is_open = $char eq $od; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 1450 | my $is_closed = $char eq $cd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 1450 | ▶ | if (!$is_open && !$is_closed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$is_open or $is_closed
MC/DC100%2/2
$is_open or $is_closed
$is_open
$is_closed
Truth table100%3/3
A or B
A= $is_openB= $is_closed
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 501 | my $next_open = index($str, $od, $i); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 501 | ▶ | if ($next_open < 0) { $next_open = $slen } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 501 | my $next_close = index($str, $cd, $i); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 501 | ▶ | if ($next_close < 0) { $next_close = $slen } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 501 | ▶ | if ($next_open < $next_close) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 9 | $i = $next_open - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 492 | $i = $next_close - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 501 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 949 | my $has_len = $start != $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 949 | my $is_comment = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 949 | ▶ | if ($is_open) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 485 | my $prev_c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 485 | ▶ | if ($i > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 64 | $prev_c = substr($str, $i - 1, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 421 | $prev_c = ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 485 | my $next_c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 485 | ▶ | if ($i + 1 < $slen) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 485 | $next_c = substr($str, $i + 1, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | $next_c = ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 485 | my $chk = $prev_c . $char . $next_c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 485 | ▶ | if ($chk =~ $self->{_space_guard_re}) { $is_open = 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 485 | ▶ | if ($next_c eq '*') { $is_comment = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 949 | ▶ | if ($is_open && $has_len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$is_open and $has_len
MC/DC100%2/2
$is_open and $has_len
$is_open
$has_len
Truth table100%3/3
A and B
A= $is_openB= $has_len
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 55 | push @blocks, [substr($str, $start, $i - $start), $i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 55 | $start = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | } elsif ($is_closed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 464 | my $len = $i - $start + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 464 | my $block = substr($str, $start, $len); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 464 | my $matched_block; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 464 | ▶ | if (index($block, $tag_if) == 0) { $matched_block = 'if' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 72 | elsif (index($block, $tag_foreach) == 0) { $matched_block = 'foreach' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 22 | elsif (index($block, $tag_literal) == 0) { $matched_block = 'literal' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 464 | my $found_close = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 464 | ▶ | if ($matched_block) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 196 | my $close_tag = "${od}/${matched_block}${cd}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 196 | my $close_tag_len = length $close_tag; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 196 | my $first_literal_close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 196 | $found_close = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 196 | foreach my $j (($i + 1) .. (length($str) - 1)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 3925 | ▶ | if (substr($str, $j, 1) eq $cd) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | # Preserve the first literal close as a fallback when its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | # payload contains raw {literal} text without a matching | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | # nested close. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 418 | ▶ | if ($matched_block eq 'literal' && !defined $first_literal_close) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$matched_block eq "literal" and not defined $first_literal_close
MC/DC100%2/2
$matched_block eq "literal" and not defined $first_literal_close
$matched_block eq "literal"
not defined $first_literal_close
Truth table100%3/3
A and not(B)
A= $matched_block eq "literal"B= not defined $first_literal_close
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 34 | my $tag_end = substr($str, $j - $close_tag_len + 1, $close_tag_len); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 34 | ▶ | if ($tag_end eq $close_tag) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 21 | $first_literal_close = $j; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 418 | my $tmp = substr($str, $start, $j - $start + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 418 | my $oc = () = $tmp =~ /\Q${od}${matched_block}\E/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 418 | my $cc = () = $tmp =~ /\Q${close_tag}\E/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 418 | ▶ | if ($oc == $cc) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 185 | $block = $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 185 | $found_close = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 185 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 196 | ▶ | if (!$found_close) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | # A literal payload may itself begin with {literal} without a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | # matching nested close. In that case its first close ends the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | # outer literal; a missing close remains an unclosed-tag error. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 11 | ▶ | if (defined $first_literal_close) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 6 | $block = substr($str, $start, $first_literal_close - $start + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 6 | $found_close = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 5 | $block = substr($str, $start); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | # Whitespace immediately inside the delimiters on EITHER side | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | # is a syntax error #50981, since a tag must hug its delimiters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | # (e.g. "{ $foo}", "{$foo }", "{ $foo }"). Only genuine template | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | # tags are subject to this rule. A block whose inner content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | # contains '{', '}' or ';' is literal text (e.g. a JS snippet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | # "function(foo) { $i = 10; }") and is left alone. Comment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | # blocks ({* ... *}) are exempt too. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 464 | ▶ | if (length($block) >= 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $block >= 3 and index($block, $self->{"_tag_comment_open"}) != 0
MC/DC50%1/2
length $block >= 3 and index($block, $self->{"_tag_comment_open"}) != 0
length $block >= 3
index($block, $self->{"_tag_comment_open"}) != 0
Truth table66%2/3
A and B
A= length $block >= 3B= index($block, $self->{"_tag_comment_open"}) != 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | && index($block, $self->{_tag_comment_open}) != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 463 | my $inner = substr($block, 1, length($block) - 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 463 | ▶ | if ($inner !~ /[{};]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 275 | my $inner_first = substr($block, 1, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 275 | my $inner_last = substr($block, length($block) - 2, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 275 | my $lead_ws = ($inner_first =~ /\s/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 275 | my $tail_ws = ($inner_last =~ /\s/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 275 | ▶ | if ($lead_ws || $tail_ws) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$lead_ws or $tail_ws
MC/DC100%2/2
$lead_ws or $tail_ws
$lead_ws
$tail_ws
Truth table100%3/3
A or B
A= $lead_wsB= $tail_ws
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 9 | my ($line, $col, $file) = $self->_get_char_location($start, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 9 | $self->_error_out( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | "Whitespace next to delimiter in tag `$block` in `$file` on line #$line", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 50981 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | # A {literal} block that sits alone on its own line (the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | # {literal} and {/literal} tags each occupy a line of their | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | # own) should not emit the \n belonging to those tag lines. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | # This mirrors the comment-line handling below. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 455 | my $orig_block_len = length($block); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 455 | ▶ | if ($matched_block && $matched_block eq 'literal' && $found_close) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$matched_block and $matched_block eq "literal" and $found_close
$matched_block and $matched_block eq "literal"
MC/DC100%3/3
$matched_block and $matched_block eq "literal" and $found_close
$matched_block
$matched_block eq "literal"
$found_close
Truth table100%4/4
A and B and C
A= $matched_blockB= $matched_block eq "literal"C= $found_close
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 21 | my $ltag = $self->{_tag_literal}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 21 | my $rtag = $self->{_tag_literal_close}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 21 | my $l_len = $self->{_tag_literal_len}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 21 | my $r_len = $self->{_tag_literal_close_len}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 21 | my $inner = substr($block, $l_len, length($block) - $l_len - $r_len); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 21 | ▶ | my $begins_line = ($start == 0) || substr($str, $start - 1, 1) eq "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$start == 0 || substr($str, $start - 1, 1) eq "\n"
MC/DC50%1/2
$start == 0 || substr($str, $start - 1, 1) eq "\n"
$start == 0
substr($str, $start - 1, 1) eq "\n"
Truth table66%2/3
A || B
A= $start == 0B= substr($str, $start - 1, 1) eq "\n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 21 | my $after_pos = $start + length($block); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 21 | ▶ | my $ends_line = ($after_pos >= $slen) || substr($str, $after_pos, 1) eq "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$after_pos >= $slen || substr($str, $after_pos, 1) eq "\n"
MC/DC50%1/2
$after_pos >= $slen || substr($str, $after_pos, 1) eq "\n"
$after_pos >= $slen
substr($str, $after_pos, 1) eq "\n"
Truth table66%2/3
A || B
A= $after_pos >= $slenB= substr($str, $after_pos, 1) eq "\n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 21 | ▶ | if ($begins_line && length($inner) && substr($inner, 0, 1) eq "\n") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$begins_line and length $inner and substr($inner, 0, 1) eq "\n"
$begins_line and length $inner
MC/DC66%2/3
$begins_line and length $inner and substr($inner, 0, 1) eq "\n"
$begins_line
length $inner
substr($inner, 0, 1) eq "\n"
Truth table75%3/4
A and B and C
A= $begins_lineB= length $innerC= substr($inner, 0, 1) eq "\n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 4 | $inner = substr($inner, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 21 | ▶ | if ($ends_line && length($inner) && substr($inner, -1) eq "\n") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$ends_line and length $inner and substr($inner, -1) eq "\n"
$ends_line and length $inner
MC/DC66%2/3
$ends_line and length $inner and substr($inner, -1) eq "\n"
$ends_line
length $inner
substr($inner, -1) eq "\n"
Truth table75%3/4
A and B and C
A= $ends_lineB= length $innerC= substr($inner, -1) eq "\n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 4 | $inner = substr($inner, 0, -1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 21 | $block = $ltag . $inner . $rtag; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 455 | ▶ | if (length($block)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 455 | push @blocks, [$block, $i] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 455 | $start += $orig_block_len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 455 | $i = $start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 940 | ▶ | if ($is_comment) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 34 | my $end = $self->find_ending_tag(substr($str, $start), $self->{_tag_comment_open}, $self->{_tag_comment_close}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 34 | ▶ | if (!defined $end) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 1 | my ($line, $col, $file) = $self->_get_char_location($i, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 1 | $self->_error_out("Missing closing `$self->{_tag_comment_close}` for comment in `$file` on line #$line", 48724); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 33 | my $after = $start + $end + length($self->{_tag_comment_close}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 33 | ▶ | my $pre_nl = ($i == 0 || substr($str, $i - 1, 1) eq "\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$i == 0 || substr($str, $i - 1, 1) eq "\n"
MC/DC100%2/2
$i == 0 || substr($str, $i - 1, 1) eq "\n"
$i == 0
substr($str, $i - 1, 1) eq "\n"
Truth table100%3/3
A || B
A= $i == 0B= substr($str, $i - 1, 1) eq "\n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 33 | ▶ | my $post_nl = ($after >= $slen || substr($str, $after, 1) eq "\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$after >= $slen || substr($str, $after, 1) eq "\n"
MC/DC100%2/2
$after >= $slen || substr($str, $after, 1) eq "\n"
$after >= $slen
substr($str, $after, 1) eq "\n"
Truth table100%3/3
A || B
A= $after >= $slenB= substr($str, $after, 1) eq "\n"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 33 | ▶ | if ($pre_nl && $post_nl && $after < $slen) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$pre_nl and $post_nl and $after < $slen
$pre_nl and $post_nl
MC/DC100%3/3
$pre_nl and $post_nl and $after < $slen
$pre_nl
$post_nl
$after < $slen
Truth table100%4/4
A and B and C
A= $pre_nlB= $post_nlC= $after < $slen
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 8 | $after++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 33 | $start = $after; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 33 | $i = $start - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 506 | ▶ | if ($start < $slen) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 108 | push @blocks, [substr($str, $start), $i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | # Strip leading newline from text blocks that follow {if} or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | # {foreach} blocks, to avoid double-newlines when the block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | # payload already ends with \n. The strip only happens when the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | # block is written in "block style" — i.e. its content ends with a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | # newline of its own. When the block is written inline (the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | # content sits on the same line as the closing tag) the newline | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | # that follows the block is real content and must be kept. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 506 | my $prev_is_if = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 506 | my $tag_foreach_close = $self->{_tag_foreach_close}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 506 | foreach my $i (0 .. $#blocks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 618 | ▶ | my $bstr = $blocks[$i][0] // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$blocks[$i][0] // ""
MC/DC0%0/1
$blocks[$i][0] // ""
$blocks[$i][0]
Truth table50%1/2
A
A= $blocks[$i][0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 618 | ▶ | my $cur_is_if = (index($bstr, $tag_if) == 0 || index($bstr, $tag_foreach) == 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
index($bstr, $tag_if) == 0 || index($bstr, $tag_foreach) == 0
MC/DC100%2/2
index($bstr, $tag_if) == 0 || index($bstr, $tag_foreach) == 0
index($bstr, $tag_if) == 0
index($bstr, $tag_foreach) == 0
Truth table100%3/3
A || B
A= index($bstr, $tag_if) == 0B= index($bstr, $tag_foreach) == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 618 | ▶ | if ($prev_is_if) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 15 | ▶ | my $prev = $blocks[$i-1][0] // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$blocks[$i - 1][0] // ""
MC/DC0%0/1
$blocks[$i - 1][0] // ""
$blocks[$i - 1][0]
Truth table50%1/2
A
A= $blocks[$i - 1][0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 15 | my $should_strip = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 15 | ▶ | if (index($prev, $tag_foreach) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 6 | $should_strip = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 6 | ▶ | if ($prev =~ /^\Q$tag_foreach\E.+?\}(.*)\Q$tag_foreach_close\E$/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 6 | ▶ | $should_strip = (substr($1, -1) eq "\n") ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | } elsif (index($prev, $tag_if) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 9 | $should_strip = $self->_if_block_is_block_style($prev); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 15 | ▶ | if ($should_strip) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 4 | $blocks[$i][0] = $self->ltrim_one($bstr, "\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 618 | $prev_is_if = $cur_is_if; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | # Pre-classify blocks once so renders dispatch on an integer type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | # instead of re-running substr/regex checks on every parse. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | # type: -1=empty 0=text 1=simple_var 2=mod_var 3=if 4=foreach | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | # 5=include 6=literal 7=expr 9=unknown (_process_block fallback) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 506 | my $var_tag = "${od}\$"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 506 | my $od_ord = $self->{_od_ord}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 506 | my $tag_if_close = $self->{_tag_if_close}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 506 | my $tag_include = $self->{_tag_include}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 506 | my $re_var_full = $self->{_re_var_full}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 506 | my $re_foreach = $self->{_re_foreach}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 506 | my $re_literal = $self->{_re_literal}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 506 | my $re_expr = $self->{_re_expr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 506 | foreach my $b (@blocks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 618 | my $bs = $b->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 0 | ▶ | if (!length $bs) { $b->[2] = -1; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 618 | ▶ | if (ord($bs) != $od_ord) { $b->[2] = 0; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 457 | ▶ | if (substr($bs, 0, 2) eq $var_tag && $bs =~ $re_var_full) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
substr($bs, 0, 2) eq $var_tag and $bs =~ /$re_var_full/u
MC/DC100%2/2
substr($bs, 0, 2) eq $var_tag and $bs =~ /$re_var_full/u
substr($bs, 0, 2) eq $var_tag
$bs =~ /$re_var_full/u
Truth table100%3/3
A and B
A= substr($bs, 0, 2) eq $var_tagB= $bs =~ /$re_var_full/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 210 | my $inner = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 210 | ▶ | if (index($inner, '|') < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 124 | $b->[2] = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 124 | $b->[3] = $inner; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 124 | ▶ | $b->[4] = (index($inner, '.') >= 0) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 86 | $b->[2] = 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 86 | $b->[3] = $inner; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 210 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 247 | ▶ | if (substr($bs, 0, $self->{_tag_if_len}) eq $tag_if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
substr($bs, 0, $self->{"_tag_if_len"}) eq $tag_if and substr($bs, -$self->{"_tag_if_close_len"}) eq $tag_if_close
MC/DC100%2/2
substr($bs, 0, $self->{"_tag_if_len"}) eq $tag_if and substr($bs, -$self->{"_tag_if_close_len"}) eq $tag_if_close
substr($bs, 0, $self->{"_tag_if_len"}) eq $tag_if
substr($bs, -$self->{"_tag_if_close_len"}) eq $tag_if_close
Truth table100%3/3
A and B
A= substr($bs, 0, $self->{"_tag_if_len"}) eq $tag_ifB= substr($bs, -$self->{"_tag_if_close_len"}) eq $tag_if_close
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | && substr($bs, -$self->{_tag_if_close_len}) eq $tag_if_close) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 99 | $b->[2] = 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 99 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 148 | ▶ | if (substr($bs, 0, $self->{_tag_foreach_len}) eq $tag_foreach && $bs =~ $re_foreach) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
substr($bs, 0, $self->{"_tag_foreach_len"}) eq $tag_foreach and $bs =~ /$re_foreach/u
MC/DC100%2/2
substr($bs, 0, $self->{"_tag_foreach_len"}) eq $tag_foreach and $bs =~ /$re_foreach/u
substr($bs, 0, $self->{"_tag_foreach_len"}) eq $tag_foreach
$bs =~ /$re_foreach/u
Truth table100%3/3
A and B
A= substr($bs, 0, $self->{"_tag_foreach_len"}) eq $tag_foreachB= $bs =~ /$re_foreach/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 71 | $b->[2] = 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 71 | $b->[3] = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 71 | $b->[4] = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 71 | $b->[5] = $3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 71 | $b->[6] = $4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 71 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 77 | ▶ | if (substr($bs, 0, $self->{_tag_include_len}) eq $tag_include) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 11 | $b->[2] = 5; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 11 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 66 | ▶ | if (substr($bs, 0, $self->{_tag_literal_len}) eq $tag_literal && $bs =~ $re_literal) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
substr($bs, 0, $self->{"_tag_literal_len"}) eq $tag_literal and $bs =~ /$re_literal/u
MC/DC100%2/2
substr($bs, 0, $self->{"_tag_literal_len"}) eq $tag_literal and $bs =~ /$re_literal/u
substr($bs, 0, $self->{"_tag_literal_len"}) eq $tag_literal
$bs =~ /$re_literal/u
Truth table100%3/3
A and B
A= substr($bs, 0, $self->{"_tag_literal_len"}) eq $tag_literalB= $bs =~ /$re_literal/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 21 | $b->[2] = 6; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 21 | $b->[3] = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 21 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 45 | ▶ | if ($bs =~ $re_expr) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 35 | $b->[2] = 7; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 35 | $b->[3] = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 35 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 10 | $b->[2] = 9; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | 506 | $self->{_blocks_cache}{$str} = \@blocks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 506 | return @blocks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | # Internal callers can reuse the cached arrayref without copying it into a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | # temporary list. Keep _get_blocks() list-returning for existing callers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 471 | ▶ | sub _get_blocks_ref { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_blocks_ref: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 471 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 471 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 471 | ▶ | if (!exists $self->{_blocks_cache}{$str}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 440 | $self->_get_blocks($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 461 | return $self->{_blocks_cache}{$str}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 499 | ▶ | sub _process_blocks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_blocks: called CC=34 SCAR=40.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 499 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 499 | my $blocks = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 499 | my $out = shift; # Optional: ref to append output to (avoids temp string + concat) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | # Blocks arrive pre-classified from _get_blocks (cached), so dispatch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | # is a plain integer compare — no substr/regex per block per render. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | # type: -1=empty 0=text 1=simple_var 2=mod_var 3=if 4=foreach | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | # 5=include 6=literal 7=expr 9=unknown (_process_block fallback) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 499 | ▶ | if ($out) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 100 | foreach my $x (@$blocks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 108 | ▶ | my $type = $x->[2] // 9; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$x->[2] // 9
MC/DC0%0/1
$x->[2] // 9
$x->[2]
Truth table50%1/2
A
A= $x->[2]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 108 | ▶ | if ($type == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 9 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 81 | $$out .= $x->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | } elsif ($type == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | my $val = $x->[4] ? $self->array_dive($x->[3], $self->{tpl_vars}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 17 | ▶ | : $self->{tpl_vars}{$x->[3]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 0 | ▶ | if (ref $val eq 'ARRAY') { $$out .= 'ARRAY' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 0 | elsif (ref $val eq 'HASH') { $$out .= 'HASH' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 17 | ▶ | elsif (defined $val) { $$out .= ($self->{auto_escape} ? escape($val) : $val) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | } elsif ($type == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 1 | $self->{char_pos} = $x->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 1 | $$out .= $self->_variable_block($x->[3]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | } elsif ($type == 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | 9 | $self->{char_pos} = $x->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 9 | $$out .= $self->_if_block($x->[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | } elsif ($type == 4) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 0 | $self->{char_pos} = $x->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 0 | $$out .= $self->_foreach_block($x->[3], $x->[4], $x->[5], $x->[6]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | } elsif ($type == 6) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 0 | $$out .= $x->[3]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | } elsif ($type == 5) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | 0 | $self->{char_pos} = $x->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 0 | $$out .= $self->_include_block($x->[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | } elsif ($type == 7) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 0 | $self->{char_pos} = $x->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 0 | $$out .= $self->_expression_block($x->[0], $x->[3]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | } elsif ($type != -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | 0 | $$out .= $self->_process_block($x->[0], $x->[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 100 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | 399 | my $html = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 399 | foreach my $x (@$blocks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 481 | ▶ | my $type = $x->[2] // 9; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$x->[2] // 9
MC/DC0%0/1
$x->[2] // 9
$x->[2]
Truth table50%1/2
A
A= $x->[2]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 481 | ▶ | if ($type == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 9 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 93 | $html .= $x->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | } elsif ($type == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | my $val = $x->[4] ? $self->array_dive($x->[3], $self->{tpl_vars}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 68 | ▶ | : $self->{tpl_vars}{$x->[3]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 68 | ▶ | if (ref $val eq 'ARRAY') { $html .= 'ARRAY' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 0 | elsif (ref $val eq 'HASH') { $html .= 'HASH' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 57 | ▶ | elsif (defined $val) { $html .= ($self->{auto_escape} ? escape($val) : $val) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | } elsif ($type == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 79 | $self->{char_pos} = $x->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 79 | $html .= $self->_variable_block($x->[3]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | } elsif ($type == 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 75 | $self->{char_pos} = $x->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 75 | $html .= $self->_if_block($x->[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | } elsif ($type == 4) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 91 | $self->{char_pos} = $x->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | 91 | $html .= $self->_foreach_block($x->[3], $x->[4], $x->[5], $x->[6]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | } elsif ($type == 6) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 17 | $html .= $x->[3]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | } elsif ($type == 5) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 12 | $self->{char_pos} = $x->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | 12 | $html .= $self->_include_block($x->[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | } elsif ($type == 7) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | 36 | $self->{char_pos} = $x->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | 36 | $html .= $self->_expression_block($x->[0], $x->[3]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | } elsif ($type != -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | 10 | $html .= $self->_process_block($x->[0], $x->[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | 372 | return $html; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | 10 | ▶ | sub _process_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_block: called CC=14 SCAR=30.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 10 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 10 | ▶ | my $char_pos = shift // -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // -1
MC/DC0%0/1
shift() // -1
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 10 | $self->{char_pos} = $char_pos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 10 | my $od = $self->{open_delim}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | 10 | my $cd_ord = $self->{_cd_ord}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | # 1. Variable block {$foo} or {$foo|modifier} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | 10 | ▶ | if (substr($str, 0, 2) eq "${od}\$" && $str =~ $self->{_re_var_full}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
substr($str, 0, 2) eq "$od\$" and $str =~ /$self->{"_re_var_full"}/u
MC/DC0%0/2
substr($str, 0, 2) eq "$od\$" and $str =~ /$self->{"_re_var_full"}/u
substr($str, 0, 2) eq "$od\$"
$str =~ /$self->{"_re_var_full"}/u
Truth table66%2/3
A and B
A= substr($str, 0, 2) eq "$od\$"B= $str =~ /$self->{"_re_var_full"}/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 0 | return $self->_variable_block($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | # 2. If block {if ...}{/if} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 10 | ▶ | if (substr($str, 0, $self->{_tag_if_len}) eq $self->{_tag_if} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
substr($str, 0, $self->{"_tag_if_len"}) eq $self->{"_tag_if"} and substr($str, -$self->{"_tag_if_close_len"}) eq $self->{"_tag_if_close"}
MC/DC0%0/2
substr($str, 0, $self->{"_tag_if_len"}) eq $self->{"_tag_if"} and substr($str, -$self->{"_tag_if_close_len"}) eq $self->{"_tag_if_close"}
substr($str, 0, $self->{"_tag_if_len"}) eq $self->{"_tag_if"}
substr($str, -$self->{"_tag_if_close_len"}) eq $self->{"_tag_if_close"}
Truth table66%2/3
A and B
A= substr($str, 0, $self->{"_tag_if_len"}) eq $self->{"_tag_if"}B= substr($str, -$self->{"_tag_if_close_len"}) eq $self->{"_tag_if_close"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | && substr($str, -$self->{_tag_if_close_len}) eq $self->{_tag_if_close}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 0 | return $self->_if_block($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | # 3. Foreach block {foreach ...}{/foreach} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | 10 | ▶ | if (substr($str, 0, $self->{_tag_foreach_len}) eq $self->{_tag_foreach} && $str =~ $self->{_re_foreach}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
substr($str, 0, $self->{"_tag_foreach_len"}) eq $self->{"_tag_foreach"} and $str =~ /$self->{"_re_foreach"}/u
MC/DC0%0/2
substr($str, 0, $self->{"_tag_foreach_len"}) eq $self->{"_tag_foreach"} and $str =~ /$self->{"_re_foreach"}/u
substr($str, 0, $self->{"_tag_foreach_len"}) eq $self->{"_tag_foreach"}
$str =~ /$self->{"_re_foreach"}/u
Truth table66%2/3
A and B
A= substr($str, 0, $self->{"_tag_foreach_len"}) eq $self->{"_tag_foreach"}B= $str =~ /$self->{"_re_foreach"}/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | 0 | return $self->_foreach_block($1, $2, $3, $4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | # 4. Include block {include ...} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | 10 | ▶ | if (substr($str, 0, $self->{_tag_include_len}) eq $self->{_tag_include}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | 0 | return $self->_include_block($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | # 5. Literal block {literal}...{/literal} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | 10 | ▶ | if (substr($str, 0, $self->{_tag_literal_len}) eq $self->{_tag_literal} && $str =~ $self->{_re_literal}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
substr($str, 0, $self->{"_tag_literal_len"}) eq $self->{"_tag_literal"} and $str =~ /$self->{"_re_literal"}/u
MC/DC0%0/2
substr($str, 0, $self->{"_tag_literal_len"}) eq $self->{"_tag_literal"} and $str =~ /$self->{"_re_literal"}/u
substr($str, 0, $self->{"_tag_literal_len"}) eq $self->{"_tag_literal"}
$str =~ /$self->{"_re_literal"}/u
Truth table66%2/3
A and B
A= substr($str, 0, $self->{"_tag_literal_len"}) eq $self->{"_tag_literal"}B= $str =~ /$self->{"_re_literal"}/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 0 | return $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | # 6. Expression / function block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 10 | ▶ | if ($str =~ $self->{_re_expr}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 0 | return $self->_expression_block($str, $1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | # 7. Unclosed tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 10 | ▶ | if (ord(substr($str, -1)) != $cd_ord) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 9 | my $tag_start = $self->{char_pos} - length($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | 9 | my ($line, $col, $file) = $self->_get_char_location($tag_start, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | 9 | $self->_error_out("Unclosed tag `$str` in `$file` on line #$line", 45821); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | # 8. Fallthrough | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | 1 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | # Block handlers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 105 | ▶ | sub _variable_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_variable_block: called CC=37 SCAR=46.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 105 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | 105 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | # Fast path: no pipe means no modifier, just resolve the variable. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | # Avoids running the pipe-split regex on every plain variable block. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | 105 | ▶ | if (index($str, '|') < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | 0 | my $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | # Inline simple key lookup (no dots) — skips array_dive method call | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | 0 | ▶ | if (index($str, '.') < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | 0 | $ret = $self->{tpl_vars}{$str}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | 0 | $ret = $self->array_dive($str, $self->{tpl_vars}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 0 | ▶ | if (ref $ret eq 'ARRAY') { return 'ARRAY' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 0 | ▶ | if (ref $ret eq 'HASH') { return 'HASH' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 0 | ▶ | if (defined $ret) { return ($self->{auto_escape} ? escape($ret) : $ret) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | # Modifier chains are parsed once per unique string (crefs resolved, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | # literal params pre-evaluated) and cached; renders just walk the chain. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 105 | my $chain = $self->{_mod_chain_cache}{$str}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 105 | ▶ | if (!$chain && $str =~ /(.+?)\|(.*)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $chain and $str =~ /(.+?)\|(.*)/u
MC/DC50%1/2
not $chain and $str =~ /(.+?)\|(.*)/u
not $chain
$str =~ /(.+?)\|(.*)/u
Truth table66%2/3
not(A) and B
A= not $chainB= $str =~ /(.+?)\|(.*)/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | 85 | $chain = $self->_build_mod_chain($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | 81 | $self->{_mod_chain_cache}{$str} = $chain; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 101 | ▶ | if ($chain) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | my $tmp = $chain->{has_dot} ? $self->array_dive($chain->{key}, $self->{tpl_vars}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 101 | ▶ | : $self->{tpl_vars}{$chain->{key}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | # "nothing" is undef or an empty string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | 101 | ▶ | my $is_nothing = (!defined $tmp || (!ref($tmp) && $tmp eq '')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
!defined($tmp) || !ref($tmp) && $tmp eq ''
not ref $tmp and $tmp eq ""
MC/DC100%3/3
!defined($tmp) || !ref($tmp) && $tmp eq ''
!defined($tmp)
not ref $tmp
$tmp eq ""
Truth table100%4/4
not(A) || not(B) and C
A= !defined($tmp)B= not ref $tmpC= $tmp eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 101 | ▶ | if ($chain->{is_default}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | 29 | my $pre; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 29 | ▶ | if ($is_nothing) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 23 | $pre = $self->_eval_shape($chain->{default_shape}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 23 | ▶ | $pre = '' unless defined $pre; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | 6 | ▶ | $pre = $tmp // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$tmp // ""
MC/DC0%0/1
$tmp // ""
$tmp
Truth table50%1/2
A
A= $tmp
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | # Apply any modifiers that follow default: (e.g. |default:"x"|uc) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 29 | ▶ | foreach my $step (@{$chain->{steps} // []}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$chain->{"steps"} // []
MC/DC0%0/1
$chain->{"steps"} // []
$chain->{"steps"}
Truth table50%1/2
A
A= $chain->{"steps"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 9 | my @params = ($pre); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 9 | foreach my $sh (@{$step->[1]}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 0 | ▶ | if ($sh->[0] == 3) { push @params, $sh->[1] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 0 | else { push @params, $self->_eval_shape($sh) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | 9 | $pre = eval { $step->[0]->(@params) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 9 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 0 | $self->_error_out("Exception: $@", 79134); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | 29 | ▶ | if ($self->{auto_escape} && !$chain->{seen_noescape} && !$chain->{seen_escape}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$self->{"auto_escape"} and not $chain->{"seen_noescape"} and not $chain->{"seen_escape"}
$self->{"auto_escape"} and not $chain->{"seen_noescape"}
MC/DC66%2/3
$self->{"auto_escape"} and not $chain->{"seen_noescape"} and not $chain->{"seen_escape"}
$self->{"auto_escape"}
not $chain->{"seen_noescape"}
not $chain->{"seen_escape"}
Truth table75%3/4
A and not(B) and not(C)
A= $self->{"auto_escape"}B= not $chain->{"seen_noescape"}C= not $chain->{"seen_escape"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 3 | return escape($pre); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | 26 | return $pre; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | 72 | ▶ | if ($is_nothing) { return '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | 66 | my $pre = $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | 66 | foreach my $step (@{$chain->{steps}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | 71 | my @params = ($pre); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | 71 | foreach my $sh (@{$step->[1]}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | 16 | ▶ | if ($sh->[0] == 3) { push @params, $sh->[1] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | 1 | else { push @params, $self->_eval_shape($sh) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 71 | $pre = eval { $step->[0]->(@params) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | 71 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | 1 | $self->_error_out("Exception: $@", 79134); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | 65 | ▶ | if ($self->{auto_escape} && !$chain->{seen_noescape} && !$chain->{seen_escape}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$self->{"auto_escape"} and not $chain->{"seen_noescape"} and not $chain->{"seen_escape"}
$self->{"auto_escape"} and not $chain->{"seen_noescape"}
MC/DC100%3/3
$self->{"auto_escape"} and not $chain->{"seen_noescape"} and not $chain->{"seen_escape"}
$self->{"auto_escape"}
not $chain->{"seen_noescape"}
not $chain->{"seen_escape"}
Truth table100%4/4
A and not(B) and not(C)
A= $self->{"auto_escape"}B= not $chain->{"seen_noescape"}C= not $chain->{"seen_escape"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | 1 | return escape($pre); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | 64 | return $pre; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 0 | my $ret = $self->array_dive($str, $self->{tpl_vars}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | 0 | ▶ | if (ref $ret eq 'ARRAY') { return 'ARRAY' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | 0 | ▶ | if (ref $ret eq 'HASH') { return 'HASH' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | 0 | ▶ | if (defined $ret) { return ($self->{auto_escape} ? escape($ret) : $ret) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | # Parse a "var|mod|mod:args" string into a cached chain: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | # { key, has_dot, is_default, default_shape, steps, seen_escape, seen_noescape } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | # Each step is [cref, [param shapes...]]. Params that classify as literals | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | # are resolved once at build time (shape kind 3); the rest keep their shape | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | # for live evaluation each render. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | 85 | ▶ | sub _build_mod_chain { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_mod_chain: called CC=33 SCAR=38.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | 85 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | 85 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | 85 | my $mod = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | 85 | ▶ | my $chain = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | key => $key, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | has_dot => (index($key, '.') >= 0) ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | 85 | ▶ | if (index($mod, 'default:') >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | # Support default with optional trailing modifiers: |default:"x"|uc | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | # Split pipe-aware (not inside quotes) and locate the default: part. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | 29 | my $pipe_re = $self->{_pipe_re}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | 29 | my @parts = split $pipe_re, $mod; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | 29 | my $def_idx = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | 29 | my $def_arg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | 29 | for my $i (0 .. $#parts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | 29 | ▶ | if ($parts[$i] =~ /^default:(.*)/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | 29 | $def_idx = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | 29 | $def_arg = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | 29 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | 29 | ▶ | if ($def_idx >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | 29 | $chain->{is_default} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | 29 | $chain->{default_shape} = $self->_shape_of($def_arg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | # Build steps for any modifiers that follow default: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | 29 | my @post = @parts[$def_idx + 1 .. $#parts]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | # Also include modifiers before default? PHP ignores them; we preserve | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | # them as pre-steps only if they existed before default, but for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | # parity we treat default as first and post-steps as chain after fallback. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | # If there were pre-default modifiers, they are ignored (matching PHP). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | 29 | my @steps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | 29 | my $seen_escape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | 29 | my $seen_noescape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | 29 | foreach my $m_part (@post) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | 9 | ▶ | next if !length $m_part; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | 9 | my @x = split /:/, $m_part, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | 9 | ▶ | my $func = $x[0] // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$x[0] // ""
MC/DC0%0/1
$x[0] // ""
$x[0]
Truth table50%1/2
A
A= $x[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | 9 | ▶ | if ($func eq 'escape') { $seen_escape = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | 9 | ▶ | if ($func eq 'noescape' || $func eq 'raw') { $seen_noescape = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$func eq "noescape" or $func eq "raw"
MC/DC100%2/2
$func eq "noescape" or $func eq "raw"
$func eq "noescape"
$func eq "raw"
Truth table100%3/3
A or B
A= $func eq "noescape"B= $func eq "raw"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | 9 | ▶ | my $param_str = $x[1] // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$x[1] // ""
MC/DC0%0/1
$x[1] // ""
$x[1]
Truth table50%1/2
A
A= $x[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | 9 | my @shapes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | 9 | ▶ | if (length $param_str) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | 0 | $self->_check_mod_params($func, $param_str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | 0 | foreach my $p (split $self->{_comma_re}, $param_str) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | 0 | push @shapes, $self->_shape_of($p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | 9 | my $cref = $self->{_mod_cache}{$func}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | 9 | ▶ | if (!defined $cref) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | 14 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | 0 | ▶ | if (defined &{"main::$func"}) { $cref = \&{"main::$func"} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | 0 | elsif (defined &{$func}) { $cref = \&{$func} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | 0 | elsif (defined &{"CORE::$func"}) { $cref = \&{"CORE::$func"} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | 0 | else { $cref = 0 } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | 0 | $self->{_mod_cache}{$func} = $cref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | 9 | ▶ | if (!$cref) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | 0 | my ($line, $col, $file) = $self->_get_char_location($self->{char_pos}, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | 0 | $self->_error_out("Unknown function call `$func` in `$file` on line #$line", 47204); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | 9 | push @steps, [$cref, \@shapes]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | 29 | $chain->{steps} = \@steps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | 29 | $chain->{seen_escape} = $seen_escape; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | 29 | $chain->{seen_noescape} = $seen_noescape; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | 29 | return $chain; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | # Fallback: treat whole suffix as default value (legacy) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | 0 | my $dval = $mod; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | 0 | $dval =~ s/^.*?default://; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | 0 | $chain->{is_default} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | 0 | $chain->{default_shape} = $self->_shape_of($dval); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | 0 | $chain->{steps} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | 0 | $chain->{seen_escape} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | 0 | $chain->{seen_noescape} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | 0 | return $chain; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | 56 | my @steps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | 56 | my $seen_escape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | 56 | my $seen_noescape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | # Split on | not inside double or single quotes (supports chained | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | # modifiers like {$x|uc|substr:0,3}). Regex precompiled in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | # _precompute_tags to avoid per-call recompile cost. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | 56 | my $pipe_re = $self->{_pipe_re}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | 56 | foreach my $m_part (split $pipe_re, $mod) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | 61 | my @x = split /:/, $m_part, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | 61 | ▶ | my $func = $x[0] // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$x[0] // ""
MC/DC0%0/1
$x[0] // ""
$x[0]
Truth table50%1/2
A
A= $x[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | 61 | ▶ | if ($func eq 'escape') { $seen_escape = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | 61 | ▶ | if ($func eq 'noescape' || $func eq 'raw') { $seen_noescape = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$func eq "noescape" or $func eq "raw"
MC/DC100%2/2
$func eq "noescape" or $func eq "raw"
$func eq "noescape"
$func eq "raw"
Truth table100%3/3
A or B
A= $func eq "noescape"B= $func eq "raw"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | 61 | ▶ | my $param_str = $x[1] // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$x[1] // ""
MC/DC100%1/1
$x[1] // ""
$x[1]
Truth table100%2/2
A
A= $x[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | 61 | my @shapes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | 61 | ▶ | if (length $param_str) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | 18 | $self->_check_mod_params($func, $param_str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | # Split on commas not inside double or single quotes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | # (parameter separator in modifier calls like substr:2,2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | 16 | foreach my $p (split $self->{_comma_re}, $param_str) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | 18 | push @shapes, $self->_shape_of($p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | # Resolve the modifier coderef once per func name and cache it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | # Priority: main::, current package (Template::Sluz built-ins), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | # then CORE:: built-in operators. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | 59 | my $cref = $self->{_mod_cache}{$func}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | 59 | ▶ | if (!defined $cref) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | 14 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | 22 | ▶ | if (defined &{"main::$func"}) { $cref = \&{"main::$func"} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | 19 | elsif (defined &{$func}) { $cref = \&{$func} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | 10 | elsif (defined &{"CORE::$func"}) { $cref = \&{"CORE::$func"} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | 2 | else { $cref = 0 } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | 22 | $self->{_mod_cache}{$func} = $cref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | 59 | ▶ | if (!$cref) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | 2 | my ($line, $col, $file) = $self->_get_char_location($self->{char_pos}, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | 2 | $self->_error_out("Unknown function call `$func` in `$file` on line #$line", 47204); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | 57 | push @steps, [$cref, \@shapes]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | 52 | $chain->{steps} = \@steps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | 52 | $chain->{seen_escape} = $seen_escape; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | 52 | $chain->{seen_noescape} = $seen_noescape; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | 52 | return $chain; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | 119 | ▶ | sub _if_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_if_block: called CC=32 SCAR=37.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | 119 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | 119 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | 119 | my $rules = $self->{_if_rules_cache}{$str}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | 119 | ▶ | if (!$rules) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | 88 | $rules = $self->_build_if_rules($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | 88 | $self->{_if_rules_cache}{$str} = $rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | 119 | my $ret = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | 119 | my $tv = $self->{tpl_vars}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | 119 | foreach my $rule (@$rules) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | 150 | my $shape = $rule->[2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | 150 | my $kind = $shape->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | 150 | my $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | 150 | ▶ | if ($kind == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | # Comparison against a literal: [2, $key, $opc, $right, $numeric] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | 10 | my ($key, $opc, $right, $numeric) = @{$shape}[1, 2, 3, 4]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | 14 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | 10 | my $left = $tv->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | 10 | ▶ | if ($numeric) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | 9 | ▶ | if ($opc == 2) { $res = $left == $right } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | 2 | elsif ($opc == 3) { $res = $left != $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | 2 | elsif ($opc == 4) { $res = $left > $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | 1 | elsif ($opc == 5) { $res = $left < $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | 1 | elsif ($opc == 6) { $res = $left >= $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | 1 | else { $res = $left <= $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | 1 | ▶ | if ($opc == 0) { $res = $left eq $right } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | 0 | else { $res = $left ne $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | } elsif ($kind == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | # Variable reference: [1, $neg, $key, $converted] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | 82 | my ($neg, $key) = @{$shape}[1, 2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | 82 | my $v = $tv->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | 82 | ▶ | if (defined $v) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | 63 | ▶ | $res = $neg ? !$v : $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | } elsif (exists $tv->{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | 2 | ▶ | $res = $neg ? 1 : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | 17 | my ($tmp, $err) = $self->_peval($shape->[3]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | 17 | ▶ | if ($err) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | 0 | my ($line, $col, $file) = $self->_get_char_location($self->{char_pos}, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | 0 | $self->_error_out("Unable to evaluate condition `$rule->[0]` in `$file` on line #$line", 18933); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | 17 | $res = $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | } elsif ($kind == 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | 18 | $res = $shape->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | } elsif ($kind == 4) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | # Dotted comparison: [4, $root, $sub, $opc, $right, $numeric, $conv] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | 18 | my ($root, $sub, $opc, $right, $numeric) = @{$shape}[1, 2, 3, 4, 5]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | 18 | my $h = $self->{__S}{$self->{_prefix} . $root}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | 18 | ▶ | if (ref $h eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | 14 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | 18 | my $left = $h->{$sub}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | 18 | ▶ | if ($numeric) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | 2 | ▶ | if ($opc == 2) { $res = $left == $right } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | 0 | elsif ($opc == 3) { $res = $left != $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | 0 | elsif ($opc == 4) { $res = $left > $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | 0 | elsif ($opc == 5) { $res = $left < $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | 0 | elsif ($opc == 6) { $res = $left >= $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | 0 | else { $res = $left <= $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | 16 | ▶ | if ($opc == 0) { $res = $left eq $right } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | 0 | else { $res = $left ne $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | 0 | my ($tmp, $err) = $self->_peval($shape->[6]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | 0 | ▶ | if ($err) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | 0 | my ($line, $col, $file) = $self->_get_char_location($self->{char_pos}, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | 0 | $self->_error_out("Unable to evaluate condition `$rule->[0]` in `$file` on line #$line", 18933); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | 0 | $res = $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | 22 | my ($tmp, $err) = $self->_peval($shape->[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | 22 | ▶ | if ($err) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | 2 | my ($line, $col, $file) = $self->_get_char_location($self->{char_pos}, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | 2 | $self->_error_out("Unable to evaluate condition `$rule->[0]` in `$file` on line #$line", 18933); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | 20 | $res = $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | 148 | ▶ | if ($res) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | # The payload's blocks are tokenized once and remembered on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | # the rule, so repeated renders skip the cache lookup. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | 100 | my $in_blocks = $rule->[3]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | 100 | ▶ | if (!$in_blocks) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | 82 | my $payload = $rule->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | 82 | my $cached = $self->{_blocks_cache}{$payload}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | 82 | ▶ | $in_blocks = $cached ? $cached : [$self->_get_blocks($payload)]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | 82 | $rule->[3] = $in_blocks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | # Pass \$ret to _process_blocks so it appends directly — | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | # avoids a temp string allocation + concat per if-payload | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | # render. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | 100 | $self->_process_blocks($in_blocks, \$ret); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | 100 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | 117 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | # Parse an {if}/{elseif}/{else} block into its branches. Each branch is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | # a [condition, payload] pair; the payload has a single leading newline | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | # stripped, matching the way the branch is rendered. The result is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | # cached per block string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | 106 | ▶ | sub _if_payloads { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_if_payloads: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | 106 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | 106 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | 106 | my $cached = $self->{_if_payload_cache}{$str}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | 106 | ▶ | return $cached if $cached; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | 97 | my $od = $self->{open_delim}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | 97 | my $isimple_start = length($od) + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | 97 | my $else_check = $od . 'else'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | 97 | my $is_simple = index($str, $else_check, $isimple_start) < 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | 97 | my @rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | 97 | ▶ | if ($is_simple) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | 57 | $str =~ $self->{_re_if_simple}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1393 | 57 | ▶ | my $cond = $1 // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$1 // ""
MC/DC100%1/1
$1 // ""
$1
Truth table100%2/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1394 | 57 | ▶ | my $payload = $2 // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$2 // ""
MC/DC100%1/1
$2 // ""
$2
Truth table100%2/2
A
A= $2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1395 | 57 | $payload = $self->ltrim_one($payload, "\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1397 | 57 | @rules = ([$cond, $payload]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1398 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1399 | 40 | my @toks = $self->get_tokens($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1400 | 40 | @rules = $self->_if_rules_from_tokens(\@toks); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1403 | 97 | $self->{_if_payload_cache}{$str} = \@rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1404 | 97 | return \@rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1407 | # True when an {if} block is written in "block style", i.e. every one of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1408 | # its branches ends with a newline of its own. In that case the newline | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1409 | # that follows the closing {/if} tag is structural and is swallowed, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1410 | # the block does not leave a blank line behind. A block written inline | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1411 | # (its content sitting on the same line as the closing tag) keeps the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1412 | # newline, since there the newline is the content's own line ending. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1413 | 9 | ▶ | sub _if_block_is_block_style { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_if_block_is_block_style: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1414 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1415 | 9 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1417 | 9 | my $rules = eval { $self->_if_payloads($str) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1418 | # An unparsable block is reported when it is rendered; keep the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1419 | # historical behaviour here and let the error surface later. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1420 | 9 | ▶ | return 1 if !$rules; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1422 | 9 | foreach my $rule (@$rules) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1423 | 10 | ▶ | my $payload = $rule->[1] // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$rule->[1] // ""
MC/DC0%0/1
$rule->[1] // ""
$rule->[1]
Truth table50%1/2
A
A= $rule->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1424 | 10 | ▶ | next if !length($payload); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1425 | 9 | ▶ | return 0 if substr($payload, -1) ne "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1428 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1431 | # Parse an {if}/{elseif}/{else} block into a list of rules. Each rule | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1432 | # is [condition, payload, shape] and the shape carries a pre-classified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1433 | # form of the condition so that renders never have to re-parse it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1434 | 97 | ▶ | sub _build_if_rules { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_if_rules: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1435 | 97 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1436 | 97 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1438 | 97 | my $rules = $self->{_if_rules_cache}{$str}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1439 | 97 | ▶ | if (!$rules) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1440 | 97 | my $parsed = $self->_if_payloads($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1442 | 97 | my @rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1443 | # Pre-resolve each condition's shape once so renders skip | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1444 | # _convert_vars/_micro_optimize/_peval for simple conditions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1445 | 97 | foreach my $rule (@$parsed) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1446 | 145 | push @rules, [$rule->[0], $rule->[1], $self->_shape_of($rule->[0])]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1447 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1449 | 97 | $rules = \@rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1450 | 97 | $self->{_if_rules_cache}{$str} = $rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1451 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1453 | 97 | return $rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1454 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1456 | 106 | ▶ | sub _foreach_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_foreach_block: called CC=25 SCAR=32.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1457 | 106 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1458 | 106 | my $src_expr = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1459 | 106 | my $okey = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1460 | 106 | my $oval = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1461 | 106 | my $payload = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1462 | 106 | my $plan = shift; # optional: an already built plan | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1463 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1464 | # The plan caches everything about this loop that does not change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1465 | # between renders: the tokenized payload, the per-iteration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1466 | # bookkeeping flags, the save/restore key lists and a compiled | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1467 | # renderer for the loop body. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1468 | 106 | ▶ | if (!$plan) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1469 | 103 | ▶ | my $ckey = defined $oval ? $okey . "\x00" . $oval : $okey; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1470 | 103 | my $slot = $self->{_foreach_plans}{$ckey}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1471 | 103 | ▶ | $plan = $slot ? $slot->{$payload} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1472 | 103 | ▶ | $plan = $self->_foreach_plan($okey, $oval, $payload) if !$plan; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1473 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1474 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1475 | 106 | my $tv = $self->{tpl_vars}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1476 | 106 | my $ks = $self->{__S}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1478 | # Resolve the loop source via its cached shape — simple variable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1479 | # sources skip _convert_vars/_peval entirely on every render. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1480 | my $shape = $self->{_src_shape_cache}{$src_expr} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1481 | 106 | ▶ | // ($self->{_src_shape_cache}{$src_expr} = $self->_shape_of($src_expr)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"_src_shape_cache"}{$src_expr} // ($self->{"_src_shape_cache"}{$src_expr} = $self->_shape_of($src_expr))
MC/DC0%0/2
$self->{"_src_shape_cache"}{$src_expr} // ($self->{"_src_shape_cache"}{$src_expr} = $self->_shape_of($src_expr))
$self->{"_src_shape_cache"}{$src_expr}
($self->{"_src_shape_cache"}{$src_expr} = $self->_shape_of($src_expr))
Truth table66%2/3
A // B
A= $self->{"_src_shape_cache"}{$src_expr}B= ($self->{"_src_shape_cache"}{$src_expr} = $self->_shape_of($src_expr))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1482 | 106 | my $src; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1484 | 106 | my $skind = $shape->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1485 | 106 | ▶ | if ($skind == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1486 | # Plain variable reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1487 | 103 | my ($neg, $key) = @{$shape}[1, 2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1488 | 103 | my $v = $tv->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1489 | 103 | ▶ | if (defined $v) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1490 | 101 | ▶ | $src = $neg ? !$v : $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1491 | } elsif (exists $tv->{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1492 | 1 | ▶ | $src = $neg ? 1 : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1493 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1494 | 1 | ($src) = $self->_peval($shape->[3]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1495 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1496 | } elsif ($skind == 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1497 | 0 | $src = $shape->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1498 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1499 | 3 | $src = $self->_eval_shape($shape); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1500 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1502 | 106 | ▶ | if (!defined $src) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1503 | 2 | $src = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1504 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1505 | 104 | my $r = ref $src; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1506 | 104 | ▶ | if ($r ne 'ARRAY' && $r ne 'HASH') { $src = [$src] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$r ne "ARRAY" and $r ne "HASH"
MC/DC100%2/2
$r ne "ARRAY" and $r ne "HASH"
$r ne "ARRAY"
$r ne "HASH"
Truth table100%3/3
A and B
A= $r ne "ARRAY"B= $r ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1508 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1509 | # Save only the keys we'll modify — O(k) where k <= 5, vs O(n) for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1510 | # copying the entire tpl_vars/__S hashes. Big win for nested foreach. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1511 | 106 | my $tpl_keys = $plan->{tpl_keys}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1512 | 106 | my $ks_keys = $plan->{ks_keys}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1513 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1514 | 106 | my (@tpl_exists, @tpl_vals, @ks_exists, @ks_vals); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1515 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1516 | 106 | ▶ | if (@$tpl_keys) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1517 | 47 | foreach my $k (@$tpl_keys) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1518 | 57 | push @tpl_exists, exists $tv->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1519 | 57 | push @tpl_vals, $tv->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1520 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1521 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1522 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1523 | 106 | ▶ | if (@$ks_keys) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1524 | 34 | foreach my $k (@$ks_keys) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1525 | 43 | push @ks_exists, exists $ks->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1526 | 43 | push @ks_vals, $ks->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1527 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1528 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1529 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1530 | 106 | my $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1531 | 106 | ▶ | if ($plan->{sub}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1532 | 49 | $ret = $plan->{sub}->($self, $tv, $ks, $src, $plan); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1533 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1534 | 57 | $ret = $self->_foreach_render($plan, $src, $tv, $ks); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1535 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1537 | # Restore only the keys we modified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1538 | 106 | foreach my $i (0 .. $#$tpl_keys) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1539 | 57 | ▶ | if ($tpl_exists[$i]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1540 | 20 | $self->{tpl_vars}{$tpl_keys->[$i]} = $tpl_vals[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1541 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1542 | 37 | delete $self->{tpl_vars}{$tpl_keys->[$i]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1543 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1544 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1546 | 106 | ▶ | if ($plan->{need_eval}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1547 | 34 | foreach my $i (0 .. $#$ks_keys) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1548 | 43 | ▶ | if ($ks_exists[$i]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1549 | 17 | $self->{__S}{$ks_keys->[$i]} = $ks_vals[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1550 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1551 | 26 | delete $self->{__S}{$ks_keys->[$i]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1552 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1553 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1554 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1555 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1556 | 106 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1557 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1558 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1559 | # Build (and cache) the plan for one {foreach} loop. A plan holds the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1560 | # tokenized payload, the flags that decide which loop variables have to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1561 | # be published to tpl_vars/__S, the list of keys to save and restore | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1562 | # around the loop, and a compiled renderer for the loop body. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1563 | 64 | ▶ | sub _foreach_plan { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_foreach_plan: called CC=30 SCAR=34.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1564 | 64 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1565 | 64 | my $okey = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1566 | 64 | my $oval = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1567 | 64 | my $raw = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1568 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1569 | 64 | ▶ | my $ckey = defined $oval ? $okey . "\x00" . $oval : $okey; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1570 | 64 | my $slot = $self->{_foreach_plans}{$ckey}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1571 | 64 | ▶ | my $plan = $slot ? $slot->{$raw} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1572 | 64 | ▶ | return $plan if $plan; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1573 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1574 | 64 | my $payload = $self->ltrim_one($raw, "\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1575 | 64 | my $blocks = $self->_get_blocks_ref($payload); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1576 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1577 | # Simple variable/text loops do not execute expressions, so __S does not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1578 | # need to be updated for every item. This is especially useful for nested | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1579 | # and large loops. (Literals never reference variables either.) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1580 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1581 | # Additionally, per-iteration tpl_vars writes for the loop variables can | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1582 | # be skipped entirely when no block can read them through tpl_vars: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1583 | # that requires every block to be text/literal/simple-var, with no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1584 | # dotted simple var rooted at the loop variable (array_dive would read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1585 | # tpl_vars). Simple vars naming the loop variable are served directly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1586 | # from the current item in the dispatch below. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1587 | 64 | my $need_eval = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1588 | 64 | my $skip_key_write = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1589 | 64 | my $skip_val_write = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1590 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1591 | 64 | foreach my $b (@$blocks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1592 | 106 | my $t = $b->[2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1593 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1594 | 106 | ▶ | if ($t != 0 && $t != 1 && $t != 6 && $t != -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition88%8/9
$t != 0 and $t != 1 and $t != 6 and $t != -1
$t != 0 and $t != 1 and $t != 6
$t != 0 and $t != 1
MC/DC75%3/4
$t != 0 and $t != 1 and $t != 6 and $t != -1
$t != 0
$t != 1
$t != 6
$t != -1
Truth table80%4/5
A and B and C and D
A= $t != 0B= $t != 1C= $t != 6D= $t != -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1595 | 25 | $need_eval = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1596 | 25 | $skip_key_write = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1597 | 25 | $skip_val_write = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1598 | ▶ | } elsif ($t == 1 && $b->[4]) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$t == 1 and $b->[4]
MC/DC100%2/2
$t == 1 and $b->[4]
$t == 1
$b->[4]
Truth table100%3/3
A and B
A= $t == 1B= $b->[4]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1599 | 7 | my $var = $b->[3]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1600 | 7 | my $d = index($var, '.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1601 | 7 | my $root; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1603 | 7 | ▶ | if ($d < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1604 | 0 | $root = $var; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1605 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1606 | 7 | $root = substr($var, 0, $d); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1607 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1608 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1609 | 7 | ▶ | if ($root eq $okey) { $skip_key_write = 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1610 | 7 | ▶ | if (defined $oval && $root eq $oval) { $skip_val_write = 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $oval and $root eq $oval
MC/DC50%1/2
defined $oval and $root eq $oval
defined $oval
$root eq $oval
Truth table66%2/3
A and B
A= defined $ovalB= $root eq $oval
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1611 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1612 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1613 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1614 | 64 | my $pfx = $self->{var_prefix}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1615 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1616 | 64 | my $need_first = index($payload, '__FOREACH_FIRST') >= 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1617 | 64 | my $need_last = index($payload, '__FOREACH_LAST') >= 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1618 | 64 | my $need_index = index($payload, '__FOREACH_INDEX') >= 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1619 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1620 | 64 | my @tpl_keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1621 | 64 | ▶ | push @tpl_keys, $okey if !$skip_key_write; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1622 | 64 | ▶ | push @tpl_keys, $oval if defined $oval && !$skip_val_write; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $oval and not $skip_val_write
MC/DC100%2/2
defined $oval and not $skip_val_write
defined $oval
not $skip_val_write
Truth table100%3/3
A and not(B)
A= defined $ovalB= not $skip_val_write
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1623 | 64 | ▶ | push @tpl_keys, '__FOREACH_FIRST' if $need_first; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1624 | 64 | ▶ | push @tpl_keys, '__FOREACH_LAST' if $need_last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1625 | 64 | ▶ | push @tpl_keys, '__FOREACH_INDEX' if $need_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1626 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1627 | 64 | my @ks_keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1628 | 64 | ▶ | if ($need_eval) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1629 | 24 | push @ks_keys, "${pfx}_$okey"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1630 | 24 | ▶ | push @ks_keys, "${pfx}_$oval" if defined $oval; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1631 | 24 | ▶ | push @ks_keys, "${pfx}__FOREACH_FIRST" if $need_first; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1632 | 24 | ▶ | push @ks_keys, "${pfx}__FOREACH_LAST" if $need_last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1633 | 24 | ▶ | push @ks_keys, "${pfx}__FOREACH_INDEX" if $need_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1634 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1635 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1636 | $plan = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1637 | 64 | ▶ | blocks => $blocks, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
defined $oval and not $skip_val_write
MC/DC100%2/2
defined $oval and not $skip_val_write
defined $oval
not $skip_val_write
Truth table100%3/3
A and not(B)
A= defined $ovalB= not $skip_val_write
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1638 | okey => $okey, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1639 | oval => $oval, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1640 | need_eval => $need_eval, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1641 | write_key => (!$skip_key_write) ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1642 | write_val => (defined $oval && !$skip_val_write) ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1643 | need_first => $need_first, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1644 | need_last => $need_last, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1645 | need_index => $need_index, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1646 | okey_ks => "${pfx}_$okey", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1647 | oval_ks => defined $oval ? "${pfx}_$oval" : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1648 | first_ks => "${pfx}__FOREACH_FIRST", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1649 | last_ks => "${pfx}__FOREACH_LAST", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1650 | index_ks => "${pfx}__FOREACH_INDEX", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1651 | tpl_keys => \@tpl_keys, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1652 | ks_keys => \@ks_keys, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1653 | gen_seq => 0, # counter used to name temporaries in generated code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1654 | nested => [], # plans for nested loops found in the body | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1655 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1656 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1657 | # Compile a specialized renderer for the loop body. Returns undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1658 | # if the generated source fails to compile, in which case the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1659 | # interpreter in _foreach_render() is used instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1660 | 64 | $plan->{sub} = $self->_compile_foreach($plan); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1661 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1662 | 64 | $self->{_foreach_plans}{$ckey}{$raw} = $plan; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1663 | 64 | return $plan; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1664 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1665 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1666 | # Quote a string so it can be embedded in generated Perl source. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1667 | 106 | ▶ | sub _perl_quote { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_perl_quote: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1668 | 106 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1669 | 106 | ▶ | $s = '' if !defined $s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1670 | 106 | $s =~ s/\\/\\\\/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1671 | 106 | $s =~ s/'/\\'/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1672 | 106 | return "'" . $s . "'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1673 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1674 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1675 | # Compile the {foreach} body into a dedicated Perl sub. The generated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1676 | # code inlines literal text and plain variable references, and delegates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1677 | # everything else (if/foreach/modifier/expression/include blocks) back to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1678 | # the regular block handlers. The result is a tight loop with no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1679 | # per-iteration type dispatch, no repeated hash lookups and no string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1680 | # comparisons on the block type. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1681 | 42 | ▶ | sub _compile_foreach { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compile_foreach: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1682 | 42 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1683 | 42 | my $plan = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1684 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1685 | 42 | my $blocks = $plan->{blocks}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1686 | 42 | my $okey = $plan->{okey}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1687 | 42 | my $oval = $plan->{oval}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1688 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1689 | 42 | my $body = $self->_gen_body($plan, $blocks, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1690 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1691 | 42 | my $book = $self->_compile_foreach_bookkeeping($plan); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1692 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1693 | 42 | my $code = "sub {\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1694 | 42 | $code .= "no warnings 'numeric';\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1695 | 42 | $code .= "my (\$self, \$tv, \$ks, \$src, \$pl) = \@_;\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1696 | 42 | $code .= "my \$ret = '';\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1697 | 42 | $code .= "my \$ae = \$self->{auto_escape};\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1698 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1699 | # Hash source: iterate the sorted key list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1700 | 42 | $code .= "if (ref(\$src) eq 'HASH') {\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1701 | 42 | $code .= "my \@kk = sort keys %\$src;\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1702 | 42 | $code .= "my \$last = \$#kk;\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1703 | 42 | $code .= "for my \$i (0 .. \$last) {\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1704 | 42 | ▶ | $code .= "my \$v_key = " . (defined $oval ? "\$kk[\$i]" : "\$src->{\$kk[\$i]}") . ";\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1705 | 42 | ▶ | $code .= "my \$v_val = " . (defined $oval ? "\$src->{\$kk[\$i]}" : "undef") . ";\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1706 | 42 | $code .= $book; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1707 | 42 | $code .= $body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1708 | 42 | $code .= "}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1709 | 42 | $code .= "} else {\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1710 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1711 | # Array source | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1712 | 42 | $code .= "my \$last = \$#\$src;\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1713 | 42 | $code .= "for my \$i (0 .. \$last) {\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1714 | 42 | ▶ | $code .= "my \$v_key = " . (defined $oval ? "\$i" : "\$src->[\$i]") . ";\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1715 | 42 | ▶ | $code .= "my \$v_val = " . (defined $oval ? "\$src->[\$i]" : "undef") . ";\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1716 | 42 | $code .= $book; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1717 | 42 | $code .= $body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1718 | 42 | $code .= "}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1719 | 42 | $code .= "}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1720 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1721 | 42 | $code .= "return \$ret;\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1722 | 42 | $code .= "}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1723 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1724 | 42 | my $sub; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1725 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1726 | # local $@ keeps a compilation failure from leaking into the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1727 | # caller's error handling. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1728 | 42 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1729 | 7 | ▶ | $sub = eval $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1730 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1731 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1732 | 42 | return $sub; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1733 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1734 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1735 | # Generate the Perl source for a list of template blocks. Literal text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1736 | # and plain variable references are inlined; everything else is delegated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1737 | # to the regular block handlers. {if} blocks whose conditions can be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1738 | # evaluated without eval() are inlined as well, which removes a method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1739 | # call, a rule lookup and a block dispatch from every iteration. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1740 | 50 | ▶ | sub _gen_body { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gen_body: called CC=17 SCAR=30.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1741 | 50 | my ($self, $plan, $blocks, $depth) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1742 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1743 | 50 | my $okey = $plan->{okey}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1744 | 50 | my $oval = $plan->{oval}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1745 | 50 | my $code = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1746 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1747 | 50 | foreach my $b (@$blocks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1748 | 75 | my $t = $b->[2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1749 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1750 | 75 | ▶ | if ($t == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 9 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1751 | 25 | $code .= '$ret .= ' . _perl_quote($b->[0]) . ";\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1752 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1753 | } elsif ($t == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1754 | 36 | my $name = $b->[3]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1755 | 36 | my $expr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1756 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1757 | 36 | ▶ | if ($b->[4]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1758 | # Dotted path — resolved through array_dive() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1759 | 5 | $expr = '$self->array_dive(' . _perl_quote($name) . ', $tv)'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1760 | } elsif ($name eq $okey) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1761 | 23 | $expr = '$v_key'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1762 | ▶ | } elsif (defined $oval && $name eq $oval) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $oval and $name eq $oval
MC/DC50%1/2
defined $oval and $name eq $oval
defined $oval
$name eq $oval
Truth table66%2/3
A and B
A= defined $ovalB= $name eq $oval
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1763 | 4 | $expr = '$v_val'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1764 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1765 | 4 | $expr = '$tv->{' . _perl_quote($name) . '}'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1766 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1767 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1768 | 36 | $code .= sprintf($VAL_TMPL, $expr) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1769 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1770 | } elsif ($t == 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1771 | 9 | my $inline = $self->_gen_if_inline($plan, $b, $depth); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1772 | 9 | ▶ | if (defined $inline) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1773 | 8 | $code .= $inline; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1774 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1775 | 1 | $code .= '$self->{char_pos} = ' . $b->[1] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1776 | . '; $ret .= $self->_if_block(' . _perl_quote($b->[0]) . ");\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1777 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1778 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1779 | } elsif ($t == 4) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1780 | # A nested loop gets its own plan, built once and handed to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1781 | # the renderer directly so that no lookup is needed at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1782 | # render time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1783 | 1 | my $nested = $self->_foreach_plan($b->[4], $b->[5], $b->[6]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1784 | 1 | my $nidx = scalar @{$plan->{nested}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1785 | 1 | push @{$plan->{nested}}, $nested; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1786 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1787 | 1 | ▶ | $code .= '$self->{char_pos} = ' . $b->[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1788 | . '; $ret .= $self->_foreach_block(' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1789 | . CORE::join(', ', _perl_quote($b->[3]), _perl_quote($b->[4]), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1790 | (defined $b->[5] ? _perl_quote($b->[5]) : 'undef'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1791 | _perl_quote($b->[6]), '$pl->{nested}[' . $nidx . ']') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1792 | . ");\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1793 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1794 | } elsif ($t == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1795 | 4 | $code .= '$self->{char_pos} = ' . $b->[1] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1796 | . '; $ret .= $self->_variable_block(' . _perl_quote($b->[3]) . ");\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1797 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1798 | } elsif ($t == 6) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1799 | 0 | $code .= '$ret .= ' . _perl_quote($b->[3]) . ";\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1800 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1801 | } elsif ($t == 7) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1802 | 0 | $code .= '$self->{char_pos} = ' . $b->[1] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1803 | . '; $ret .= $self->_expression_block(' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1804 | . _perl_quote($b->[0]) . ', ' . _perl_quote($b->[3]) . ");\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1805 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1806 | } elsif ($t == 5) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1807 | 0 | $code .= '$self->{char_pos} = ' . $b->[1] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1808 | . '; $ret .= $self->_include_block(' . _perl_quote($b->[0]) . ");\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1809 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1810 | } elsif ($t != -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1811 | 0 | $code .= '$ret .= $self->_process_block(' . _perl_quote($b->[0]) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1812 | . ', ' . $b->[1] . ");\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1813 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1814 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1815 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1816 | 50 | return $code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1817 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1818 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1819 | # Try to build an inline {if} block. Returns the generated source, or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1820 | # undef when the block cannot be inlined (in which case the caller falls | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1821 | # back to the regular _if_block() handler). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1822 | 9 | ▶ | sub _gen_if_inline { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gen_if_inline: called CC=16 SCAR=28.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1823 | 9 | my ($self, $plan, $b, $depth) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1824 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1825 | 9 | my $str = $b->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1826 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1827 | 9 | my $rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1828 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1829 | # A malformed block raises an error here; fall back to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1830 | # regular handler so the error is reported at the usual time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1831 | 9 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1832 | 9 | $rules = eval { $self->_build_if_rules($str) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1833 | 9 | ▶ | return undef if !$rules || !@$rules; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rules and @$rules
MC/DC0%0/2
$rules and @$rules
$rules
@$rules
Truth table33%1/3
A and B
A= $rulesB= @$rules
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1834 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1835 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1836 | 9 | ▶ | my $multi = (@$rules > 1) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1837 | 9 | my $flag = '$m' . $plan->{gen_seq}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1838 | 9 | my @r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1839 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1840 | 9 | foreach my $rule (@$rules) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1841 | 9 | my $shape = $rule->[2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1842 | 9 | my $kind = $shape->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1843 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1844 | 9 | my $cond; # the condition to test | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1845 | my $guard; # undef when the fast path is always available | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1846 | 9 | my $pre; # statements evaluated before the condition | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1847 | 9 | my $tmp = '$cv' . $plan->{gen_seq}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1848 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1849 | 9 | ▶ | if ($kind == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1850 | # [2, $key, $opc, $right, $numeric] — compare against tpl_vars | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1851 | 2 | my ($key, $opc, $right, $numeric) = @{$shape}[1, 2, 3, 4]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1852 | 2 | $cond = $self->_gen_cmp('$tv->{' . _perl_quote($key) . '}', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1853 | $opc, $right, $numeric); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1854 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1855 | } elsif ($kind == 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1856 | # Constant condition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1857 | 0 | $cond = _perl_quote($shape->[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1858 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1859 | } elsif ($kind == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1860 | # [1, $neg, $key, $converted] — a plain variable reference. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1861 | # The key must exist, otherwise the regular handler is used | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1862 | # so that the eval() fallback keeps working. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1863 | 4 | my ($neg, $key) = @{$shape}[1, 2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1864 | 4 | $pre = "my $tmp = \$tv->{" . _perl_quote($key) . "};\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1865 | 4 | $guard = 'exists $tv->{' . _perl_quote($key) . '}'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1866 | 4 | ▶ | $cond = $neg ? "!$tmp" : $tmp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1867 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1868 | } elsif ($kind == 4) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1869 | # [4, $root, $sub, $opc, $right, $numeric, $converted] — a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1870 | # comparison against a dotted path held in the __S hash. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1871 | 2 | my ($root, $sub, $opc, $right, $numeric) = @{$shape}[1, 2, 3, 4, 5]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1872 | 2 | $pre = "my $tmp = \$ks->{" . _perl_quote($self->{_prefix} . $root) . "};\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1873 | 2 | $guard = "ref $tmp eq 'HASH'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1874 | 2 | $cond = $self->_gen_cmp($tmp . '->{' . _perl_quote($sub) . '}', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1875 | $opc, $right, $numeric); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1876 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1877 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1878 | # Needs eval() — cannot be inlined. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1879 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1880 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1881 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1882 | # The payload of the rule | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1883 | 8 | my $payload = $rule->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1884 | 8 | my $pblocks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1885 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1886 | 8 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1887 | 8 | $pblocks = eval { $self->_get_blocks_ref($payload) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1888 | 8 | ▶ | return undef if !$pblocks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1889 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1890 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1891 | 8 | my $pcode = $self->_gen_body($plan, $pblocks, $depth + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1892 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1893 | 8 | push @r, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1894 | cond => $cond, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1895 | guard => $guard, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1896 | pre => $pre, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1897 | code => $pcode, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1898 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1899 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1900 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1901 | # The regular handler takes over whenever the fast path for a rule | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1902 | # is not available. It re-evaluates the whole block, so it is only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1903 | # reached in situations that cannot be evaluated inline. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1904 | 8 | my $fb = '$self->{char_pos} = ' . $b->[1] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1905 | . '; $ret .= $self->_if_block(' . _perl_quote($str) . ');'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1906 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1907 | 8 | my $code = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1908 | 8 | ▶ | $code .= "my $flag = 0;\n" if $multi; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1909 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1910 | 8 | foreach my $r (@r) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1911 | 8 | ▶ | my $set = $multi ? "$flag = 1; " : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1912 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1913 | 8 | ▶ | if (defined $r->{guard}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1914 | 6 | $code .= $r->{pre}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1915 | 6 | $code .= 'if (' . $r->{guard} . ") {\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1916 | 6 | $code .= "if ($r->{cond}) { $set" . $r->{code} . "}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1917 | 6 | $code .= "} else {\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1918 | 6 | $code .= $set . $fb . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1919 | 6 | $code .= "}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1920 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1921 | 2 | ▶ | my $guard = $multi ? "!" . $flag . " && " : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1922 | 2 | $code .= "if ($guard$r->{cond}) { $set" . $r->{code} . "}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1923 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1924 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1925 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1926 | 8 | return $code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1927 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1928 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1929 | # Build the Perl source for a comparison. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1930 | 4 | ▶ | sub _gen_cmp { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gen_cmp: called CC=8 SCAR=30.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1931 | 4 | my ($self, $left, $opc, $right, $numeric) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1932 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1933 | 4 | ▶ | if ($numeric) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1934 | 2 | ▶ | if ($opc == 2) { return $left . ' == ' . $right } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1935 | 0 | elsif ($opc == 3) { return $left . ' != ' . $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1936 | 0 | elsif ($opc == 4) { return $left . ' > ' . $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1937 | 0 | elsif ($opc == 5) { return $left . ' < ' . $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1938 | 0 | elsif ($opc == 6) { return $left . ' >= ' . $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1939 | 0 | else { return $left . ' <= ' . $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1940 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1941 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1942 | 2 | my $r = _perl_quote($right); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1943 | 2 | ▶ | if ($opc == 0) { return $left . ' eq ' . $r } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1944 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1945 | 0 | return $left . ' ne ' . $r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1946 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1947 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1948 | # Generate the per-iteration bookkeeping code for a compiled foreach: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1949 | # the __FOREACH_* flags and the publication of the loop variables to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1950 | # tpl_vars and __S. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1951 | 42 | ▶ | sub _compile_foreach_bookkeeping { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compile_foreach_bookkeeping: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1952 | 42 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1953 | 42 | my $plan = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1954 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1955 | 42 | my $code = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1956 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1957 | 42 | ▶ | if ($plan->{need_first}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1958 | 3 | $code .= "my \$fv = (\$i == 0) ? 1 : 0;\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1959 | 3 | $code .= "\$tv->{'__FOREACH_FIRST'} = \$fv;\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1960 | $code .= "\$ks->{" . _perl_quote($plan->{first_ks}) . "} = \$fv;\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1961 | 3 | ▶ | if $plan->{need_eval}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1962 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1963 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1964 | 42 | ▶ | if ($plan->{need_last}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1965 | 2 | $code .= "my \$lv = (\$i == \$last) ? 1 : 0;\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1966 | 2 | $code .= "\$tv->{'__FOREACH_LAST'} = \$lv;\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1967 | $code .= "\$ks->{" . _perl_quote($plan->{last_ks}) . "} = \$lv;\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1968 | 2 | ▶ | if $plan->{need_eval}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1969 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1970 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1971 | 42 | ▶ | if ($plan->{need_index}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1972 | 1 | $code .= "\$tv->{'__FOREACH_INDEX'} = \$i;\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1973 | $code .= "\$ks->{" . _perl_quote($plan->{index_ks}) . "} = \$i;\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1974 | 1 | ▶ | if $plan->{need_eval}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1975 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1976 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1977 | 42 | ▶ | if ($plan->{write_key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1978 | 16 | $code .= "\$tv->{" . _perl_quote($plan->{okey}) . "} = \$v_key;\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1979 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1980 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1981 | 42 | ▶ | if ($plan->{write_val}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1982 | 5 | $code .= "\$tv->{" . _perl_quote($plan->{oval}) . "} = \$v_val;\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1983 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1984 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1985 | 42 | ▶ | if ($plan->{need_eval}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1986 | 14 | $code .= "\$ks->{" . _perl_quote($plan->{okey_ks}) . "} = \$v_key;\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1987 | $code .= "\$ks->{" . _perl_quote($plan->{oval_ks}) . "} = \$v_val;\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1988 | 14 | ▶ | if defined $plan->{oval_ks}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1989 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1990 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1991 | 42 | return $code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1992 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1993 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1994 | # Interpreter fallback used when the compiled renderer could not be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1995 | # built. Semantically identical to the compiled path. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1996 | 57 | ▶ | sub _foreach_render { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_foreach_render: called CC=41 SCAR=40.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1997 | 57 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1998 | 57 | my $plan = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1999 | 57 | my $src = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2000 | 57 | my $tv = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2001 | 57 | my $ks = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2002 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2003 | 57 | my $blocks = $plan->{blocks}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2004 | 57 | my $okey = $plan->{okey}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2005 | 57 | my $oval = $plan->{oval}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2006 | 57 | my $auto_escape = $self->{auto_escape}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2007 | 57 | my $ret = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2008 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2009 | 57 | my @items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2010 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2011 | 57 | ▶ | if (ref $src eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2012 | 2 | my @keys = sort keys %$src; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2013 | 2 | for my $i (0 .. $#keys) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2014 | 6 | my $k = $keys[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2015 | push @items, [ (defined $oval ? $k : $src->{$k}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2016 | 6 | ▶ | (defined $oval ? $src->{$k} : undef) ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2017 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2018 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2019 | 55 | for my $i (0 .. $#$src) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2020 | 134 | ▶ | push @items, [ (defined $oval ? $i : $src->[$i]), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2021 | (defined $oval ? $src->[$i] : undef) ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2022 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2023 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2024 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2025 | 57 | my $last = $#items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2026 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2027 | 57 | for my $i (0 .. $last) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2028 | 140 | my ($v_key, $v_val) = @{$items[$i]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2029 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2030 | 140 | ▶ | if ($plan->{need_first}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2031 | 6 | ▶ | my $v = ($i == 0) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2032 | 6 | $tv->{__FOREACH_FIRST} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2033 | 6 | ▶ | $ks->{$plan->{first_ks}} = $v if $plan->{need_eval}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2034 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2035 | 140 | ▶ | if ($plan->{need_last}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2036 | 6 | ▶ | my $v = ($i == $last) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2037 | 6 | $tv->{__FOREACH_LAST} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2038 | 6 | ▶ | $ks->{$plan->{last_ks}} = $v if $plan->{need_eval}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2039 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2040 | 140 | ▶ | if ($plan->{need_index}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2041 | 6 | $tv->{__FOREACH_INDEX} = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2042 | 6 | ▶ | $ks->{$plan->{index_ks}} = $i if $plan->{need_eval}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2043 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2044 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2045 | 140 | ▶ | $tv->{$okey} = $v_key if $plan->{write_key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2046 | 140 | ▶ | $tv->{$oval} = $v_val if $plan->{write_val}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2047 | 140 | ▶ | $ks->{$plan->{okey_ks}} = $v_key if $plan->{need_eval}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2048 | 140 | ▶ | $ks->{$plan->{oval_ks}} = $v_val if $plan->{need_eval} && defined $plan->{oval_ks}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$plan->{"need_eval"} and defined $plan->{"oval_ks"}
MC/DC0%0/2
$plan->{"need_eval"} and defined $plan->{"oval_ks"}
$plan->{"need_eval"}
defined $plan->{"oval_ks"}
Truth table66%2/3
A and B
A= $plan->{"need_eval"}B= defined $plan->{"oval_ks"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2049 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2050 | 140 | foreach my $b (@$blocks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2051 | 254 | my $type = $b->[2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2052 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2053 | 254 | ▶ | if ($type == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 9 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2054 | 58 | $ret .= $b->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2055 | } elsif ($type == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2056 | 132 | my $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2057 | 132 | ▶ | if ($b->[4]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2058 | 8 | $val = $self->array_dive($b->[3], $tv); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2059 | } elsif ($b->[3] eq $okey) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2060 | 88 | $val = $v_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2061 | ▶ | } elsif (defined $oval && $b->[3] eq $oval) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $oval and $b->[3] eq $oval
MC/DC50%1/2
defined $oval and $b->[3] eq $oval
defined $oval
$b->[3] eq $oval
Truth table66%2/3
A and B
A= defined $ovalB= $b->[3] eq $oval
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2062 | 12 | $val = $v_val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2063 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2064 | 24 | $val = $tv->{$b->[3]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2065 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2066 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2067 | 132 | my $r = ref $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2068 | 132 | ▶ | if ($r eq '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2069 | 132 | ▶ | $ret .= ($auto_escape ? escape($val) : $val) if defined $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2070 | } elsif ($r eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2071 | 0 | $ret .= 'ARRAY'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2072 | } elsif ($r eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2073 | 0 | $ret .= 'HASH'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2074 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2075 | 0 | $ret .= $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2076 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2077 | } elsif ($type == 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2078 | 32 | $self->{char_pos} = $b->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2079 | 32 | $ret .= $self->_if_block($b->[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2080 | } elsif ($type == 4) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2081 | 12 | $self->{char_pos} = $b->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2082 | 12 | $ret .= $self->_foreach_block($b->[3], $b->[4], $b->[5], $b->[6]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2083 | } elsif ($type == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2084 | 14 | $self->{char_pos} = $b->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2085 | 14 | $ret .= $self->_variable_block($b->[3]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2086 | } elsif ($type == 6) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2087 | 6 | $ret .= $b->[3]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2088 | } elsif ($type == 7) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2089 | 0 | $self->{char_pos} = $b->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2090 | 0 | $ret .= $self->_expression_block($b->[0], $b->[3]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2091 | } elsif ($type == 5) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2092 | 0 | $self->{char_pos} = $b->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2093 | 0 | $ret .= $self->_include_block($b->[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2094 | } elsif ($type != -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2095 | 0 | $ret .= $self->_process_block($b->[0], $b->[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2096 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2097 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2098 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2099 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2100 | 57 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2102 | 12 | ▶ | sub _include_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_include_block: called CC=8 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2103 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2104 | 12 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2106 | 12 | my $save = { %{$self->{tpl_vars}} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2107 | 12 | my $save_S = { %{$self->{__S}} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2108 | 12 | my $inc_tpl = $self->_extract_include_file($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2110 | 11 | ▶ | if ($self->{perl_file_dir}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2111 | 11 | $inc_tpl = $self->{perl_file_dir} . "/$inc_tpl"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2114 | 11 | ▶ | while ($str =~ m/(\w+)=(['"](.+?)['"])/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2115 | 12 | my $key = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2116 | 12 | my $val = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2118 | 12 | ▶ | if ($key eq 'file') { next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2120 | 2 | $val = $self->_convert_vars($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2121 | 2 | my ($res) = $self->_peval($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2123 | 2 | ▶ | if (defined $res) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2124 | 2 | $self->assign($key => $res); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2125 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2126 | 0 | $self->assign($key => $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2130 | 11 | ▶ | if (!-f $inc_tpl || !-r $inc_tpl) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-f $inc_tpl and -r $inc_tpl
MC/DC50%1/2
-f $inc_tpl and -r $inc_tpl
-f $inc_tpl
-r $inc_tpl
Truth table66%2/3
A and B
A= -f $inc_tplB= -r $inc_tpl
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2131 | 1 | $self->{inc_tpl_file} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2132 | 1 | my ($line, $col, $file) = $self->_get_char_location($self->{char_pos}, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2133 | 1 | $self->_error_out("Unable to load include template `$inc_tpl` in `$file` on line #$line", 18485); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2136 | # Slurp up the TPL content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2137 | 10 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2138 | 10 | ▶ | open my $fh, '<', $inc_tpl or $self->_error_out("Cannot open `$inc_tpl`: $!", 63579); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2139 | 10 | my $content = <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2140 | 10 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2142 | 10 | my @blocks = $self->_get_blocks($content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2143 | 10 | my $r = $self->_process_blocks(\@blocks); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2145 | 10 | $self->{tpl_vars} = $save; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2146 | 10 | $self->{__S} = $save_S; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2147 | 10 | $self->{inc_tpl_file} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2149 | 10 | return $r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2152 | 36 | ▶ | sub _expression_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_expression_block: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2153 | 36 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2154 | 36 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2155 | 36 | my $inner = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2157 | 36 | ▶ | if ($str !~ /["\d\$\(]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2158 | 5 | my ($line, $col, $file) = $self->_get_char_location($self->{char_pos}, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2159 | 5 | $self->_error_out("Unknown block type `$str` in `$file` on line #$line", 73467); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2162 | 31 | my $after = $self->_convert_vars($inner); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2163 | 31 | my ($ret, $err) = $self->_peval($after); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2165 | 31 | my $valid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2166 | 31 | ▶ | if (defined $ret && (!ref $ret || ref $ret eq '')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $ret and !ref($ret) || ref $ret eq ""
not ref $ret or ref $ret eq ""
MC/DC33%1/3
defined $ret and !ref($ret) || ref $ret eq ""
defined $ret
not ref $ret
ref $ret eq ""
Truth table50%2/4
A and not(B) or C
A= defined $retB= not ref $retC= ref $ret eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2167 | 27 | $valid = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2168 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2169 | 4 | $valid = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2172 | 31 | ▶ | if ($err || !$valid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$err or not $valid
MC/DC100%2/2
$err or not $valid
$err
not $valid
Truth table100%3/3
A or not(B)
A= $errB= not $valid
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2173 | 4 | my ($line, $col, $file) = $self->_get_char_location($self->{char_pos}, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2174 | 4 | $self->_error_out("Unknown tag `$str` in `$file` on line #$line", 18933); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2177 | 27 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2180 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2181 | # Variable / eval engine | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2182 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2184 | 181 | ▶ | sub _convert_vars { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_convert_vars: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2185 | 181 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2186 | 181 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2187 | 181 | ▶ | if (index($str, '$') < 0) { return $str } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2189 | # Check conversion cache — avoids re-running regex substitutions on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2190 | # the same expression (e.g. an {if} condition inside a {foreach} loop) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2191 | 163 | ▶ | if (exists $self->{_convert_cache}{$str}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2192 | 45 | return $self->{_convert_cache}{$str}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2195 | 118 | my $orig = $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2197 | # Step 1: $var.key -> $__S->{sluz_pfx_var}->{key} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2198 | 118 | $str =~ s/(\$\w[\w\.]*)/ $self->_dot_to_bracket_cb($1) /ge; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2200 | # Step 2: $__S->{...}["key"] -> $__S->{...}->{key} (PHP bracket syntax) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2201 | 118 | ▶ | if (index($str, '[') >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2202 | 4 | $str =~ s/(\$__S(?:->\{[^}]+\})+)\[(["'])([^\]]+?)\2\]/$1 . '->{' . $3 . '}'/ge; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2205 | 118 | $self->{_convert_cache}{$orig} = $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2206 | 118 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2209 | 127 | ▶ | sub _dot_to_bracket_cb { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dot_to_bracket_cb: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2210 | 127 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2211 | 127 | my $match = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2212 | 127 | my @parts = split /\./, $match; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2213 | 127 | my $first = shift @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2214 | 127 | my $var = substr($first, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2215 | 127 | my $res = "\$__S->\{$self->{var_prefix}_$var\}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2217 | 127 | foreach my $p (@parts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2218 | 14 | ▶ | if ($p =~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2219 | 2 | $res .= "->[$p]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2220 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2221 | 12 | $res .= "->{$p}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2224 | 127 | return $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2227 | 305 | ▶ | sub _micro_optimize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_micro_optimize: called CC=27 SCAR=33.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2228 | 305 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2229 | 305 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2231 | # Check shape cache — avoids re-running all the classification regexes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2232 | # on repeat calls with the same expression string (e.g. a foreach/if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2233 | # condition re-evaluated on every loop iteration). Only the *shape* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2234 | # (literal vs. variable-reference, and which var) is cached; the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2235 | # actual value is still looked up live from tpl_vars each call. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2236 | 305 | my $cached = $self->{_micro_cache}{$str}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2237 | 305 | ▶ | if ($cached) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2238 | 136 | my $type = $cached->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2239 | 136 | ▶ | if ($type eq 'lit') { return $cached->[1] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2240 | 89 | ▶ | if ($type eq 'var') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2241 | 57 | my (undef, $neg, $key) = @$cached; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2242 | 57 | ▶ | if (exists $self->{tpl_vars}{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2243 | 29 | ▶ | return $neg ? !$self->{tpl_vars}{$key} : $self->{tpl_vars}{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2245 | 28 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2247 | 32 | ▶ | if ($type eq 'cmp') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2248 | 0 | return $self->_micro_compare($cached, $self->{tpl_vars}{$cached->[1]}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2250 | 32 | return undef; # type eq 'none' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2253 | 169 | ▶ | if ($str =~ /^-?\d+(?:\.\d+)?$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2254 | 10 | $self->{_micro_cache}{$str} = ['lit', $str]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2255 | 10 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2258 | 159 | ▶ | if (!length $str) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2259 | 1 | $self->{_micro_cache}{$str} = ['none']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2260 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2263 | # Fast path for the common loop condition {$item eq "value"}. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2264 | # expression shape is stable across iterations; only the variable value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2265 | # changes, so avoid invoking Perl eval for every item. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2266 | 158 | ▶ | if ($str =~ /^\$__S->\{sluz_pfx_(\w+)\}\s*(==|!=|eq|ne|>=|<=|>|<)\s*(?:"([^"]*)"|'([^']*)'|(-?\d+(?:\.\d+)?))$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2267 | 12 | my ($key, $op, $dquote, $squote, $number) = ($1, $2, $3, $4, $5); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2268 | 12 | ▶ | my $literal = defined $number ? $number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2269 | : (defined $dquote ? $dquote : $squote); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2270 | 12 | ▶ | my $numeric = ($op ne 'eq' && $op ne 'ne'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$op ne 'eq' && $op ne 'ne'
MC/DC50%1/2
$op ne 'eq' && $op ne 'ne'
$op ne 'eq'
$op ne 'ne'
Truth table66%2/3
A && B
A= $op ne 'eq'B= $op ne 'ne'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2271 | 12 | my $entry = ['cmp', $key, $op, $literal, $numeric]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2272 | 12 | $self->{_micro_cache}{$str} = $entry; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2273 | 12 | return $self->_micro_compare($entry, $self->{tpl_vars}{$key}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2275 | 146 | my $first = ord($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2276 | 146 | my $last = ord(substr($str, -1)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2278 | 146 | ▶ | if ($first == 39 && $last == 39) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$first == 39 and $last == 39
MC/DC50%1/2
$first == 39 and $last == 39
$first == 39
$last == 39
Truth table66%2/3
A and B
A= $first == 39B= $last == 39
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2279 | 8 | my $tmp = substr($str, 1, length($str) - 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2280 | 8 | ▶ | if (index($tmp, "'") < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2281 | 8 | $self->{_micro_cache}{$str} = ['lit', $tmp]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2282 | 8 | return $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2286 | 138 | ▶ | if ($first == 34 && $last == 34) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$first == 34 and $last == 34
MC/DC50%1/2
$first == 34 and $last == 34
$first == 34
$last == 34
Truth table66%2/3
A and B
A= $first == 34B= $last == 34
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2287 | 30 | my $tmp = substr($str, 1, length($str) - 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2288 | 30 | ▶ | if (index($tmp, '$') < 0 && index($tmp, '"') < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
index($tmp, "\$") == -1 and index($tmp, "\"") == -1
MC/DC50%1/2
index($tmp, "\$") == -1 and index($tmp, "\"") == -1
index($tmp, "\$") == -1
index($tmp, "\"") == -1
Truth table66%2/3
A and B
A= index($tmp, "\$") == -1B= index($tmp, "\"") == -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2289 | 28 | $self->{_micro_cache}{$str} = ['lit', $tmp]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2290 | 28 | return $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2294 | 110 | ▶ | if ($str =~ /^(!?)\$__S->\{sluz_pfx_(\w+)\}$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2295 | 62 | my ($neg, $key) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2296 | 62 | $self->{_micro_cache}{$str} = ['var', $neg, $key]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2297 | 62 | ▶ | if (exists $self->{tpl_vars}{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2298 | 51 | ▶ | return $neg ? !$self->{tpl_vars}{$key} : $self->{tpl_vars}{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2300 | 11 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2303 | 48 | ▶ | if ($str =~ /^(!?)(\w+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2304 | 2 | my ($neg, $key) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2305 | 2 | $self->{_micro_cache}{$str} = ['var', $neg, $key]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2306 | 2 | ▶ | if (exists $self->{tpl_vars}{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2307 | 2 | ▶ | return $neg ? !$self->{tpl_vars}{$key} : $self->{tpl_vars}{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2309 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2312 | 46 | $self->{_micro_cache}{$str} = ['none']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2313 | 46 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2316 | 12 | ▶ | sub _micro_compare { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_micro_compare: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2317 | 12 | my ($self, $entry, $left) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2318 | 12 | my ($op, $right, $numeric) = @$entry[2, 3, 4]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2320 | 14 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2321 | 12 | ▶ | if ($numeric) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2322 | 10 | ▶ | if ($op eq '==') { return $left == $right } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2323 | 7 | ▶ | if ($op eq '!=') { return $left != $right } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2324 | 5 | ▶ | if ($op eq '>=') { return $left >= $right } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2325 | 4 | ▶ | if ($op eq '<=') { return $left <= $right } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2326 | 3 | ▶ | if ($op eq '>') { return $left > $right } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2328 | 1 | return $left < $right; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2331 | 2 | ▶ | if ($op eq 'eq') { return $left eq $right } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2333 | 0 | return $left ne $right; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2336 | # Modifier params must be quoted, numeric, or variable references. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2337 | # A bare word such as |join_comma:abc is rejected (#31558) instead of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2338 | # silently becoming undef. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2339 | 18 | ▶ | sub _check_mod_params { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_mod_params: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2340 | 18 | my ($self, $func, $param_str) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2342 | 18 | foreach my $p (split $self->{_comma_re}, $param_str) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2343 | 20 | $p =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2344 | 20 | ▶ | next if !length $p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2345 | 20 | ▶ | next if $p =~ /^"[^"]*"$/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2346 | 11 | ▶ | next if $p =~ /^'[^']*'$/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2347 | 11 | ▶ | next if $p =~ /^-?\d+(?:\.\d+)?$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2348 | 2 | ▶ | next if index($p, '$') >= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2350 | 2 | my ($line, $col, $file) = $self->_get_char_location($self->{char_pos}, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2351 | 2 | $self->_error_out("Unquoted function parameter `$p` in `$func` in `$file` on line #$line", 31558); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2353 | 16 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2356 | # Classify a raw expression into a cached shape tuple so hot paths can | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2357 | # resolve it without calling _peval. Classification is pure (regex + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2358 | # tpl_vars lookups only), so it is safe to run at cache-build time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2359 | # Returns: [3, literal] | [1, $neg, $key, converted] | [2, $key, $opc, $right, $numeric] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2360 | # [4, $root, $sub, $opc, $right, $numeric, converted] | [0, converted] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2361 | # The var shape keeps the converted string because a missing key must | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2362 | # fall back to _peval (e.g. !$missing_var is true via eval, not undef). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2363 | 224 | ▶ | sub _shape_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_shape_of: called CC=11 SCAR=24.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2364 | 224 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2365 | 224 | ▶ | my $raw = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2367 | 224 | ▶ | my $conv = (index($raw, '$') < 0) ? $raw : $self->_convert_vars($raw); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2369 | # A comparison against a dotted path ($x.key eq "value") is common | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2370 | # inside loops. Recognise it here so the condition can be evaluated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2371 | # with a plain hash lookup instead of a compiled eval sub. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2372 | 224 | ▶ | if ($conv =~ $self->{_re_cmp_dotted}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2373 | 7 | my ($root, $sub, $op, $dquote, $squote, $number) = ($1, $2, $3, $4, $5, $6); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2374 | 7 | ▶ | my $literal = defined $number ? $number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2375 | : (defined $dquote ? $dquote : $squote); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2376 | 7 | ▶ | my $numeric = ($op ne 'eq' && $op ne 'ne'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$op ne 'eq' && $op ne 'ne'
MC/DC50%1/2
$op ne 'eq' && $op ne 'ne'
$op ne 'eq'
$op ne 'ne'
Truth table66%2/3
A && B
A= $op ne 'eq'B= $op ne 'ne'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2378 | 7 | return [4, $root, $sub, $OP_CODE{$op}, $literal, $numeric, $conv]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2379 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2381 | 217 | $self->_micro_optimize($conv); # populate _micro_cache with the shape | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2382 | 217 | my $e = $self->{_micro_cache}{$conv}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2383 | 217 | ▶ | if ($e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2384 | 217 | my $t = $e->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2386 | 217 | ▶ | if ($t eq 'lit') { return [3, $e->[1]] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2387 | 136 | ▶ | if ($t eq 'var') { return [1, $e->[1], $e->[2], $conv] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2388 | 35 | ▶ | if ($t eq 'cmp') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2389 | 12 | my ($key, $op, $literal, $numeric) = @{$e}[1, 2, 3, 4]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2390 | 12 | return [2, $key, $OP_CODE{$op}, $literal, $numeric]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2394 | 23 | return [0, $conv]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2395 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2397 | # Evaluate a shape tuple against the live tpl_vars. Mirrors the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2398 | # _micro_optimize/_peval semantics exactly. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2399 | 27 | ▶ | sub _eval_shape { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_eval_shape: called CC=10 SCAR=36.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2400 | 27 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2401 | 27 | my $shape = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2402 | 27 | my $tv = $self->{tpl_vars}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2404 | 27 | my $kind = $shape->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2405 | 27 | ▶ | if ($kind == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2406 | 0 | my ($neg, $key) = @{$shape}[1, 2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2407 | 0 | my $v = $tv->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2408 | 0 | ▶ | if (defined $v) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2409 | 0 | ▶ | return $neg ? !$v : $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2411 | 0 | ▶ | if (exists $tv->{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2412 | 0 | ▶ | return $neg ? 1 : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2413 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2414 | 0 | my ($ret) = $self->_peval($shape->[3]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2415 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2418 | 27 | ▶ | if ($kind == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2419 | 0 | my ($key, $opc, $right, $numeric) = @{$shape}[1, 2, 3, 4]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2420 | 0 | return $self->_cmp_apply($opc, $tv->{$key}, $right, $numeric); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2421 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2423 | 27 | ▶ | if ($kind == 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2424 | 23 | return $shape->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2427 | 4 | ▶ | if ($kind == 4) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2428 | 0 | my ($root, $sub, $opc, $right, $numeric) = @{$shape}[1, 2, 3, 4, 5]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2429 | 0 | my $h = $self->{__S}{$self->{_prefix} . $root}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2430 | 0 | ▶ | if (ref $h eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2431 | 0 | return $self->_cmp_apply($opc, $h->{$sub}, $right, $numeric); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2433 | 0 | my ($ret) = $self->_peval($shape->[6]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2434 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2437 | 4 | my ($ret) = $self->_peval($shape->[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2439 | 4 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2440 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2442 | # Apply a comparison operator. The operator is passed as a small | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2443 | # integer code so the hot paths avoid repeated string comparisons. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2444 | 0 | ▶ | sub _cmp_apply { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cmp_apply: not called CC=8 SCAR=39.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2445 | 0 | my ($self, $opc, $left, $right, $numeric) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2447 | 14 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2449 | 0 | ▶ | if ($numeric) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2450 | 0 | ▶ | if ($opc == 2) { return $left == $right } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2451 | 0 | elsif ($opc == 3) { return $left != $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2452 | 0 | elsif ($opc == 4) { return $left > $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2453 | 0 | elsif ($opc == 5) { return $left < $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2454 | 0 | elsif ($opc == 6) { return $left >= $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2455 | 0 | else { return $left <= $right } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2456 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2458 | 0 | ▶ | if ($opc == 0) { return $left eq $right } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2460 | 0 | return $left ne $right; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2462 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2463 | 88 | ▶ | sub _peval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_peval: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2464 | 88 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2465 | 88 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2466 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2467 | 88 | ▶ | if (index($str, '===') >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2468 | 0 | $str =~ s/===/==/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2469 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2471 | 88 | my $opt = $self->_micro_optimize($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2472 | 88 | ▶ | if (defined $opt) { return ($opt, 0) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2474 | # Use the persistent $__S hash (maintained by assign/foreach) instead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2475 | # of rebuilding it from tpl_vars on every call | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2476 | 74 | my $__S = $self->{__S}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2478 | # Check verified sub cache — subs that have succeeded at least once. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2479 | # Skip eval/local $SIG overhead (the biggest per-call cost in loops). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2480 | # no warnings in the compiled sub suppresses uninitialized-value warnings. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2481 | 74 | my $vsub = $self->{_verified_sub_cache}{$str}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2482 | 74 | ▶ | if ($vsub) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2483 | 18 | return ($vsub->($__S), 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2485 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2486 | # Check compiled sub cache — avoids re-parsing the same expression | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2487 | 56 | my $sub = $self->{_sub_cache}{$str}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2488 | 56 | ▶ | if (!defined $sub) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2489 | # Compile in main:: first (where user functions live), then Template::Sluz | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2490 | 9 | ▶ | $sub = eval "package main; no warnings; sub { my \$__S = \$_[0]; return ($str); }"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2491 | 56 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2492 | 2 | ▶ | $sub = eval "no warnings; sub { my \$__S = \$_[0]; return ($str); }"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2494 | # Cache the result (even undef) so we don't recompile failures | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2495 | 56 | $self->{_sub_cache}{$str} = $sub; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2496 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2498 | 56 | my $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2499 | 56 | ▶ | if ($sub) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2500 | 53 | ▶ | local $SIG{__WARN__} = sub {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2501 | 53 | $ret = eval { $sub->($__S) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2502 | 53 | ▶ | unless ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2503 | # Promote to verified cache — skip eval/SIG on future calls | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2504 | 48 | $self->{_verified_sub_cache}{$str} = $sub; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2505 | 48 | delete $self->{_sub_cache}{$str}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2506 | 48 | return ($ret, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2508 | # Cached sub failed (e.g. function not in main::) — evict and fall through | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2509 | 5 | delete $self->{_sub_cache}{$str}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2511 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2512 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2513 | 8 | ▶ | local $SIG{__WARN__} = sub {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2514 | 6 | ▶ | $ret = eval "no warnings; return ($str);"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2515 | 8 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2516 | 3 | ▶ | $ret = eval "package main; no warnings; return ($str);"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2517 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2518 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2519 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2520 | 8 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2521 | 5 | return (undef, -1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2522 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2523 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2524 | 3 | return ($ret, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2525 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2526 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2527 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2528 | # Error handling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2529 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2530 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2531 | 45 | ▶ | sub _error_out { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error_out: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2532 | 45 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2533 | 45 | my $msg = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2534 | 45 | my $err_num = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2535 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2536 | 45 | croak "Template::Sluz error #$err_num: $msg"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2537 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2539 | 36 | ▶ | sub _get_char_location { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_char_location: called CC=12 SCAR=26.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2540 | 36 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2541 | 36 | my $pos = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2542 | 36 | ▶ | my $tpl_file = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() // ""
MC/DC100%1/1
shift() // ""
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2543 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2544 | 0 | ▶ | if ($self->{inc_tpl_file}) { $tpl_file = $self->{inc_tpl_file} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2546 | # Use display file name and line offset when available (e.g. inline DATA templates) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2547 | 36 | ▶ | my $display_file = exists $self->{tpl_file_display} ? $self->{tpl_file_display} : $tpl_file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2548 | 36 | ▶ | my $line_offset = exists $self->{tpl_line_offset} ? $self->{tpl_line_offset} : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2550 | # Guard: no file context (e.g. parse_string) — skip _get_tpl_content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2551 | # to avoid trying to open the perl_file_dir directory as a template file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2552 | 36 | ▶ | if (!length $tpl_file) { return (-1, -1, $display_file) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2553 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2554 | 6 | my $str = $self->_get_tpl_content($tpl_file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2555 | 0 | ▶ | if ($pos < 0 || !defined $str) { return (-1, -1, $display_file) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$pos < 0 or not defined $str
MC/DC0%0/2
$pos < 0 or not defined $str
$pos < 0
not defined $str
Truth table33%1/3
A or not(B)
A= $pos < 0B= not defined $str
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2556 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2557 | 6 | my $line = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2558 | 6 | my $col = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2559 | 6 | ▶ | for (my $i = 0; $i < length $str; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2560 | 50 | $col++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2561 | 50 | ▶ | if (substr($str, $i, 1) eq "\n") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2562 | 3 | $line++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2563 | 3 | $col = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2564 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2565 | 50 | ▶ | if ($pos == $i) { return ($line + $line_offset, $col, $display_file) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2566 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2567 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2568 | 0 | ▶ | if ($pos == length $str) { return ($line + $line_offset, $col, $display_file) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2569 | 0 | return (-1, -1, $display_file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2570 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2571 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2572 | 12 | ▶ | sub _extract_include_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_include_file: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2573 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2574 | 12 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2575 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2576 | 12 | ▶ | if ($str =~ /\s(file=)(['"].+?['"])/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2577 | 10 | my $xstr = $self->_convert_vars($2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2578 | 10 | my ($ret) = $self->_peval($xstr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2579 | 10 | $self->{inc_tpl_file} = $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2580 | 10 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2581 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2582 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2583 | 2 | ▶ | if ($str =~ /\s(['"].+?['"])/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2584 | 1 | my $xstr = $self->_convert_vars($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2585 | 1 | my ($ret) = $self->_peval($xstr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2586 | 1 | $self->{inc_tpl_file} = $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2587 | 1 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2588 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2589 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2590 | 1 | my ($line, $col, $file) = $self->_get_char_location($self->{char_pos}, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2591 | 1 | $self->_error_out("Unable to find a file in include block `$str` in `$file` on line #$line", 68493); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2592 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2593 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2594 | 40 | ▶ | sub _if_rules_from_tokens { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_if_rules_from_tokens: called CC=16 SCAR=27.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2595 | 40 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2596 | 40 | my $toks = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2597 | 40 | my $num = scalar @$toks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2598 | 40 | my $nested = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2599 | 40 | my @tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2600 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2601 | 40 | my $tif_tag = $self->{_tag_if}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2602 | 40 | my $tifc_tag = $self->{_tag_if_close}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2603 | 40 | my $tif_prefix = $self->{open_delim} . 'if'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2604 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2605 | 40 | foreach my $i (0 .. $num - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2606 | 244 | my $item = $toks->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2607 | 244 | ▶ | if (index($item, $tif_prefix) == 0) { $nested++ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2608 | 244 | ▶ | if ($item eq $tifc_tag) { $nested-- } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2609 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2610 | 244 | my $yes = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2611 | 244 | ▶ | if ($nested == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2612 | 180 | ▶ | $yes = $self->is_if_token($item) || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->is_if_token($item) || 0
MC/DC100%1/1
$self->is_if_token($item) || 0
$self->is_if_token($item)
Truth table100%2/2
A
A= $self->is_if_token($item)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2613 | 180 | ▶ | $yes = 0 if $item eq $tifc_tag; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2614 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2615 | 244 | $tmp[$i] = $yes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2616 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2617 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2618 | 40 | $tmp[$num - 1] = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2619 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2620 | 40 | my @conds; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2621 | 40 | foreach my $i (0 .. $num - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2622 | 244 | ▶ | if ($tmp[$i]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2623 | 128 | my $test = $self->is_if_token($toks->[$i]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2624 | 128 | ▶ | if ($i != $num - 1) { push @conds, $test } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2625 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2626 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2627 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2628 | 40 | my $str = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2629 | 40 | my @payloads; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2630 | 40 | my $first = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2631 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2632 | 40 | foreach my $i (0 .. $num - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2633 | 244 | ▶ | if ($tmp[$i]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2634 | 128 | ▶ | if (!$first) { push @payloads, $str } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2635 | 128 | $first = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2636 | 128 | $str = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2637 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2638 | 116 | $str .= $toks->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2639 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2640 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2641 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2642 | 40 | ▶ | if (@conds != @payloads) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2643 | 0 | $self->_error_out("Error parsing if conditions in '$str'", 95320); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2644 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2645 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2646 | 40 | my @ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2647 | 40 | foreach my $x (0 .. $#conds) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2648 | 88 | push @ret, [$conds[$x], $payloads[$x]]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2649 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2650 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2651 | 40 | foreach my $rule (@ret) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2652 | 88 | $rule->[1] = $self->ltrim_one($rule->[1], "\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2653 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2654 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2655 | 40 | return @ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2656 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2657 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2658 | 14 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2659 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2660 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||