| 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 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 10 | ▶ | use 5.016; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 10 | ▶ | use File::Basename qw(dirname basename); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 10 | ▶ | use autouse 'Carp' => qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 10 | ▶ | use constant SLUZ_INLINE => 'INLINE_TEMPLATE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 10 | our $VERSION = 'v0.9.6'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ################################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # Built-in Sluz functions that can be used in templates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | ################################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | ▶ | sub count { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
count: called CC=4 SCAR=22.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | my $v = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 3 | ▶ | if (ref $v eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | return scalar @$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if (ref $v eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | return scalar(keys %$v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if (defined $v) { return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 4 | ▶ | sub join { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
join: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 4 | my $arr = shift(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 4 | ▶ | my $glue = shift() // ', '; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() // ", "
MC/DC100%1/1
shift() // ", "
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 4 | return CORE::join($glue, @$arr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ################################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | ################################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 11 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 11 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 11 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | my $self = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | version => $VERSION, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | tpl_file => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | inc_tpl_file => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | debug => $args{debug} // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 11 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | tpl_vars => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | parent_tpl => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | var_prefix => 'sluz_pfx', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | perl_file => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | perl_file_dir => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | fetch_called => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | char_pos => -1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | open_delim => '{', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | close_delim => '}', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | _sub_cache => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | __S => {}, # Cached prefixed var hash used by _peval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | _convert_cache => {}, # Cached _convert_vars results (avoids re-running regex on repeated expressions) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | _blocks_cache => {}, # Cached _get_blocks results (avoids re-tokenizing if payloads in loops) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | _if_rules_cache => {}, # Cached parsed {if} rules (avoids re-parsing same if block in loops) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | _verified_sub_cache => {}, # Cached subs that succeeded once — skip eval/SIG overhead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | _mod_cache => {}, # Cached resolved modifier coderefs keyed by func name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 11 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 11 | $self->_precompute_tags(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 11 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 244 | ▶ | sub assign { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
assign: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 244 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 244 | my $pfx = $self->{var_prefix}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # Accept either a hashref: assign($hash_ref) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 244 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 9 | my $h = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 9 | @{$self->{tpl_vars}}{keys %$h} = values %$h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 9 | for my $k (keys %$h) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 24 | $self->{__S}{"${pfx}_$k"} = $h->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # Or a key-value list: assign(name => 'Scott', age => 42) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } elsif (@_ % 2 == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 234 | my %h = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 234 | @{$self->{tpl_vars}}{keys %h} = values %h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 234 | for my $k (keys %h) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 258 | $self->{__S}{"${pfx}_$k"} = $h{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | $self->_error_out("Invalid assign. Must be a key/value or hash", 18956); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 3 | ▶ | sub fetch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 3 | ▶ | my $tpl_file = shift // SLUZ_INLINE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // "INLINE_TEMPLATE"
MC/DC0%0/1
shift() // "INLINE_TEMPLATE"
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 3 | my $parent = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 3 | ▶ | if (!$self->{perl_file}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | $self->{perl_file} = $self->_get_perl_file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | $self->{perl_file_dir} = dirname($self->{perl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | my $parent_tpl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 3 | ▶ | if (defined $parent) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | $parent_tpl = $parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 2 | $parent_tpl = $self->{parent_tpl}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 3 | ▶ | if ($parent_tpl) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | $self->assign('__CHILD_TPL', $tpl_file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | $tpl_file = $parent_tpl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 3 | my $str = $self->_get_tpl_content($tpl_file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 3 | my @blocks = $self->_get_blocks($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 3 | my $html = $self->_process_blocks(\@blocks); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 3 | $self->{fetch_called} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 3 | return $html; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | return $self->fetch(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | sub display { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
display: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | print $self->fetch(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # Parse a string instead of a file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 220 | ▶ | sub parse_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_string: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 220 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 220 | ▶ | my $tpl_str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 220 | my @blocks = $self->_get_blocks($tpl_str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 220 | return $self->_process_blocks(\@blocks); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # Getter/setter for parent TPL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 2 | ▶ | sub parent_tpl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parent_tpl: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 2 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 2 | $self->{parent_tpl} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 2 | return $self->{parent_tpl}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | ▶ | sub set_delimiters { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_delimiters: called CC=6 SCAR=19.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | my $open = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | my $close = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | ▶ | if (!defined $open || !defined $close) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $open and defined $close
MC/DC0%0/2
defined $open and defined $close
defined $open
defined $close
Truth table33%1/3
A and B
A= defined $openB= defined $close
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | $self->_error_out("set_delimiters requires both open and close delimiter arguments", 51234); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1 | ▶ | if (length($open) != 1 || length($close) != 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
length $open != 1 or length $close != 1
MC/DC0%0/2
length $open != 1 or length $close != 1
length $open != 1
length $close != 1
Truth table33%1/3
A or B
A= length $open != 1B= length $close != 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | $self->_error_out("Delimiters must be single characters", 51235); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 1 | ▶ | if ($open eq $close) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $self->_error_out("Open and close delimiters must be different characters", 51236); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 1 | $self->{open_delim} = $open; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 1 | $self->{close_delim} = $close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | $self->_precompute_tags(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # Clear all caches since results are delimiter-dependent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | $self->{_blocks_cache} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | $self->{_if_rules_cache} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 1 | $self->{_convert_cache} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | $self->{_sub_cache} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | $self->{_verified_sub_cache} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | $self->{_mod_cache} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # Dive down an array or hashref using our dotted syntax | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 80 | ▶ | sub array_dive { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
array_dive: called CC=11 SCAR=26.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 80 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 80 | my $needle = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 80 | my $haystack = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 80 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # Quick path: needle is a direct key in the hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 80 | ▶ | if (exists $haystack->{$needle}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 50 | return $haystack->{$needle}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # Walk dotted path (e.g. "user.address.city") through nested structures | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 30 | my @parts = split /\./, $needle; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 30 | my $arr = $haystack; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 30 | for my $elem (@parts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 53 | ▶ | if (!defined $arr) { return undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 53 | ▶ | if (ref $arr eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 10 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 10 | $arr = $arr->[$elem]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } elsif (ref $arr eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 43 | ▶ | if (!exists $arr->{$elem}) { return undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 34 | $arr = $arr->{$elem}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 21 | return $arr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # HTML-escape a string for safe output. Encodes & < > " ' to entities. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # Usable as a modifier: {$var|escape} or as a callable: {escape($var)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 32 | ▶ | sub escape { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
escape: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 32 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 32 | ▶ | if (ref $str eq 'ARRAY') { return 'ARRAY' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 31 | ▶ | if (ref $str eq 'HASH') { return 'HASH' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 31 | $str =~ s/&/&/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 31 | $str =~ s/</</g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 31 | $str =~ s/>/>/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 31 | $str =~ s/"/"/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 31 | $str =~ s/'/'/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 31 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # Bypass auto-escaping when auto_escape is on: {$var|noescape} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 7 | ▶ | sub noescape { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
noescape: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 7 | return shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # Apply auto-escaping if enabled, otherwise return value unchanged. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # Ref types (ARRAY/HASH) pass through unescaped. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | sub _esc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_esc: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | my ($self, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | if (!$self->{auto_escape}) { return $val } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | if (ref $val) { return $val } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | return escape($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 129 | ▶ | sub ltrim_one { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ltrim_one: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 129 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 129 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 129 | my $char = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 129 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 15 | return substr($str, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 114 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 23 | ▶ | sub find_ending_tag { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_ending_tag: called CC=7 SCAR=19.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 23 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 23 | ▶ | my $haystack = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 23 | my $open_tag = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 23 | my $close_tag = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # Find the first close tag; if there's only one open tag before it, we're done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 23 | my $pos = index($haystack, $close_tag); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 23 | ▶ | if ($pos < 0) { return undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 23 | my $substr = substr($haystack, 0, $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 23 | my $open_count = () = $substr =~ /\Q$open_tag\E/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 23 | ▶ | if ($open_count == 1) { return $pos } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # Nested tags: scan forward through subsequent close tags until | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # open/close counts balance (max 5 nesting levels) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 5 | my $close_len = length $close_tag; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 5 | my $offset = $pos + $close_len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 5 | for (0 .. 4) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 13 | $pos = index($haystack, $close_tag, $offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 13 | ▶ | if ($pos < 0) { return undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 13 | $substr = substr($haystack, 0, $pos + 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 13 | $open_count = () = $substr =~ /\Q$open_tag\E/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 13 | my $close_count = () = $substr =~ /\Q$close_tag\E/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 13 | ▶ | if ($open_count == $close_count) { return $pos } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 8 | $offset = $pos + $close_len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 24 | ▶ | sub get_tokens { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_tokens: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 24 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 24 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 24 | my $o = quotemeta($self->{open_delim}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 24 | my $c = quotemeta($self->{close_delim}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 24 | my @tokens = split /($o[^$c]+$c)/, $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 24 | ▶ | @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 $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 24 | return @tokens; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 195 | ▶ | sub is_if_token { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_if_token: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 195 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 195 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 195 | ▶ | if ($str eq $self->{_tag_else}) { return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 153 | ▶ | if ($str eq $self->{_tag_if_close}) { return 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 123 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 70 | my $inner = substr($str, length($self->{open_delim})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 70 | $inner =~ s/^\S+\s+//; # strip 'if ' or 'elseif ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 70 | $inner =~ s/\Q$self->{close_delim}\E$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 70 | return $inner; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 53 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | # Private methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 12 | ▶ | sub _precompute_tags { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_precompute_tags: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 12 | my $o = $self->{open_delim}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 12 | my $c = $self->{close_delim}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | # Tag strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 12 | $self->{_tag_if} = "${o}if "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 12 | $self->{_tag_if_close} = "${o}/if${c}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 12 | $self->{_tag_else} = "${o}else${c}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 12 | $self->{_tag_elseif} = "${o}elseif "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 12 | $self->{_tag_foreach} = "${o}foreach "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 12 | $self->{_tag_foreach_close} = "${o}/foreach${c}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 12 | $self->{_tag_include} = "${o}include "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 12 | $self->{_tag_literal} = "${o}literal${c}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 12 | $self->{_tag_literal_close} = "${o}/literal${c}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 12 | $self->{_tag_comment_open} = "${o}*"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 12 | $self->{_tag_comment_close} = "*${c}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # Precomputed tag lengths (avoids repeated length() calls in hot loops) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 12 | $self->{_tag_if_len} = length($self->{_tag_if}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 12 | $self->{_tag_if_close_len} = length($self->{_tag_if_close}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 12 | $self->{_tag_foreach_len} = length($self->{_tag_foreach}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 12 | $self->{_tag_include_len} = length($self->{_tag_include}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 12 | $self->{_tag_literal_len} = length($self->{_tag_literal}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 12 | $self->{_tag_literal_close_len} = length($self->{_tag_literal_close}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | # Precomputed quotemeta values (avoids per-call quotemeta in _get_blocks) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 12 | $self->{_od_qr} = quotemeta($o); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 12 | $self->{_cd_qr} = quotemeta($c); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | # Precompiled space-guard regex (avoids per-open-delimiter regex compile) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 12 | my $od_qr = $self->{_od_qr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 12 | my $cd_qr = $self->{_cd_qr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 12 | $self->{_space_guard_re} = qr/\s[$od_qr$cd_qr]\s/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | # Precompiled variable regex: {$var} or {$var.dot.path} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 12 | $self->{_re_var_simple} = qr/^\Q$o\E\$(\w[\w.]*)\Q$c\E$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 12 | $self->{_re_var_full} = qr/^\Q$o\E\$([\w|.'";\t :,!@#%^&*?_\/\\\-]+)\Q$c\E$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | # Precompiled foreach regex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 12 | $self->{_re_foreach} = qr/^\Q$o\Eforeach (\$\w[\w.]*) as \$(\w+)(?: => \$(\w+))?\Q$c\E(.+)\Q$o\E\/foreach\Q$c\E$/s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | # Precompiled literal regex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 12 | $self->{_re_literal} = qr/^\Q$o\Eliteral\Q$c\E(.+)\Q$o\E\/literal\Q$c\E$/s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | # Precompiled expression catch-all regex | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 12 | $self->{_re_expr} = qr/^\Q$o\E(.+)\Q$c\E$/s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # Precompiled simple if regex (no else/elseif) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 12 | $self->{_re_if_simple} = qr/\Q$o\Eif (.+?)\Q$c\E(.+)\Q$o\E\/if\Q$c\E/s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | # Precomputed ord values for fast single-character delimiter checks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 12 | $self->{_od_ord} = ord($o); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 12 | $self->{_cd_ord} = ord($c); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 12 | $self->{_dollar_ord} = ord('$'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | # Precompiled modifier-split regexes (avoids per-modifier-call recompile) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 12 | $self->{_pipe_re} = qr/\|(?![^"]*"(?:(?:[^"]*"){2})*[^"]*$)(?![^']*'(?:(?:[^']*'){2})*[^']*$)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 12 | $self->{_comma_re} = qr/,(?=(?:[^"]*"[^"]*")*[^"]*$)(?=(?:[^']*'[^']*')*[^']*$)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 12 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 1 | ▶ | sub _get_perl_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_perl_file: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 1 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 1 | my $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 1 | ▶ | while (caller($i)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 3 | $file = (caller($i))[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 3 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 1 | ▶ | return $file || __FILE__; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$file || __FILE__
MC/DC0%0/1
$file || __FILE__
$file
Truth table50%1/2
A
A= $file
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 4 | ▶ | sub _get_tpl_content { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_tpl_content: called CC=11 SCAR=31.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 4 | ▶ | my $tpl_file = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 4 | $self->{tpl_file} = $tpl_file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 4 | my $tf = $tpl_file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 4 | ▶ | if ($self->{perl_file_dir}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 4 | $tf = $self->{perl_file_dir} . "/$tf"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 4 | ▶ | if (!length($tpl_file)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | $self->_error_out("Template file name is empty", 86801); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 4 | ▶ | if ($tpl_file eq SLUZ_INLINE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | my ($c, $line_offset) = $self->_get_inline_content($self->{perl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | if (defined $c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | $self->{tpl_file_display} = $self->{perl_file}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | $self->{tpl_line_offset} = $line_offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | return $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | delete $self->{tpl_file_display}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | delete $self->{tpl_line_offset}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 4 | delete $self->{tpl_file_display}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 4 | delete $self->{tpl_line_offset}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 4 | ▶ | if ($tf && !-r $tf) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$tf and not -r $tf
MC/DC0%0/2
$tf and not -r $tf
$tf
not -r $tf
Truth table33%1/3
A and not(B)
A= $tfB= not -r $tf
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | $self->_error_out("Unable to load template file <code>$tf</code>", 42280); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 4 | ▶ | if ($tf) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 4 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 4 | ▶ | open my $fh, '<', $tf or $self->_error_out("Cannot open <code>$tf</code>: $!", 13983); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 4 | my $str = <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 4 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 4 | ▶ | return $str // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$str // ""
MC/DC0%0/1
$str // ""
$str
Truth table50%1/2
A
A= $str
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | sub _get_inline_content { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_inline_content: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | ▶ | open my $fh, '<', $file or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | my $str = <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | my $idx = index($str, '__DATA__'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | if ($idx < 0) { return undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | my $before = substr($str, 0, $idx + 9); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | my $line_offset = $before =~ tr/\n//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | return (substr($str, $idx + 9), $line_offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | # Tokenizer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 331 | ▶ | sub _get_blocks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_blocks: called CC=41 SCAR=37.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 331 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 331 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | # Check blocks cache — avoids re-tokenizing the same payload string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | # (e.g. an {if} payload re-parsed on every iteration of a {foreach} loop) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 331 | ▶ | if (exists $self->{_blocks_cache}{$str}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 15 | return @{$self->{_blocks_cache}{$str}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 316 | my $od = $self->{open_delim}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 316 | my $cd = $self->{close_delim}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 316 | my $tag_if = $self->{_tag_if}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 316 | my $tag_foreach = $self->{_tag_foreach}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 316 | my $tag_literal = $self->{_tag_literal}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 316 | my $slen = length $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 316 | my $start = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 316 | my $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | my @blocks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 316 | my $z = index($str, $od); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 316 | ▶ | if ($z < 0) { $z = $slen } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 316 | ▶ | for ($i = $z; $i < $slen; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 851 | my $char = substr($str, $i, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 851 | my $is_open = $char eq $od; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 851 | my $is_closed = $char eq $cd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 851 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 293 | my $next_open = index($str, $od, $i); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 293 | ▶ | if ($next_open < 0) { $next_open = $slen } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 293 | my $next_close = index($str, $cd, $i); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 293 | ▶ | if ($next_close < 0) { $next_close = $slen } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 293 | ▶ | if ($next_open < $next_close) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 7 | $i = $next_open - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 286 | $i = $next_close - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 293 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 558 | my $has_len = $start != $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 558 | my $is_comment = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 558 | ▶ | if ($is_open) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 288 | my $prev_c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 288 | ▶ | if ($i > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 34 | $prev_c = substr($str, $i - 1, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 254 | $prev_c = ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 288 | my $next_c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 288 | ▶ | if ($i + 1 < $slen) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 288 | $next_c = substr($str, $i + 1, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | $next_c = ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 288 | my $chk = $prev_c . $char . $next_c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 288 | ▶ | if ($chk =~ $self->{_space_guard_re}) { $is_open = 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 288 | ▶ | if ($next_c eq '*') { $is_comment = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 558 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 30 | push @blocks, [substr($str, $start, $i - $start), $i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 30 | $start = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } elsif ($is_closed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 270 | my $len = $i - $start + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 270 | my $block = substr($str, $start, $len); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 270 | my $matched_block; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 270 | ▶ | if (index($block, $tag_if) == 0) { $matched_block = 'if' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 39 | elsif (index($block, $tag_foreach) == 0) { $matched_block = 'foreach' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 7 | elsif (index($block, $tag_literal) == 0) { $matched_block = 'literal' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 270 | ▶ | if ($matched_block) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 104 | my $close_tag = "${od}/${matched_block}${cd}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 104 | ▶ | for (my $j = $i + 1; $j < length $str; $j++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 2077 | ▶ | if (substr($str, $j, 1) eq $cd) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 230 | my $tmp = substr($str, $start, $j - $start + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 230 | my $oc = () = $tmp =~ /\Q${od}${matched_block}\E/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 230 | my $cc = () = $tmp =~ /\Q${close_tag}\E/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 230 | ▶ | if ($oc == $cc) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 103 | $block = $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 103 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 270 | ▶ | if (length $block) { push @blocks, [$block, $i] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 270 | $start += length($block); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 270 | $i = $start; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 558 | ▶ | if ($is_comment) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 23 | my $end = $self->find_ending_tag(substr($str, $start), $self->{_tag_comment_open}, $self->{_tag_comment_close}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 23 | ▶ | if (!defined $end) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | my ($line, $col, $file) = $self->_get_char_location($i, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | $self->_error_out("Missing closing <code>$self->{_tag_comment_close}</code> for comment in <code>$file</code> on line #$line", 48724); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 23 | my $after = $start + $end + length($self->{_tag_comment_close}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 23 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 23 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 23 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 7 | $after++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 23 | $start = $after; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 23 | $i = $start - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 316 | ▶ | if ($start < $slen) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 70 | push @blocks, [substr($str, $start), $i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | # Strip leading newline from text blocks that follow {if} or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | # {foreach} blocks, to avoid double-newlines when the block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | # payload already ends with \n. For {foreach}, only strip when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | # the payload actually ends with \n — if the payload is inline | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | # (no trailing \n), the newline is structural content, not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | # whitespace noise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 316 | my $prev_is_if = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 316 | my $tag_foreach_close = $self->{_tag_foreach_close}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 316 | for my $i (0 .. $#blocks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 370 | ▶ | 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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 370 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 370 | ▶ | if ($prev_is_if) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 4 | my $should_strip = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 4 | ▶ | if ($blocks[$i-1][0] =~ /^\Q$tag_foreach\E.+?\}(.*)\Q$tag_foreach_close\E$/s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 2 | ▶ | $should_strip = (substr($1, -1) eq "\n") ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 4 | ▶ | if ($should_strip) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 3 | $blocks[$i][0] = $self->ltrim_one($bstr, "\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 370 | $prev_is_if = $cur_is_if; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 316 | $self->{_blocks_cache}{$str} = \@blocks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 316 | return @blocks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 289 | ▶ | sub _process_blocks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_blocks: called CC=28 SCAR=33.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 289 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 289 | my $blocks = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 289 | my $out = shift; # Optional: ref to append output to (avoids temp string + concat) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 289 | my $od_ord = $self->{_od_ord}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 289 | my $od = $self->{open_delim}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 289 | my $var_tag = "${od}\$"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 289 | my $var_re = $self->{_re_var_simple}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 289 | ▶ | if ($out) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 57 | for my $x (@$blocks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 62 | my $block = $x->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 62 | ▶ | next unless length $block; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 62 | ▶ | if (ord($block) != $od_ord) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 42 | $$out .= $block; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 42 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | # Fast path: {$var} or {$var.dot} with no modifier — inline | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | # variable resolution, skip _process_block AND _variable_block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 20 | ▶ | if (substr($block, 0, 2) eq $var_tag && index($block, '|') < 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
substr($block, 0, 2) eq $var_tag and index($block, "|") == -1 and $block =~ /$var_re/u
substr($block, 0, 2) eq $var_tag and index($block, "|") == -1
MC/DC66%2/3
substr($block, 0, 2) eq $var_tag and index($block, "|") == -1 and $block =~ /$var_re/u
substr($block, 0, 2) eq $var_tag
index($block, "|") == -1
$block =~ /$var_re/u
Truth table75%3/4
A and B and C
A= substr($block, 0, 2) eq $var_tagB= index($block, "|") == -1C= $block =~ /$var_re/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | && $block =~ $var_re) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 13 | my $var = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 13 | my $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 13 | ▶ | if (index($var, '.') < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 9 | $val = $self->{tpl_vars}{$var}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 4 | $val = $self->array_dive($var, $self->{tpl_vars}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 13 | ▶ | if (ref $val eq 'ARRAY') { $$out .= 'ARRAY' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | elsif (ref $val eq 'HASH') { $$out .= 'HASH' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 13 | ▶ | elsif (defined $val) { $$out .= ($self->{auto_escape} ? escape($val) : $val) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 13 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | # If block fast path — skip _process_block dispatch (mirrors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | # the $html branch so the $out path is equally fast). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 7 | ▶ | if (substr($block, 0, $self->{_tag_if_len}) eq $self->{_tag_if} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
substr($block, 0, $self->{"_tag_if_len"}) eq $self->{"_tag_if"} and substr($block, -$self->{"_tag_if_close_len"}) eq $self->{"_tag_if_close"}
MC/DC50%1/2
substr($block, 0, $self->{"_tag_if_len"}) eq $self->{"_tag_if"} and substr($block, -$self->{"_tag_if_close_len"}) eq $self->{"_tag_if_close"}
substr($block, 0, $self->{"_tag_if_len"}) eq $self->{"_tag_if"}
substr($block, -$self->{"_tag_if_close_len"}) eq $self->{"_tag_if_close"}
Truth table66%2/3
A and B
A= substr($block, 0, $self->{"_tag_if_len"}) eq $self->{"_tag_if"}B= substr($block, -$self->{"_tag_if_close_len"}) eq $self->{"_tag_if_close"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | && substr($block, -$self->{_tag_if_close_len}) eq $self->{_tag_if_close}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 6 | $self->{char_pos} = $x->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 6 | $$out .= $self->_if_block($block); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 1 | $$out .= $self->_process_block($block, $x->[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 57 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 232 | my $html = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 232 | for my $x (@$blocks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 272 | my $block = $x->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 272 | ▶ | next unless length $block; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 272 | ▶ | if (ord($block) != $od_ord) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 52 | $html .= $block; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 52 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | # Fast path: {$var} or {$var.dot} with no modifier | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 220 | ▶ | if (substr($block, 0, 2) eq $var_tag && index($block, '|') < 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
substr($block, 0, 2) eq $var_tag and index($block, "|") == -1 and $block =~ /$var_re/u
substr($block, 0, 2) eq $var_tag and index($block, "|") == -1
MC/DC100%3/3
substr($block, 0, 2) eq $var_tag and index($block, "|") == -1 and $block =~ /$var_re/u
substr($block, 0, 2) eq $var_tag
index($block, "|") == -1
$block =~ /$var_re/u
Truth table100%4/4
A and B and C
A= substr($block, 0, 2) eq $var_tagB= index($block, "|") == -1C= $block =~ /$var_re/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | && $block =~ $var_re) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 49 | my $var = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 49 | my $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 49 | ▶ | if (index($var, '.') < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 45 | $val = $self->{tpl_vars}{$var}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 4 | $val = $self->array_dive($var, $self->{tpl_vars}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 49 | ▶ | if (ref $val eq 'ARRAY') { $html .= 'ARRAY' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | elsif (ref $val eq 'HASH') { $html .= 'HASH' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 38 | ▶ | elsif (defined $val) { $html .= ($self->{auto_escape} ? escape($val) : $val) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 49 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | # If block fast path — skip _process_block dispatch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 171 | ▶ | if (substr($block, 0, $self->{_tag_if_len}) eq $self->{_tag_if} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
substr($block, 0, $self->{"_tag_if_len"}) eq $self->{"_tag_if"} and substr($block, -$self->{"_tag_if_close_len"}) eq $self->{"_tag_if_close"}
MC/DC100%2/2
substr($block, 0, $self->{"_tag_if_len"}) eq $self->{"_tag_if"} and substr($block, -$self->{"_tag_if_close_len"}) eq $self->{"_tag_if_close"}
substr($block, 0, $self->{"_tag_if_len"}) eq $self->{"_tag_if"}
substr($block, -$self->{"_tag_if_close_len"}) eq $self->{"_tag_if_close"}
Truth table100%3/3
A and B
A= substr($block, 0, $self->{"_tag_if_len"}) eq $self->{"_tag_if"}B= substr($block, -$self->{"_tag_if_close_len"}) eq $self->{"_tag_if_close"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | && substr($block, -$self->{_tag_if_close_len}) eq $self->{_tag_if_close}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 44 | $self->{char_pos} = $x->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 44 | $html .= $self->_if_block($block); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 44 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 127 | $html .= $self->_process_block($block, $x->[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 222 | return $html; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 140 | ▶ | sub _process_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_block: called CC=14 SCAR=26.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 140 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 140 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 140 | ▶ | my $char_pos = shift // -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // -1
MC/DC0%0/1
shift() // -1
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 140 | $self->{char_pos} = $char_pos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 140 | my $od = $self->{open_delim}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 140 | my $cd_ord = $self->{_cd_ord}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | # 1. Variable block {$foo} or {$foo|modifier} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 140 | ▶ | if (substr($str, 0, 2) eq "${od}\$" && $str =~ $self->{_re_var_full}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
substr($str, 0, 2) eq "$od\$" and $str =~ /$self->{"_re_var_full"}/u
MC/DC100%2/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 table100%3/3
A and B
A= substr($str, 0, 2) eq "$od\$"B= $str =~ /$self->{"_re_var_full"}/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 60 | return $self->_variable_block($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | # 2. If block {if ...}{/if} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 80 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | && substr($str, -$self->{_tag_if_close_len}) eq $self->{_tag_if_close}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | return $self->_if_block($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | # 3. Foreach block {foreach ...}{/foreach} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 80 | ▶ | 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/DC50%1/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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 39 | return $self->_foreach_block($1, $2, $3, $4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | # 4. Include block {include ...} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 41 | ▶ | if (substr($str, 0, $self->{_tag_include_len}) eq $self->{_tag_include}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 9 | return $self->_include_block($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | # 5. Literal block {literal}...{/literal} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 32 | ▶ | 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/DC50%1/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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 7 | return $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | # 6. Expression / function block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 25 | ▶ | if ($str =~ $self->{_re_expr}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 21 | return $self->_expression_block($str, $1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | # 7. Unclosed tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 4 | ▶ | if (ord(substr($str, -1)) != $cd_ord) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 3 | my $tag_start = $self->{char_pos} - length($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 3 | my ($line, $col, $file) = $self->_get_char_location($tag_start, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 3 | $self->_error_out("Unclosed tag <code>$str</code> in <code>$file</code> on line #$line", 45821); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | # 8. Fallthrough | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 1 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | # Block handlers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 60 | ▶ | sub _variable_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_variable_block: called CC=38 SCAR=44.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 60 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 60 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | # Fast path: no pipe means no modifier, just resolve the variable. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | # Avoids running the pipe-split regex on every plain variable block. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 60 | ▶ | if (index($str, '|') < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | my $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | # Inline simple key lookup (no dots) — skips array_dive method call | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 0 | ▶ | if (index($str, '.') < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | $ret = $self->{tpl_vars}{$str}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | $ret = $self->array_dive($str, $self->{tpl_vars}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | ▶ | if (ref $ret eq 'ARRAY') { return 'ARRAY' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | ▶ | if (ref $ret eq 'HASH') { return 'HASH' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | ▶ | if (defined $ret) { return ($self->{auto_escape} ? escape($ret) : $ret) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 60 | ▶ | if ($str =~ /(.+?)\|(.*)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 60 | my $key = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 60 | my $mod = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 60 | my $tmp = $self->array_dive($key, $self->{tpl_vars}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 60 | ▶ | my $is_nothing = (!defined $tmp || (defined $tmp && ref $tmp eq '' && !length $tmp && $tmp ne '0')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%10/12
!defined($tmp) || defined $tmp && ref $tmp eq '' && !length($tmp) && $tmp ne '0'
defined $tmp and ref $tmp eq "" and not length $tmp and $tmp ne 0
defined $tmp and ref $tmp eq "" and not length $tmp
defined $tmp and ref $tmp eq ""
MC/DC60%3/5
!defined($tmp) || defined $tmp && ref $tmp eq '' && !length($tmp) && $tmp ne '0'
!defined($tmp)
defined $tmp
ref $tmp eq ""
not length $tmp
$tmp ne 0
Truth table66%4/6
not(A) || B and C and not(D) and E
A= !defined($tmp)B= defined $tmpC= ref $tmp eq ""D= not length $tmpE= $tmp ne 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 60 | my $is_default = index($mod, 'default:') >= 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 60 | ▶ | if ($is_nothing && $is_default) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$is_nothing and $is_default
MC/DC100%2/2
$is_nothing and $is_default
$is_nothing
$is_default
Truth table100%3/3
A and B
A= $is_nothingB= $is_default
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 6 | my $dval = $mod; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 6 | $dval =~ s/^.*?default://; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 6 | my ($ret) = $self->_peval($dval); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 6 | ▶ | if (defined $ret) { return $ret } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | ▶ | } elsif (!$is_nothing && $is_default) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
not $is_nothing and $is_default
MC/DC100%2/2
not $is_nothing and $is_default
not $is_nothing
$is_default
Truth table100%3/3
not(A) and B
A= not $is_nothingB= $is_default
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 3 | ▶ | return $tmp // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$tmp // ""
MC/DC0%0/1
$tmp // ""
$tmp
Truth table50%1/2
A
A= $tmp
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 51 | ▶ | if ($is_nothing) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 6 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 45 | my $pre = $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 45 | my $seen_escape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 45 | my $seen_noescape = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | # Split on | not inside double or single quotes (supports chained | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | # modifiers like {$x|uc|substr:0,3}). Regex precompiled in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | # _precompute_tags to avoid per-call recompile cost. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 45 | my $pipe_re = $self->{_pipe_re}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 45 | for my $m_part (split $pipe_re, $mod) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 49 | my @x = split /:/, $m_part, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 49 | ▶ | 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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 49 | ▶ | if ($func eq 'escape') { $seen_escape = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 49 | ▶ | if ($func eq 'noescape') { $seen_noescape = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 49 | ▶ | 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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 49 | my @params = ($pre); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 49 | ▶ | if (length $param_str) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | # Split on commas not inside double or single quotes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | # (parameter separator in modifier calls like substr:2,2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | my @new = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 16 | my ($v) = $self->_peval($_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 16 | $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 15 | } split $self->{_comma_re}, $param_str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 15 | push @params, @new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | # Resolve the modifier coderef once per func name and cache it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | # Priority: main::, current package (Template::Sluz built-ins), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | # then CORE:: built-in operators. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 49 | my $cref = $self->{_mod_cache}{$func}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 49 | ▶ | if (!defined $cref) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 10 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 12 | ▶ | if (defined &{"main::$func"}) { $cref = \&{"main::$func"} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 10 | elsif (defined &{$func}) { $cref = \&{$func} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 4 | elsif (defined &{"CORE::$func"}) { $cref = \&{"CORE::$func"} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 0 | else { $cref = 0 } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 12 | $self->{_mod_cache}{$func} = $cref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 49 | ▶ | if (!$cref) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | my ($line, $col, $file) = $self->_get_char_location($self->{char_pos}, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | $self->_error_out("Unknown function call <code>$func</code> in <code>$file</code> on line #$line", 47204); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 49 | $pre = eval { $cref->(@params) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 49 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 0 | $self->_error_out("Exception: $@", 79134); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 45 | ▶ | if ($self->{auto_escape} && !$seen_noescape && !$seen_escape) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$self->{"auto_escape"} and not $seen_noescape and not $seen_escape
$self->{"auto_escape"} and not $seen_noescape
MC/DC100%3/3
$self->{"auto_escape"} and not $seen_noescape and not $seen_escape
$self->{"auto_escape"}
not $seen_noescape
not $seen_escape
Truth table100%4/4
A and not(B) and not(C)
A= $self->{"auto_escape"}B= not $seen_noescapeC= not $seen_escape
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 1 | return escape($pre); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 44 | return $pre; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 0 | my $ret = $self->array_dive($str, $self->{tpl_vars}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 0 | ▶ | if (ref $ret eq 'ARRAY') { return 'ARRAY' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 0 | ▶ | if (ref $ret eq 'HASH') { return 'HASH' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 0 | ▶ | if (defined $ret) { return ($self->{auto_escape} ? escape($ret) : $ret) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 68 | ▶ | sub _if_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_if_block: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 68 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | 68 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 68 | my @rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 68 | ▶ | if (exists $self->{_if_rules_cache}{$str}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 12 | @rules = @{$self->{_if_rules_cache}{$str}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 56 | my $od = $self->{open_delim}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 56 | my $cd = $self->{close_delim}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 56 | my $isimple_start = length($od) + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 56 | my $else_check = $od . 'else'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 56 | my $is_simple = index($str, $else_check, $isimple_start) < 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 56 | ▶ | if ($is_simple) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 32 | $str =~ $self->{_re_if_simple}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 32 | ▶ | my $cond = $1 // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$1 // ""
MC/DC100%1/1
$1 // ""
$1
Truth table100%2/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 32 | ▶ | my $payload = $2 // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$2 // ""
MC/DC100%1/1
$2 // ""
$2
Truth table100%2/2
A
A= $2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 32 | $payload = $self->ltrim_one($payload, "\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 32 | @rules = ([$cond, $payload]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 24 | my @toks = $self->get_tokens($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 24 | @rules = $self->_if_rules_from_tokens(\@toks); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 56 | $self->{_if_rules_cache}{$str} = \@rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 68 | my $ret = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 68 | for my $rule (@rules) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 86 | my $raw = $rule->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | # Inline _convert_vars for cached expressions — saves method call per iteration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | my $test = (index($raw, '$') < 0) ? $raw : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 86 | ▶ | ($self->{_convert_cache}{$raw} // $self->_convert_vars($raw)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"_convert_cache"}{$raw} // $self->_convert_vars($raw)
MC/DC0%0/2
$self->{"_convert_cache"}{$raw} // $self->_convert_vars($raw)
$self->{"_convert_cache"}{$raw}
$self->_convert_vars($raw)
Truth table66%2/3
A // B
A= $self->{"_convert_cache"}{$raw}B= $self->_convert_vars($raw)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 86 | my $payload = $rule->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 86 | my ($res) = $self->_peval($test); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 86 | ▶ | if ($res) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | # Inline _get_blocks for cached payloads. Pass \$ret to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | # _process_blocks so it appends directly — avoids a temp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | # string allocation + concat per if-payload render. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 57 | my $cached = $self->{_blocks_cache}{$payload}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 57 | ▶ | my @in_blocks = $cached ? @$cached : $self->_get_blocks($payload); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 57 | $self->_process_blocks(\@in_blocks, \$ret); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 57 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 68 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 39 | ▶ | sub _foreach_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_foreach_block: called CC=64 SCAR=44.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 39 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | 39 | my $src_expr = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 39 | my $okey = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 39 | my $oval = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 39 | my $payload = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 39 | my $conv_src = $self->_convert_vars($src_expr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | 39 | $payload = $self->ltrim_one($payload, "\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 39 | my @blocks = $self->_get_blocks($payload); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | # Pre-classify blocks for fast dispatch in the loop (cached in block arrays) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | # type: -1=empty, 0=text, 1=simple_var, 2=if_block, 99=other | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 39 | my $od = $self->{open_delim}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | 39 | my $od_ord = $self->{_od_ord}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 39 | for my $b (@blocks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 62 | ▶ | next if defined $b->[2]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 56 | my $bs = $b->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 56 | ▶ | if (!length $bs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 0 | $b->[2] = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | } elsif (ord($bs) != $od_ord) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 16 | $b->[2] = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | ▶ | } elsif (substr($bs, 0, 2) eq "${od}\$" && index($bs, '|') < 0 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
substr($bs, 0, 2) eq "$od\$" and index($bs, "|") == -1 and $bs =~ /$self->{"_re_var_simple"}/u
substr($bs, 0, 2) eq "$od\$" and index($bs, "|") == -1
MC/DC66%2/3
substr($bs, 0, 2) eq "$od\$" and index($bs, "|") == -1 and $bs =~ /$self->{"_re_var_simple"}/u
substr($bs, 0, 2) eq "$od\$"
index($bs, "|") == -1
$bs =~ /$self->{"_re_var_simple"}/u
Truth table75%3/4
A and B and C
A= substr($bs, 0, 2) eq "$od\$"B= index($bs, "|") == -1C= $bs =~ /$self->{"_re_var_simple"}/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | && $bs =~ $self->{_re_var_simple}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 30 | $b->[2] = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 30 | $b->[3] = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | ▶ | } elsif (substr($bs, 0, $self->{_tag_if_len}) eq $self->{_tag_if} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
substr($bs, 0, $self->{"_tag_if_len"}) eq $self->{"_tag_if"} and substr($bs, -$self->{"_tag_if_close_len"}) eq $self->{"_tag_if_close"}
MC/DC50%1/2
substr($bs, 0, $self->{"_tag_if_len"}) eq $self->{"_tag_if"} and substr($bs, -$self->{"_tag_if_close_len"}) eq $self->{"_tag_if_close"}
substr($bs, 0, $self->{"_tag_if_len"}) eq $self->{"_tag_if"}
substr($bs, -$self->{"_tag_if_close_len"}) eq $self->{"_tag_if_close"}
Truth table66%2/3
A and B
A= substr($bs, 0, $self->{"_tag_if_len"}) eq $self->{"_tag_if"}B= substr($bs, -$self->{"_tag_if_close_len"}) eq $self->{"_tag_if_close"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | && substr($bs, -$self->{_tag_if_close_len}) eq $self->{_tag_if_close}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 6 | $b->[2] = 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 4 | $b->[2] = 99; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 39 | my ($src) = $self->_peval($conv_src); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 39 | ▶ | if (!defined $src) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 2 | $src = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | ▶ | } elsif (ref $src ne 'ARRAY' && ref $src ne 'HASH') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
ref $src ne "ARRAY" and ref $src ne "HASH"
MC/DC100%2/2
ref $src ne "ARRAY" and ref $src ne "HASH"
ref $src ne "ARRAY"
ref $src ne "HASH"
Truth table100%3/3
A and B
A= ref $src ne "ARRAY"B= ref $src ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 1 | $src = [$src]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 39 | my $pfx = $self->{var_prefix}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | # Precompute __S keys for the loop variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 39 | my $okey_ks = "${pfx}_$okey"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 39 | ▶ | my $oval_ks = defined $oval ? "${pfx}_$oval" : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | 39 | my $first_ks = "${pfx}__FOREACH_FIRST"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | 39 | my $last_ks = "${pfx}__FOREACH_LAST"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | 39 | my $index_ks = "${pfx}__FOREACH_INDEX"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | 39 | my $ret = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 39 | my $idx = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 39 | my $need_first = index($payload, '__FOREACH_FIRST') >= 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 39 | my $need_last = index($payload, '__FOREACH_LAST') >= 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | 39 | my $need_index = index($payload, '__FOREACH_INDEX') >= 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | # Save only the keys we'll modify — O(k) where k <= 5, vs O(n) for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | # copying the entire tpl_vars/__S hashes. Big win for nested foreach. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | 39 | my @tpl_keys = ($okey); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | 39 | my @ks_keys = ($okey_ks); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 39 | ▶ | if (defined $oval) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 9 | push @tpl_keys, $oval; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | 9 | push @ks_keys, $oval_ks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 39 | ▶ | push @tpl_keys, '__FOREACH_FIRST' if $need_first; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | 39 | ▶ | push @ks_keys, $first_ks if $need_first; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 39 | ▶ | push @tpl_keys, '__FOREACH_LAST' if $need_last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 39 | ▶ | push @ks_keys, $last_ks if $need_last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | 39 | ▶ | push @tpl_keys, '__FOREACH_INDEX' if $need_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | 39 | ▶ | push @ks_keys, $index_ks if $need_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | 39 | my @tpl_exists = map { exists $self->{tpl_vars}{$_} } @tpl_keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | 39 | my @tpl_vals = map { $self->{tpl_vars}{$_} } @tpl_keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | 39 | my @ks_exists = map { exists $self->{__S}{$_} } @ks_keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | 39 | my @ks_vals = map { $self->{__S}{$_} } @ks_keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | 39 | ▶ | if (ref $src eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | 35 | my $last = $#$src; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | 35 | for my $i (0 .. $last) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | 88 | ▶ | if ($need_first) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | 6 | ▶ | $self->{tpl_vars}{__FOREACH_FIRST} = ($idx == 0) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 6 | ▶ | $self->{__S}{$first_ks} = ($idx == 0) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | 88 | ▶ | if ($need_last) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 3 | ▶ | $self->{tpl_vars}{__FOREACH_LAST} = ($idx == $last) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 3 | ▶ | $self->{__S}{$last_ks} = ($idx == $last) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 88 | ▶ | if ($need_index) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 3 | $self->{tpl_vars}{__FOREACH_INDEX} = $idx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 3 | $self->{__S}{$index_ks} = $idx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 88 | ▶ | if (defined $oval) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | 16 | $self->{tpl_vars}{$okey} = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | 16 | $self->{tpl_vars}{$oval} = $src->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | 16 | $self->{__S}{$okey_ks} = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | 16 | $self->{__S}{$oval_ks} = $src->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | 72 | $self->{tpl_vars}{$okey} = $src->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | 72 | $self->{__S}{$okey_ks} = $src->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | # Inline block processing with pre-classified types — no substr/regex per iteration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | 88 | for my $b (@blocks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 132 | my $type = $b->[2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | 132 | ▶ | if ($type == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 34 | $ret .= $b->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | } elsif ($type == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | 68 | my $var = $b->[3]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | 68 | my $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | 68 | ▶ | if (index($var, '.') < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | 56 | $val = $self->{tpl_vars}{$var}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | 12 | $val = $self->array_dive($var, $self->{tpl_vars}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | 68 | ▶ | if (ref $val eq 'ARRAY') { $ret .= 'ARRAY' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | 0 | elsif (ref $val eq 'HASH') { $ret .= 'HASH' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | 68 | ▶ | elsif (defined $val) { $ret .= ($self->{auto_escape} ? escape($val) : $val) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | } elsif ($type == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 18 | $self->{char_pos} = $b->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 18 | $ret .= $self->_if_block($b->[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | } elsif ($type == -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 12 | $ret .= $self->_process_block($b->[0], $b->[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 88 | $idx++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | } elsif (ref $src eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | 4 | my @keys = sort keys %$src; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | 4 | my $last = $#keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | 4 | for my $i (0 .. $last) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | 11 | my $k = $keys[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 11 | ▶ | if ($need_first) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | 0 | ▶ | $self->{tpl_vars}{__FOREACH_FIRST} = ($idx == 0) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 0 | ▶ | $self->{__S}{$first_ks} = ($idx == 0) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | 11 | ▶ | if ($need_last) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | 0 | ▶ | $self->{tpl_vars}{__FOREACH_LAST} = ($idx == $last) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 0 | ▶ | $self->{__S}{$last_ks} = ($idx == $last) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 11 | ▶ | if ($need_index) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 0 | $self->{tpl_vars}{__FOREACH_INDEX} = $idx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 0 | $self->{__S}{$index_ks} = $idx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | 11 | ▶ | if (defined $oval) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | 6 | $self->{tpl_vars}{$okey} = $k; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | 6 | $self->{tpl_vars}{$oval} = $src->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 6 | $self->{__S}{$okey_ks} = $k; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 6 | $self->{__S}{$oval_ks} = $src->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 5 | $self->{tpl_vars}{$okey} = $src->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 5 | $self->{__S}{$okey_ks} = $src->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | # Inline block processing with pre-classified types — no substr/regex per iteration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | 11 | for my $b (@blocks) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 32 | my $type = $b->[2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 32 | ▶ | if ($type == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 15 | $ret .= $b->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | } elsif ($type == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | 17 | my $var = $b->[3]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | 17 | my $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 17 | ▶ | if (index($var, '.') < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | 17 | $val = $self->{tpl_vars}{$var}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | 0 | $val = $self->array_dive($var, $self->{tpl_vars}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | 17 | ▶ | if (ref $val eq 'ARRAY') { $ret .= 'ARRAY' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | 0 | elsif (ref $val eq 'HASH') { $ret .= 'HASH' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | 17 | ▶ | elsif (defined $val) { $ret .= ($self->{auto_escape} ? escape($val) : $val) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | } elsif ($type == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | 0 | $self->{char_pos} = $b->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | 0 | $ret .= $self->_if_block($b->[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | } elsif ($type == -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 0 | $ret .= $self->_process_block($b->[0], $b->[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | 11 | $idx++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | # Restore only the keys we modified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | 39 | for my $i (0 .. $#tpl_keys) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | 52 | ▶ | if ($tpl_exists[$i]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | 23 | $self->{tpl_vars}{$tpl_keys[$i]} = $tpl_vals[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 29 | delete $self->{tpl_vars}{$tpl_keys[$i]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | 52 | ▶ | if ($ks_exists[$i]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | 23 | $self->{__S}{$ks_keys[$i]} = $ks_vals[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 29 | delete $self->{__S}{$ks_keys[$i]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | 39 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | 9 | ▶ | sub _include_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_include_block: called CC=8 SCAR=21.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | 9 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | 9 | my $save = $self->{tpl_vars}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | 9 | my $inc_tpl = $self->_extract_include_file($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | 9 | ▶ | if ($self->{perl_file_dir}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | 9 | $inc_tpl = $self->{perl_file_dir} . "/$inc_tpl"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | 9 | ▶ | while ($str =~ m/(\w+)=(['"](.+?)['"])/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | 9 | my $key = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | 9 | my $val = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | 9 | ▶ | if ($key eq 'file') { next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | 1 | $val = $self->_convert_vars($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | 1 | my ($res) = $self->_peval($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | 1 | ▶ | if (defined $res) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | 1 | $self->assign($key => $res); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | 0 | $self->assign($key => $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | 9 | ▶ | if (!-f $inc_tpl || !-r $inc_tpl) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-f $inc_tpl and -r $inc_tpl
MC/DC0%0/2
-f $inc_tpl and -r $inc_tpl
-f $inc_tpl
-r $inc_tpl
Truth table33%1/3
A and B
A= -f $inc_tplB= -r $inc_tpl
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | 0 | $self->{inc_tpl_file} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | 0 | my ($line, $col, $file) = $self->_get_char_location($self->{char_pos}, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | 0 | $self->_error_out("Unable to load include template <code>$inc_tpl</code> in <code>$file</code> on line #$line", 18485); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | 9 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | 9 | ▶ | open my $fh, '<', $inc_tpl or $self->_error_out("Cannot open <code>$inc_tpl</code>: $!", 63579); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | 9 | my $content = <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | 9 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | 9 | my @blocks = $self->_get_blocks($content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | 9 | my $r = $self->_process_blocks(\@blocks); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | 9 | $self->{tpl_vars} = $save; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | 9 | $self->{inc_tpl_file} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | 9 | return $r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | 21 | ▶ | sub _expression_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_expression_block: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | 21 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | 21 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | 21 | my $inner = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | 21 | ▶ | if ($str !~ /["\d\$\(]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | 5 | my ($line, $col, $file) = $self->_get_char_location($self->{char_pos}, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | 5 | $self->_error_out("Unknown block type <code>$str</code> in <code>$file</code> on line #$line", 73467); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | 16 | my $after = $self->_convert_vars($inner); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | 16 | my ($ret, $err) = $self->_peval($after); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | 16 | my $valid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | 16 | ▶ | 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 ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | 14 | $valid = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | 2 | $valid = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | 16 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | 2 | my ($line, $col, $file) = $self->_get_char_location($self->{char_pos}, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | 2 | $self->_error_out("Unknown tag <code>$str</code> in <code>$file</code> on line #$line", 18933); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | 14 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | # Variable / eval engine | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | 97 | ▶ | sub _convert_vars { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_convert_vars: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | 97 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | 97 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | 97 | ▶ | if (index($str, '$') < 0) { return $str } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | # Check conversion cache — avoids re-running regex substitutions on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | # the same expression (e.g. an {if} condition inside a {foreach} loop) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | 84 | ▶ | if (exists $self->{_convert_cache}{$str}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | 21 | return $self->{_convert_cache}{$str}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | 63 | my $orig = $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | # Step 1: $var.key -> $__S->{sluz_pfx_var}->{key} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | 63 | $str =~ s/(\$\w[\w\.]*)/ $self->_dot_to_bracket_cb($1) /ge; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | # Step 2: $__S->{...}["key"] -> $__S->{...}->{key} (PHP bracket syntax) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | 63 | ▶ | if (index($str, '[') >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | 3 | $str =~ s/(\$__S(?:->\{[^}]+\})+)\[(["'])([^\]]+?)\2\]/$1 . '->{' . $3 . '}'/ge; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | 63 | $self->{_convert_cache}{$orig} = $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | 63 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | 67 | ▶ | sub _dot_to_bracket_cb { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dot_to_bracket_cb: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | 67 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | 67 | my $match = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | 67 | my @parts = split /\./, $match; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | 67 | my $first = shift @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | 67 | my $var = substr($first, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | 67 | my $res = "\$__S->\{$self->{var_prefix}_$var\}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | 67 | for my $p (@parts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | 6 | ▶ | if ($p =~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | 1 | $res .= "->[$p]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | 5 | $res .= "->{$p}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | 67 | return $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | 173 | ▶ | sub _micro_optimize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_micro_optimize: called CC=17 SCAR=28.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | 173 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | 173 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | 173 | ▶ | if ($str =~ /^-?\d+(?:\.\d+)?$/) { return $str } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | 154 | ▶ | if (!length $str) { return undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | 153 | my $first = ord($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | 153 | my $last = ord(substr($str, -1)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | 153 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | 10 | my $tmp = substr($str, 1, length($str) - 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | 10 | ▶ | if (index($tmp, "'") < 0) { return $tmp } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | 143 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | 16 | my $tmp = substr($str, 1, length($str) - 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | 16 | ▶ | if (index($tmp, '$') < 0 && index($tmp, '"') < 0) { return $tmp } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | 130 | ▶ | if ($str =~ /^(!?)\$__S->\{sluz_pfx_(\w+)\}$/ && exists $self->{tpl_vars}{$2}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$str =~ /^(!?)\$__S->\{sluz_pfx_(\w+)\}$/u and exists $self->{"tpl_vars"}{$2}
MC/DC100%2/2
$str =~ /^(!?)\$__S->\{sluz_pfx_(\w+)\}$/u and exists $self->{"tpl_vars"}{$2}
$str =~ /^(!?)\$__S->\{sluz_pfx_(\w+)\}$/u
exists $self->{"tpl_vars"}{$2}
Truth table100%3/3
A and B
A= $str =~ /^(!?)\$__S->\{sluz_pfx_(\w+)\}$/uB= exists $self->{"tpl_vars"}{$2}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | 80 | ▶ | return $1 ? !$self->{tpl_vars}{$2} : $self->{tpl_vars}{$2}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | 50 | ▶ | if ($str =~ /^(!?)(\w+)$/ && exists $self->{tpl_vars}{$2}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$str =~ /^(!?)(\w+)$/u and exists $self->{"tpl_vars"}{$2}
MC/DC50%1/2
$str =~ /^(!?)(\w+)$/u and exists $self->{"tpl_vars"}{$2}
$str =~ /^(!?)(\w+)$/u
exists $self->{"tpl_vars"}{$2}
Truth table66%2/3
A and B
A= $str =~ /^(!?)(\w+)$/uB= exists $self->{"tpl_vars"}{$2}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | 3 | ▶ | return $1 ? !$self->{tpl_vars}{$2} : $self->{tpl_vars}{$2}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | 47 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | 173 | ▶ | sub _peval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_peval: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | 173 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | 173 | ▶ | my $str = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | 173 | ▶ | if (index($str, '===') >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | 0 | $str =~ s/===/==/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | 173 | my $opt = $self->_micro_optimize($str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | 173 | ▶ | if (defined $opt) { return ($opt, 0) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | # Use the persistent $__S hash (maintained by assign/foreach) instead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | # of rebuilding it from tpl_vars on every call | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | 50 | my $__S = $self->{__S}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | # Check verified sub cache — subs that have succeeded at least once. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | # Skip eval/local $SIG overhead (the biggest per-call cost in loops). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | # no warnings in the compiled sub suppresses uninitialized-value warnings. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | 50 | my $vsub = $self->{_verified_sub_cache}{$str}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | 50 | ▶ | if ($vsub) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | 13 | return ($vsub->($__S), 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | # Check compiled sub cache — avoids re-parsing the same expression | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | 37 | my $sub = $self->{_sub_cache}{$str}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | 37 | ▶ | if (!defined $sub) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | # Compile in main:: first (where user functions live), then Template::Sluz | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | 6 | ▶ | $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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | 37 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | 1 | ▶ | $sub = eval "no warnings; sub { my \$__S = \$_[0]; return ($str); }"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | # Cache the result (even undef) so we don't recompile failures | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | 37 | $self->{_sub_cache}{$str} = $sub; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | 37 | my $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | 37 | ▶ | if ($sub) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | 36 | ▶ | local $SIG{__WARN__} = sub {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | 36 | $ret = eval { $sub->($__S) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | 36 | ▶ | unless ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | # Promote to verified cache — skip eval/SIG on future calls | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | 33 | $self->{_verified_sub_cache}{$str} = $sub; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | 33 | delete $self->{_sub_cache}{$str}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | 33 | return ($ret, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | # Cached sub failed (e.g. function not in main::) — evict and fall through | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | 3 | delete $self->{_sub_cache}{$str}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | 4 | ▶ | local $SIG{__WARN__} = sub {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | 4 | ▶ | $ret = eval "no warnings; return ($str);"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | 4 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | 1 | ▶ | $ret = eval "package main; no warnings; return ($str);"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | 4 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | 1 | return (undef, -1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | 3 | return ($ret, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | # Error handling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | # ------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | 11 | ▶ | sub _error_out { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error_out: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | 11 | my $msg = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | 11 | my $err_num = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | 11 | croak "Template::Sluz error #$err_num: $msg"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | 10 | ▶ | sub _get_char_location { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_char_location: called CC=12 SCAR=29.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | 10 | my $pos = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | 10 | ▶ | my $tpl_file = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() // ""
MC/DC100%1/1
shift() // ""
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | 10 | ▶ | if ($self->{inc_tpl_file}) { $tpl_file = $self->{inc_tpl_file} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | # Use display file name and line offset when available (e.g. inline DATA templates) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | 10 | ▶ | my $display_file = exists $self->{tpl_file_display} ? $self->{tpl_file_display} : $tpl_file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | 10 | ▶ | my $line_offset = exists $self->{tpl_line_offset} ? $self->{tpl_line_offset} : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | # Guard: no file context (e.g. parse_string) — skip _get_tpl_content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | # to avoid trying to open the perl_file_dir directory as a template file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | 10 | ▶ | if (!length $tpl_file) { return (-1, -1, $display_file) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | 1 | my $str = $self->_get_tpl_content($tpl_file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | 1 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | 1 | my $line = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | 1 | my $col = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | 1 | ▶ | for (my $i = 0; $i < length $str; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | 4 | $col++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | 4 | ▶ | if (substr($str, $i, 1) eq "\n") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | 0 | $line++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | 0 | $col = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | 4 | ▶ | if ($pos == $i) { return ($line + $line_offset, $col, $display_file) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | 0 | ▶ | if ($pos == length $str) { return ($line + $line_offset, $col, $display_file) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | 0 | return (-1, -1, $display_file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | 9 | ▶ | sub _extract_include_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_include_file: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | 9 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | 9 | ▶ | if ($str =~ /\s(file=)(['"].+?['"])/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | 8 | my $xstr = $self->_convert_vars($2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | 8 | my ($ret) = $self->_peval($xstr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | 8 | $self->{inc_tpl_file} = $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | 8 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | 1 | ▶ | if ($str =~ /\s(['"].+?['"])/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1393 | 1 | my $xstr = $self->_convert_vars($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1394 | 1 | my ($ret) = $self->_peval($xstr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1395 | 1 | $self->{inc_tpl_file} = $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1396 | 1 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1399 | 0 | my ($line, $col, $file) = $self->_get_char_location($self->{char_pos}, $self->{tpl_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1400 | 0 | $self->_error_out("Unable to find a file in include block <code>$str</code> in <code>$file</code> on line #$line", 68493); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1403 | 24 | ▶ | sub _if_rules_from_tokens { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_if_rules_from_tokens: called CC=16 SCAR=27.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1404 | 24 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1405 | 24 | my $toks = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1406 | 24 | my $num = scalar @$toks; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1407 | 24 | my $nested = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1408 | 24 | my @tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1409 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1410 | 24 | my $tif_tag = $self->{_tag_if}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1411 | 24 | my $tifc_tag = $self->{_tag_if_close}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1412 | 24 | my $tif_prefix = $self->{open_delim} . 'if'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1414 | 24 | for my $i (0 .. $num - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1415 | 160 | my $item = $toks->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1416 | 160 | ▶ | if (index($item, $tif_prefix) == 0) { $nested++ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1417 | 160 | ▶ | if ($item eq $tifc_tag) { $nested-- } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1419 | 160 | my $yes = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1420 | 160 | ▶ | if ($nested == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1421 | 116 | ▶ | $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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1422 | 116 | ▶ | $yes = 0 if $item eq $tifc_tag; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1424 | 160 | $tmp[$i] = $yes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1427 | 24 | $tmp[$num - 1] = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1428 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1429 | 24 | my @conds; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1430 | 24 | for my $i (0 .. $num - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1431 | 160 | ▶ | if ($tmp[$i]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1432 | 79 | my $test = $self->is_if_token($toks->[$i]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1433 | 79 | ▶ | if ($i != $num - 1) { push @conds, $test } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1434 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1437 | 24 | my $str = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1438 | 24 | my @payloads; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1439 | 24 | my $first = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1440 | 24 | for my $i (0 .. $num - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1441 | 160 | ▶ | if ($tmp[$i]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1442 | 79 | ▶ | if (!$first) { push @payloads, $str } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1443 | 79 | $first = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1444 | 79 | $str = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1445 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1446 | 81 | $str .= $toks->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1447 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1448 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1450 | 24 | ▶ | if (@conds != @payloads) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1451 | 0 | $self->_error_out("Error parsing if conditions in '$str'", 95320); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1452 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1454 | 24 | my @ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1455 | 24 | push @ret, [$conds[$_], $payloads[$_]] for 0 .. $#conds; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1456 | 24 | for my $rule (@ret) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1457 | 55 | $rule->[1] = $self->ltrim_one($rule->[1], "\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1458 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1459 | 24 | return @ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1460 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1461 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1462 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1463 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1464 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||