Alloy/Parse.pm

filter: Statementstmt 87.9% 513 / 583 Branchbran 82.7% 303 / 366 Conditioncond 71.0% 140 / 197 MC/DCmcdc 54.6% 59 / 108 Subroutinesub 76.7% 56 / 73 Podpod 13.1% 5 / 38 totaltotal 78.8% 1076 / 1365 CC 262 SCAR 41.5
CC
262
Cov
83%
parse_expr
144.4
__ANON__
30.0
__ANON__
30.0
CRAP 63.7
« Alloy.pm ↑ Summary Alloy/Context.pm »
1 package Template::Alloy::Parse;
2  
3 =head1 NAME
4  
5 Template::Alloy::Parse - Common parsing role for creating AST from templates
6  
7 =cut
8  
9 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use Template::Alloy;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use Template::Alloy::Operator qw($QR_OP $QR_OP_ASSIGN $QR_OP_PREFIX
Subroutine BEGIN: called CC=1 SCAR=0.0
14 9 $OP $OP_ASSIGN $OP_PREFIX $OP_POSTFIX);
15  
16 9 our $VERSION = $Template::Alloy::VERSION;
17 9 our @EXPORT_OK = qw(define_directive define_syntax
18 $ALIASES $DIRECTIVES $TAGS $QR_DIRECTIVE $QR_COMMENTS);
19  
20 0 ▶sub new { die "This class is a role for use by packages such as Template::Alloy" }
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
21  
22 ###----------------------------------------------------------------###
23  
24 9 our $TAGS = {
25 asp => ['<%', '%>' ], # ASP
26 default => ['\[%', '%\]' ], # default
27 html => ['<!--', '-->' ], # HTML comments
28 mason => ['<%', '>' ], # HTML::Mason
29 metatext => ['%%', '%%' ], # Text::MetaText
30 php => ['<\?', '\?>' ], # PHP
31 star => ['\[\*', '\*\]' ], # TT alternate
32 template => ['\[%', '%\]' ], # Normal Template Toolkit
33 template1 => ['[\[%]%', '%[%\]]'], # TT1
34 tt2 => ['\[%', '%\]' ], # TT2
35 };
36  
37 our $SYNTAX = {
38 4058 ▶ alloy => sub { shift->parse_tree_tt3(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
39 0 ▶ js => sub { shift->parse_tree_js(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
40 0 ▶ jsr => sub { shift->parse_tree_jsr(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
41 18 ▶ ht => sub { my $self = shift; local $self->{'V2EQUALS'} = 0; local $self->{'EXPR'} = 0; $self->parse_tree_hte(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
42 279 ▶ hte => sub { my $self = shift; local $self->{'V2EQUALS'} = 0; $self->parse_tree_hte(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
43 3 ▶ tt3 => sub { shift->parse_tree_tt3(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
44 6 ▶ tt2 => sub { my $self = shift; local $self->{'V2PIPE'} = 1; $self->parse_tree_tt3(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
45 9 ▶ tt1 => sub { my $self = shift; local $self->{'V2PIPE'} = 1; local $self->{'V1DOLLAR'} = 1; $self->parse_tree_tt3(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
46 106 ▶ tmpl => sub { shift->parse_tree_tmpl(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
47 266 ▶ velocity => sub { shift->parse_tree_velocity(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
48 9 };
49  
50 our $DIRECTIVES = {
51 #name parse_sub play_sub block postdir continue no_interp
52 BLOCK => [\&parse_BLOCK, \&play_BLOCK, 1],
53 0 ▶ BREAK => [sub {}, \&play_control],
Subroutine __ANON__: not called CC=1 SCAR=0.0
54 CALL => [\&parse_CALL, \&play_CALL],
55 CASE => [\&parse_CASE, undef, 0, 0, {SWITCH => 1, CASE => 1}],
56 CATCH => [\&parse_CATCH, undef, 0, 0, {TRY => 1, CATCH => 1}],
57 15 ▶ CLEAR => [sub {}, \&play_CLEAR],
Subroutine __ANON__: called CC=1 SCAR=0.0
58 0 ▶ '#' => [sub {}, sub {}],
Subroutine __ANON__: not called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=0.0
59 4 ▶ COMMENT => [sub {}, sub {}, 1],
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=0.0
60 CONFIG => [\&parse_CONFIG, \&play_CONFIG],
61 DEBUG => [\&parse_DEBUG, \&play_DEBUG],
62 DEFAULT => [\&parse_DEFAULT, \&play_DEFAULT],
63 DUMP => [\&parse_DUMP, \&play_DUMP],
64 32 ▶ ELSE => [sub {}, undef, 0, 0, {IF => 1, ELSIF => 1, UNLESS => 1}],
Subroutine __ANON__: called CC=1 SCAR=0.0
65 ELSIF => [\&parse_IF, undef, 0, 0, {IF => 1, ELSIF => 1, UNLESS => 1}],
66 868 ▶ END => [sub {}, sub {}],
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=0.0
67 EVAL => [\&parse_EVAL, \&play_EVAL],
68 FILTER => [\&parse_FILTER, \&play_FILTER, 1, 1],
69 '|' => [\&parse_FILTER, \&play_FILTER, 1, 1],
70 12 ▶ FINAL => [sub {}, undef, 0, 0, {TRY => 1, CATCH => 1}],
Subroutine __ANON__: called CC=1 SCAR=0.0
71 FOR => [\&parse_FOR, \&play_FOR, 1, 1],
72 FOREACH => [\&parse_FOR, \&play_FOR, 1, 1],
73 GET => [\&parse_GET, \&play_GET],
74 IF => [\&parse_IF, \&play_IF, 1, 1],
75 INCLUDE => [\&parse_INCLUDE, \&play_INCLUDE],
76 INSERT => [\&parse_INSERT, \&play_INSERT],
77 0 ▶ JS => [sub {}, \&play_JS, 1, 0, 0, 1],
Subroutine __ANON__: not called CC=1 SCAR=0.0
78 9 ▶ LAST => [sub {}, \&play_control],
Subroutine __ANON__: called CC=1 SCAR=0.0
79 LOOP => [\&parse_LOOP, \&play_LOOP, 1, 1],
80 MACRO => [\&parse_MACRO, \&play_MACRO],
81 META => [\&parse_META, \&play_META],
82 6 ▶ NEXT => [sub {}, \&play_control],
Subroutine __ANON__: called CC=1 SCAR=0.0
83 18 ▶ PERL => [sub {}, \&play_PERL, 1, 0, 0, 1],
Subroutine __ANON__: called CC=1 SCAR=0.0
84 PROCESS => [\&parse_PROCESS, \&play_PROCESS],
85 3 ▶ RAWPERL => [sub {}, \&play_RAWPERL, 1, 0, 0, 1],
Subroutine __ANON__: called CC=1 SCAR=0.0
86 RETURN => [\&parse_RETURN, \&play_control],
87 SET => [\&parse_SET, \&play_SET],
88 26 ▶ STOP => [sub {}, \&play_control],
Subroutine __ANON__: called CC=1 SCAR=0.0
89 SWITCH => [\&parse_SWITCH, \&play_SWITCH, 1],
90 0 ▶ TAGS => [\&parse_TAGS, sub {}],
Subroutine __ANON__: not called CC=1 SCAR=0.0
91 THROW => [\&parse_THROW, \&play_THROW],
92 9 ▶ TRY => [sub {}, \&play_TRY, 1],
Subroutine __ANON__: called CC=1 SCAR=0.0
93 UNLESS => [\&parse_UNLESS, \&play_UNLESS, 1, 1],
94 USE => [\&parse_USE, \&play_USE],
95 VIEW => [\&parse_VIEW, \&play_VIEW, 1],
96 WHILE => [\&parse_WHILE, \&play_WHILE, 1, 1],
97 WRAPPER => [\&parse_WRAPPER, \&play_WRAPPER, 1, 1],
98 #name parse_sub play_sub block postdir continue no_interp
99 };
100 9 our $ALIASES = {
101 EVALUATE => 'EVAL',
102 };
103  
104  
105 9 our $QR_DIRECTIVE = '( [a-zA-Z]+\b | \| )';
106 9 our $QR_COMMENTS = '(?-s: \# .* \s*)*';
107 9 our $QR_FILENAME = '([a-zA-Z]]:/|/)? [\w\.][\w\-\.]* (?:/[\w\-\.]+)*';
108 9 our $QR_BLOCK = '\w+\b (?: :\w+\b)* )';
109 9 our $QR_NUM = '(?:\d*\.\d+ | \d+) (?: [eE][+-]?\d+ )?';
110 9 our $QR_AQ_SPACE = '(?: \\s+ | \$ | (?=;) )';
111  
112 9 our $_escapes = {n => "\n", r => "\r", t => "\t", '"' => '"', '\\' => '\\', '$' => '$'};
113 9 our $QR_ESCAPES = qr{[nrt\"\$\\]};
114  
115 0 ▶sub define_directive {
Subroutine define_directive: not called CC=1 SCAR=6.9
Pod undocumented
116 0 my ($self, $name, $args) = @_;
117 0 $DIRECTIVES->{$name} = [@{ $args }{qw(parse_sub play_sub is_block is_postop continues no_interp)}];
118 0 return 1;
119 }
120  
121 0 ▶sub define_syntax {
Subroutine define_syntax: not called CC=1 SCAR=6.9
Pod undocumented
122 0 my ($self, $name, $sub) = @_;
123 0 $SYNTAX->{$name} = $sub;
124 0 return 1;
125 }
126  
127 ###----------------------------------------------------------------###
128  
129 4748 ▶sub parse_tree {
Subroutine parse_tree: called CC=3 SCAR=11.0
Pod documented
130 4748 ▶ my $syntax = $_[0]->{'SYNTAX'} || 'alloy';
Condition100%2/2
$_[0]{'SYNTAX'} || 'alloy'
l!l
6934055
MC/DC100%1/1
$_[0]{'SYNTAX'} || 'alloy'
$_[0]{'SYNTAX'}
Truth table100%2/2
A
A= $_[0]{'SYNTAX'}
Aresult
11
00
131 4748 ▶ my $meth = $SYNTAX->{$syntax} || $_[0]->throw('config', "Unknown SYNTAX \"$syntax\"");
Condition66%2/3
$Template::Alloy::Parse::SYNTAX->{$syntax} || $_[0]->throw('config', qq[Unknown SYNTAX "$syntax"])
l!l&&r!l&&!r
474530
MC/DC0%0/2
$Template::Alloy::Parse::SYNTAX->{$syntax} || $_[0]->throw('config', qq[Unknown SYNTAX "$syntax"])
$Template::Alloy::Parse::SYNTAX->{$syntax} $_[0]->throw('config', qq[Unknown SYNTAX "$syntax"])
Truth table33%1/3
A || B
A= $Template::Alloy::Parse::SYNTAX->{$syntax}B= $_[0]->throw('config', qq[Unknown SYNTAX "$syntax"])
ABresult
1X1
011
000
132 4745 return $meth->(@_);
133 }
134  
135 ###----------------------------------------------------------------###
136  
137 15946 ▶sub parse_expr {
Subroutine parse_expr: called CC=129 SCAR=49.7
Pod documented
138 15946 my $self = shift;
139 15946 my $str_ref = shift;
140 15946 ▶ my $ARGS = shift || {};
Condition100%2/2
shift() || {}
l!l
208013866
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
141 15946 ▶ my $is_aq = $ARGS->{'auto_quote'} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ARGS->{'auto_quote'} ? : 1849 14097 15946
142 15946 my $mark = pos $$str_ref;
143  
144 ### allow for custom auto_quoting (such as hash constructors)
145 15946 ▶ if ($is_aq) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_aq) 1849 14097 15946
146 1849 ▶ if ($$str_ref =~ m{ \G \s* $QR_COMMENTS $ARGS->{'auto_quote'} }gcx) {
Branch: 3 branches
BranchTrueFalseTotal
if ($$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $ARGS->{'auto_quote'} /cgx) { } 1191 658 1849
elsif ($$str_ref =~ / \G \$\{ /cgx) { } 12 646 658
elsif ($$str_ref =~ / \G \$ /cgx) { } 43 603 646
147 1191 return $1;
148  
149 ### allow for ${foo.bar} type constructs
150 } elsif ($$str_ref =~ m{ \G \$\{ }gcx) {
151 12 my $var = $self->parse_expr($str_ref);
152 12 ▶ $$str_ref =~ m{ \G \s* $QR_COMMENTS \} }gcxo
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS \} /cgox or $self->throw("parse", "Missing close \"}\" from \"\${\"", undef, pos $$str_ref) 12 0 12
153 || $self->throw('parse', 'Missing close "}" from "${"', undef, pos($$str_ref));
154 12 return $var;
155  
156 ### allow for auto-quoted $foo
157 } elsif ($$str_ref =~ m{ \G \$ }gcx) {
158 43 ▶ return $self->parse_expr($str_ref)
Condition33%1/3
$self->parse_expr($str_ref) || $self->throw('parse', 'Missing variable', undef, pos $$str_ref)
l!l&&r!l&&!r
4300
MC/DC0%0/2
$self->parse_expr($str_ref) || $self->throw('parse', 'Missing variable', undef, pos $$str_ref)
$self->parse_expr($str_ref) $self->throw('parse', 'Missing variable', undef, pos $$str_ref)
Truth table33%1/3
A || B
A= $self->parse_expr($str_ref)B= $self->throw('parse', 'Missing variable', undef, pos $$str_ref)
ABresult
1X1
011
000
159 || $self->throw('parse', "Missing variable", undef, pos($$str_ref));
160 }
161 }
162  
163 14700 $$str_ref =~ m{ \G \s* $QR_COMMENTS }gcxo;
164  
165 ### allow for macro definer
166 14700 ▶ if ($$str_ref =~ m{ \G -> \s* }gcxo) { # longest token would be nice - until then this comes before prefix
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G -> \s* /cgox) 27 14673 14700
167 27 local $self->{'_operator_precedence'} = 0; # reset presedence
168 27 my $args;
169 27 ▶ if ($$str_ref =~ m{ \G \( \s* }gcx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G \( \s* /cgx) 18 9 27
170 18 $args = $self->parse_args($str_ref, {positional_only => 1});
171 18 ▶ $$str_ref =~ m{ \G \) \s* }gcx || $self->throw('parse.missing', "Missing close ')'", undef, pos($$str_ref));
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G \) \s* /cgx or $self->throw("parse.missing", "Missing close ')'", undef, pos $$str_ref) 18 0 18
172 }
173 27 ▶ $$str_ref =~ m{ \G \{ $QR_COMMENTS }gcx || $self->throw('parse.missing', "Missing open '{'", undef, pos($$str_ref));
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G \{ $Template::Alloy::Parse::QR_COMMENTS /cgx or $self->throw("parse.missing", "Missing open '{'", undef, pos $$str_ref) 27 0 27
174 27 local $self->{'END_TAG'} = qr{ \} }x;
175 27 my $tree = $self->parse_tree_tt3($str_ref, 'one_tag_only');
176 27 ▶ return [[undef, '->', $args || [['this',0]], $tree]];
Condition100%2/2
$args || [['this', 0]]
l!l
189
MC/DC100%1/1
$args || [['this', 0]]
$args
Truth table100%2/2
A
A= $args
Aresult
11
00
177 }
178  
179 ### test for leading prefix operators
180 14673 my $has_prefix;
181 14673 ▶ while (! $is_aq && $$str_ref =~ m{ \G ($QR_OP_PREFIX) }gcxo) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_aq and $$str_ref =~ / \G ($Template::Alloy::Parse::QR_OP_PREFIX) /cgox) 98 14673 14771
Condition100%3/3
not $is_aq and $$str_ref =~ / \G ($Template::Alloy::Parse::QR_OP_PREFIX) /cgox
!ll&&!rl&&r
6031407098
MC/DC100%2/2
not $is_aq and $$str_ref =~ / \G ($Template::Alloy::Parse::QR_OP_PREFIX) /cgox
not $is_aq $$str_ref =~ / \G ($Template::Alloy::Parse::QR_OP_PREFIX) /cgox
Truth table100%3/3
not(A) and B
A= not $is_aqB= $$str_ref =~ / \G ($Template::Alloy::Parse::QR_OP_PREFIX) /cgox
ABresult
0X0
100
111
182 98 push @{ $has_prefix }, $1;
183 98 $$str_ref =~ m{ \G \s* $QR_COMMENTS }gcxo;
184 }
185  
186 14673 my @var;
187 my $is_literal;
188 14673 my $is_namespace;
189 14673 my $already_parsed_args;
190  
191 ### allow hex
192 14673 ▶ if ($$str_ref =~ m{ \G 0x ( [a-fA-F0-9]+ ) }gcx) {
Branch: 12 branches
BranchTrueFalseTotal
if ($$str_ref =~ / \G 0x ( [a-fA-F0-9]+ ) /cgx) { } 0 14673 14673
elsif ($$str_ref =~ / \G ( $Template::Alloy::Parse::QR_NUM ) /cgx) { } 2799 11874 14673
elsif (not $is_aq and $$str_ref =~ / \G qw ([^\w\s]) \s* /cgox) { } 18 11856 11874
elsif ($$str_ref =~ / \G (\w+) /cgx) { } 6230 5626 11856
elsif (not $is_aq and $$str_ref =~ m[ \G / ]cgx) { } 47 5579 5626
elsif ($$str_ref =~ / \G \' (.*?) (?<! \\) \' /cgsx) { } 1150 4429 5579
elsif ($$str_ref =~ / \G \" /cgx) { } 678 3751 4429
elsif ($$str_ref =~ / \G \$ (\w+) \b /cgx) { } 302 3449 3751
elsif ($$str_ref =~ / \G \$\{ /cgx) { } 126 3323 3449
elsif (not $is_aq and $$str_ref =~ / \G \[ /cgx) { } 305 3018 3323
elsif (not $is_aq and $$str_ref =~ / \G \{ /cgx) { } 173 2845 3018
elsif (not $is_aq and $$str_ref =~ / \G ([\$\@]?) \( /cgx) { } 228 2617 2845
193 0 ▶ my $number = eval { hex $1 } || 0;
Condition0%0/2
eval { do { hex $1 } } || 0
l!l
00
MC/DC0%0/1
eval { do { hex $1 } } || 0
eval { do { hex $1 } }
Truth table0%0/2
A
A= eval { do { hex $1 } }
Aresult
11
00
194 0 push @var, \ $number;
195 0 $is_literal = 1;
196  
197 ### allow for numbers
198 } elsif ($$str_ref =~ m{ \G ( $QR_NUM ) }gcx) {
199 2799 my $number = 0 + $1;
200 2799 push @var, \ $number;
201 2799 $is_literal = 1;
202  
203 ### allow for quoted array constructor
204 ▶ } elsif (! $is_aq && $$str_ref =~ m{ \G qw ([^\w\s]) \s* }gcxo) {
Condition100%3/3
not $is_aq and $$str_ref =~ / \G qw ([^\w\s]) \s* /cgox
!ll&&!rl&&r
6031125318
MC/DC100%2/2
not $is_aq and $$str_ref =~ / \G qw ([^\w\s]) \s* /cgox
not $is_aq $$str_ref =~ / \G qw ([^\w\s]) \s* /cgox
Truth table100%3/3
not(A) and B
A= not $is_aqB= $$str_ref =~ / \G qw ([^\w\s]) \s* /cgox
ABresult
0X0
100
111
205 18 my $quote = $1;
206 18 $quote =~ y|([{<|)]}>|;
207 18 ▶ $$str_ref =~ m{ \G (.*?) (?<!\\) \Q$quote\E }gcxs
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G (.*?) (?<!\\) \Q$quote\E /cgsx or $self->throw("parse.missing.array_close", qq[Missing close "$quote"], undef, pos $$str_ref) 18 0 18
208 || $self->throw('parse.missing.array_close', "Missing close \"$quote\"", undef, pos($$str_ref));
209 18 my $str = $1;
210 18 $str =~ s{ ^ \s+ }{}x;
211 18 $str =~ s{ \s+ $ }{}x;
212 18 $str =~ s{ \\ \Q$quote\E }{$quote}gx;
213 18 push @var, [undef, '[]', split /\s+/, $str];
214  
215 ### looks like a normal variable start
216 } elsif ($$str_ref =~ m{ \G (\w+) }gcx) {
217 6230 push @var, $1;
218 6230 ▶ $is_namespace = 1 if $self->{'NAMESPACE'} && $self->{'NAMESPACE'}->{$1};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"NAMESPACE"} and $self->{"NAMESPACE"}{$1} 45 6185 6230
Condition100%3/3
$self->{"NAMESPACE"} and $self->{"NAMESPACE"}{$1}
!ll&&!rl&&r
6182345
MC/DC100%2/2
$self->{"NAMESPACE"} and $self->{"NAMESPACE"}{$1}
$self->{"NAMESPACE"} $self->{"NAMESPACE"}{$1}
Truth table100%3/3
A and B
A= $self->{"NAMESPACE"}B= $self->{"NAMESPACE"}{$1}
ABresult
0X0
100
111
219  
220 ### allow for regex constructor
221 ▶ } elsif (! $is_aq && $$str_ref =~ m{ \G / }gcx) {
Condition100%3/3
not $is_aq and $$str_ref =~ m[ \G / ]cgx
!ll&&!rl&&r
504507547
MC/DC100%2/2
not $is_aq and $$str_ref =~ m[ \G / ]cgx
not $is_aq $$str_ref =~ m[ \G / ]cgx
Truth table100%3/3
not(A) and B
A= not $is_aqB= $$str_ref =~ m[ \G / ]cgx
ABresult
0X0
100
111
222 47 ▶ $$str_ref =~ m{ \G (.*?) (?<! \\) / ([msixeg]*) }gcxs
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ m[ \G (.*?) (?<! \\) / ([msixeg]*) ]cgsx or $self->throw("parse", "Unclosed regex tag \"/\"", undef, pos $$str_ref) 39 8 47
223 || $self->throw('parse', 'Unclosed regex tag "/"', undef, pos($$str_ref));
224 39 my ($str, $opts) = ($1, $2);
225 39 ▶ $self->throw('parse', 'e option not allowed on regex', undef, pos($$str_ref)) if $opts =~ /e/;
Branch: 1 branch
BranchTrueFalseTotal
if $opts =~ /e/ 3 36 39
226 36 ▶ $self->throw('parse', 'g option not supported on regex', undef, pos($$str_ref)) if $opts =~ /g/;
Branch: 1 branch
BranchTrueFalseTotal
if $opts =~ /g/ 3 33 36
227 33 $str =~ s|\\n|\n|g;
228 33 $str =~ s|\\t|\t|g;
229 33 $str =~ s|\\r|\r|g;
230 33 $str =~ s|\\\/|\/|g;
231 33 $str =~ s|\\\$|\$|g;
232 33 ▶ $self->throw('parse', "Invalid regex: $@", undef, pos($$str_ref)) if ! eval { "" =~ /$str/; 1 };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { "" =~ /$str/; 1 } } 6 27 33
233 27 push @var, [undef, 'qr', $str, $opts];
234  
235 ### allow for single quoted strings
236 } elsif ($$str_ref =~ m{ \G \' (.*?) (?<! \\) \' }gcxs) {
237 1150 my $str = $1;
238 1150 $str =~ s{ \\\' }{\'}xg;
239 1150 ▶ return $str if $is_aq;
Branch: 1 branch
BranchTrueFalseTotal
if $is_aq 25 1125 1150
240 1125 push @var, \ $str;
241 1125 $is_literal = 1;
242  
243 ### allow for double quoted strings
244 } elsif ($$str_ref =~ m{ \G \" }gcx) {
245 678 my @pieces;
246 678 ▶ while ($$str_ref =~ m{ \G (.*?) ([\"\$\\]) }gcxs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G (.*?) ([\"\$\\]) /cgsx) 808 3 811
247 808 my ($str, $item) = ($1, $2);
248 808 ▶ if (length $str) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $str) 685 123 808
249 685 ▶ if (defined($pieces[-1]) && ! ref($pieces[-1])) { $pieces[-1] .= $str; } else { push @pieces, $str }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pieces[-1] and not ref $pieces[-1]) { } 40 645 685
Condition100%3/3
defined $pieces[-1] and not ref $pieces[-1]
!ll&&!rl&&r
6153040
MC/DC100%2/2
defined $pieces[-1] and not ref $pieces[-1]
defined $pieces[-1] not ref $pieces[-1]
Truth table100%3/3
A and not(B)
A= defined $pieces[-1]B= not ref $pieces[-1]
ABresult
0X0
100
111
250 }
251 808 ▶ if ($item eq '\\') {
Branch: 3 branches
BranchTrueFalseTotal
if ($item eq '\\') { } 21 787 808
elsif ($item eq '"') { } 675 112 787
elsif ($self->{'AUTO_EVAL'}) { } 16 96 112
252 21 ▶ my $chr = ($$str_ref =~ m{ \G ($QR_ESCAPES) }gcxo) ? $_escapes->{$1} : '\\';
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G ($Template::Alloy::Parse::QR_ESCAPES) /cgox ? : 21 0 21
253 0 ▶ if (defined($pieces[-1]) && ! ref($pieces[-1])) { $pieces[-1] .= $chr; } else { push @pieces, $chr }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pieces[-1] and not ref $pieces[-1]) { } 21 0 21
Condition33%1/3
defined $pieces[-1] and not ref $pieces[-1]
!ll&&!rl&&r
0021
MC/DC0%0/2
defined $pieces[-1] and not ref $pieces[-1]
defined $pieces[-1] not ref $pieces[-1]
Truth table33%1/3
A and not(B)
A= defined $pieces[-1]B= not ref $pieces[-1]
ABresult
0X0
100
111
254 21 next;
255 } elsif ($item eq '"') {
256 675 last;
257 } elsif ($self->{'AUTO_EVAL'}) {
258 0 ▶ if (defined($pieces[-1]) && ! ref($pieces[-1])) { $pieces[-1] .= '$'; } else { push @pieces, '$' }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pieces[-1] and not ref $pieces[-1]) { } 16 0 16
Condition33%1/3
defined $pieces[-1] and not ref $pieces[-1]
!ll&&!rl&&r
0016
MC/DC0%0/2
defined $pieces[-1] and not ref $pieces[-1]
defined $pieces[-1] not ref $pieces[-1]
Truth table33%1/3
A and not(B)
A= defined $pieces[-1]B= not ref $pieces[-1]
ABresult
0X0
100
111
259 16 next;
260 }
261  
262 96 my $not = $$str_ref =~ m{ \G ! }gcx;
263 96 my $mark = pos($$str_ref);
264 96 my $ref;
265 96 ▶ if ($$str_ref =~ m{ \G \{ }gcx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G \{ /cgx) { } 42 54 96
266 42 local $self->{'_operator_precedence'} = 0; # allow operators
267 42 $ref = $self->parse_expr($str_ref);
268 42 ▶ $$str_ref =~ m{ \G \s* $QR_COMMENTS \} }gcxo
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS \} /cgox or $self->throw("parse", "Missing close }", undef, pos $$str_ref) 42 0 42
269 || $self->throw('parse', 'Missing close }', undef, pos($$str_ref));
270 } else {
271 54 local $self->{'_operator_precedence'} = 1; # no operators
272 54 ▶ $ref = $self->parse_expr($str_ref)
Condition33%1/3
$self->parse_expr($str_ref) || $self->throw('parse', 'Error while parsing for interpolated string', undef, pos $$str_ref)
l!l&&r!l&&!r
5400
MC/DC0%0/2
$self->parse_expr($str_ref) || $self->throw('parse', 'Error while parsing for interpolated string', undef, pos $$str_ref)
$self->parse_expr($str_ref) $self->throw('parse', 'Error while parsing for interpolated string', undef, pos $$str_ref)
Truth table33%1/3
A || B
A= $self->parse_expr($str_ref)B= $self->throw('parse', 'Error while parsing for interpolated string', undef, pos $$str_ref)
ABresult
1X1
011
000
273 || $self->throw('parse', "Error while parsing for interpolated string", undef, pos($$str_ref));
274 }
275 96 ▶ if (! $not && $self->{'SHOW_UNDEFINED_INTERP'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $not and $self->{"SHOW_UNDEFINED_INTERP"}) 8 88 96
Condition100%3/3
not $not and $self->{"SHOW_UNDEFINED_INTERP"}
!ll&&!rl&&r
4848
MC/DC100%2/2
not $not and $self->{"SHOW_UNDEFINED_INTERP"}
not $not $self->{"SHOW_UNDEFINED_INTERP"}
Truth table100%3/3
not(A) and B
A= not $notB= $self->{"SHOW_UNDEFINED_INTERP"}
ABresult
0X0
100
111
276 8 $ref = [[undef, '//', $ref, '$'.substr($$str_ref, $mark, pos($$str_ref)-$mark)], 0];
277 }
278 96 ▶ push @pieces, $ref if defined $ref;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ref 96 0 96
279 }
280 678 ▶ if (! @pieces) { # [% "" %]
Branch: 4 branches
BranchTrueFalseTotal
if (not @pieces) { } 3 675 678
elsif (@pieces == 1 and ref $pieces[0]) { } 51 624 675
elsif ($self->{'AUTO_EVAL'}) { } 44 580 624
elsif (@pieces == 1) { } 535 45 580
281 3 ▶ return '' if $is_aq;
Branch: 1 branch
BranchTrueFalseTotal
if $is_aq 0 3 3
282 3 push @var, \ '';
283 3 $is_literal = 1;
284 ▶ } elsif (@pieces == 1 && ref $pieces[0]) { # [% "$foo" %] or [% "${ 1 + 2 }" %]
Condition100%3/3
@pieces == 1 and ref $pieces[0]
!ll&&!rl&&r
4557951
MC/DC100%2/2
@pieces == 1 and ref $pieces[0]
@pieces == 1 ref $pieces[0]
Truth table100%3/3
A and B
A= @pieces == 1B= ref $pieces[0]
ABresult
0X0
100
111
285 51 ▶ return $pieces[0] if $is_aq;
Branch: 1 branch
BranchTrueFalseTotal
if $is_aq 12 39 51
286 39 push @var, @{ $pieces[0] };
287 39 $already_parsed_args = 1;
288 } elsif ($self->{'AUTO_EVAL'}) {
289 44 push @var, [undef, '~', @pieces], 0, '|', 'eval', 0;
290 44 ▶ return \@var if $is_aq;
Branch: 1 branch
BranchTrueFalseTotal
if $is_aq 14 30 44
291 30 $already_parsed_args = 1;
292 } elsif (@pieces == 1) { # [% "foo" %]
293 535 ▶ return $pieces[0] if $is_aq;
Branch: 1 branch
BranchTrueFalseTotal
if $is_aq 8 527 535
294 527 push @var, \ $pieces[0];
295 527 $is_literal = 1;
296 } else { # [% "foo $bar baz" %]
297 45 push @var, [undef, '~', @pieces];
298 45 ▶ return [$var[0], 0] if $is_aq;
Branch: 1 branch
BranchTrueFalseTotal
if $is_aq 9 36 45
299 }
300  
301 ### allow for leading $foo type constructs
302 } elsif ($$str_ref =~ m{ \G \$ (\w+) \b }gcx) {
303 302 ▶ if ($self->{'V1DOLLAR'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'V1DOLLAR'}) { } 203 99 302
304 203 push @var, $1;
305 203 ▶ $is_namespace = 1 if $self->{'NAMESPACE'} && $self->{'NAMESPACE'}->{$1};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"NAMESPACE"} and $self->{"NAMESPACE"}{$1} 3 200 203
Condition66%2/3
$self->{"NAMESPACE"} and $self->{"NAMESPACE"}{$1}
!ll&&!rl&&r
20003
MC/DC50%1/2
$self->{"NAMESPACE"} and $self->{"NAMESPACE"}{$1}
$self->{"NAMESPACE"} $self->{"NAMESPACE"}{$1}
Truth table66%2/3
A and B
A= $self->{"NAMESPACE"}B= $self->{"NAMESPACE"}{$1}
ABresult
0X0
100
111
306 } else {
307 99 push @var, [$1, 0];
308 }
309  
310 ### allow for ${foo.bar} type constructs
311 } elsif ($$str_ref =~ m{ \G \$\{ }gcx) {
312 126 push @var, $self->parse_expr($str_ref);
313 126 ▶ $$str_ref =~ m{ \G \s* $QR_COMMENTS \} }gcxo
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS \} /cgox or $self->throw("parse", "Missing close \"}\" from \"\${\"", undef, pos $$str_ref) 126 0 126
314 || $self->throw('parse', 'Missing close "}" from "${"', undef, pos($$str_ref));
315  
316 ### looks like an array constructor
317 ▶ } elsif (! $is_aq && $$str_ref =~ m{ \G \[ }gcx) {
Condition100%3/3
not $is_aq and $$str_ref =~ / \G \[ /cgx
!ll&&!rl&&r
4362582305
MC/DC100%2/2
not $is_aq and $$str_ref =~ / \G \[ /cgx
not $is_aq $$str_ref =~ / \G \[ /cgx
Truth table100%3/3
not(A) and B
A= not $is_aqB= $$str_ref =~ / \G \[ /cgx
ABresult
0X0
100
111
318 305 local $self->{'_operator_precedence'} = 0; # reset presedence
319 305 my $arrayref = [undef, '[]'];
320 305 ▶ while (defined(my $var = $self->parse_expr($str_ref))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $var = $self->parse_expr($str_ref))) 376 302 678
321 376 push @$arrayref, $var;
322 376 $$str_ref =~ m{ \G \s* $QR_COMMENTS , }gcxo;
323 }
324 302 ▶ $$str_ref =~ m{ \G \s* $QR_COMMENTS \] }gcxo
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS \] /cgox or $self->throw("parse.missing.square_bracket", "Missing close ]", undef, pos $$str_ref) 299 3 302
325 || $self->throw('parse.missing.square_bracket', "Missing close \]", undef, pos($$str_ref));
326 299 push @var, $arrayref;
327  
328 ### looks like a hash constructor
329 ▶ } elsif (! $is_aq && $$str_ref =~ m{ \G \{ }gcx) {
Condition100%3/3
not $is_aq and $$str_ref =~ / \G \{ /cgx
!ll&&!rl&&r
4362409173
MC/DC100%2/2
not $is_aq and $$str_ref =~ / \G \{ /cgx
not $is_aq $$str_ref =~ / \G \{ /cgx
Truth table100%3/3
not(A) and B
A= not $is_aqB= $$str_ref =~ / \G \{ /cgx
ABresult
0X0
100
111
330 173 local $self->{'_operator_precedence'} = 0; # reset precedence
331 173 my $hashref = [undef, '{}'];
332 173 ▶ while (defined(my $key = $self->parse_expr($str_ref, {auto_quote => "(\\w+\\b) (?! \\.) \\s* $QR_COMMENTS"}))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $key = $self->parse_expr($str_ref, {"auto_quote", "(\\w+\\b) (?! \\.) \\s* $Template::Alloy::Parse::QR_COMMENTS"}))) 194 173 367
333 194 $$str_ref =~ m{ \G \s* $QR_COMMENTS (?: = >? | [:,]) }gcxo;
334 194 my $val = $self->parse_expr($str_ref);
335 194 push @$hashref, $key, $val;
336 194 $$str_ref =~ m{ \G \s* $QR_COMMENTS , }gcxo;
337 }
338 173 ▶ $$str_ref =~ m{ \G \s* $QR_COMMENTS \} }gcxo
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS \} /cgox or $self->throw("parse.missing.curly_bracket", "Missing close }", undef, pos $$str_ref) 173 0 173
339 || $self->throw('parse.missing.curly_bracket', "Missing close \}", undef, pos($$str_ref));
340 173 push @var, $hashref;
341  
342 ### looks like a paren grouper or a context specifier
343 ▶ } elsif (! $is_aq && $$str_ref =~ m{ \G ([\$\@]?) \( }gcx) {
Condition100%3/3
not $is_aq and $$str_ref =~ / \G ([\$\@]?) \( /cgx
!ll&&!rl&&r
4362181228
MC/DC100%2/2
not $is_aq and $$str_ref =~ / \G ([\$\@]?) \( /cgx
not $is_aq $$str_ref =~ / \G ([\$\@]?) \( /cgx
Truth table100%3/3
not(A) and B
A= not $is_aqB= $$str_ref =~ / \G ([\$\@]?) \( /cgx
ABresult
0X0
100
111
344 228 local $self->{'_operator_precedence'} = 0; # reset precedence
345 228 my $ctx = $1;
346 228 my $var = $self->parse_expr($str_ref, {allow_parened_ops => 1});
347  
348 228 ▶ $$str_ref =~ m{ \G \s* $QR_COMMENTS \) }gcxo
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS \) /cgox or $self->throw("parse.missing.paren", "Missing close ) in group", undef, pos $$str_ref) 228 0 228
349 || $self->throw('parse.missing.paren', "Missing close \) in group", undef, pos($$str_ref));
350  
351 228 ▶ $self->throw('parse', 'Paren group cannot be followed by an open paren', undef, pos($$str_ref))
Branch: 1 branch
BranchTrueFalseTotal
if $$str_ref =~ / \G \( /cgx 3 225 228
352 if $$str_ref =~ m{ \G \( }gcx;
353 225 $already_parsed_args = 1;
354  
355 225 ▶ if (! ref $var) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $var) { } 3 222 225
elsif (not defined $var->[0]) { } 0 222 222
356 3 push @var, \$var, 0;
357 3 $is_literal = 1;
358 } elsif (! defined $var->[0]) {
359 0 push @var, $var, 0;
360 } else {
361 222 push @var, @$var;
362 }
363 225 ▶ if ($ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx) 90 135 225
364 90 my $copy = [@var];
365 90 @var = ([undef, "$ctx()", $copy], 0);
366 }
367  
368 ### nothing to find - return failure
369 } else {
370 2617 ▶ pos($$str_ref) = $mark if $is_aq || $has_prefix;
Branch: 1 branch
BranchTrueFalseTotal
if $is_aq or $has_prefix 436 2181 2617
Condition66%2/3
$is_aq or $has_prefix
l!l&&r!l&&!r
43602181
MC/DC50%1/2
$is_aq or $has_prefix
$is_aq $has_prefix
Truth table66%2/3
A or B
A= $is_aqB= $has_prefix
ABresult
1X1
011
000
371 2617 return;
372 }
373  
374 # auto_quoted thing was too complicated
375 11959 ▶ if ($is_aq) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_aq) 99 11860 11959
376 99 pos($$str_ref) = $mark;
377 99 return;
378 }
379  
380 ### looks for args for the initial
381 11860 ▶ if ($already_parsed_args) {
Branch: 2 branches
BranchTrueFalseTotal
if ($already_parsed_args) { } 294 11566 11860
elsif ($$str_ref =~ / \G \( /cgox) { } 183 11383 11566
382 # do nothing
383 } elsif ($$str_ref =~ m{ \G \( }gcxo) {
384 183 local $self->{'_operator_precedence'} = 0; # reset precedence
385 183 my $args = $self->parse_args($str_ref, {is_parened => 1});
386 183 ▶ $$str_ref =~ m{ \G \s* $QR_COMMENTS \) }gcxo
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS \) /cgox or $self->throw("parse.missing.paren", "Missing close ) in args", undef, pos $$str_ref) 183 0 183
387 || $self->throw('parse.missing.paren', "Missing close \) in args", undef, pos($$str_ref));
388 183 push @var, $args;
389 } else {
390 11383 push @var, 0;
391 }
392  
393 ### allow for nested items
394 11860 ▶ while ($$str_ref =~ m{ \G \s* $QR_COMMENTS ( \.(?!\.) | \|(?!\|) ) }gcx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS ( \.(?!\.) | \|(?!\|) ) /cgx) 2813 11830 14643
395 2813 ▶ if ($1 eq '|' && $self->{'V2PIPE'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq "|" and $self->{"V2PIPE"}) 15 2798 2813
Condition100%3/3
$1 eq "|" and $self->{"V2PIPE"}
!ll&&!rl&&r
264815015
MC/DC100%2/2
$1 eq "|" and $self->{"V2PIPE"}
$1 eq "|" $self->{"V2PIPE"}
Truth table100%3/3
A and B
A= $1 eq "|"B= $self->{"V2PIPE"}
ABresult
0X0
100
111
396 15 pos($$str_ref) -= 1;
397 15 last;
398 }
399  
400 2798 ▶ push(@var, $1) if ! $ARGS->{'no_dots'};
Branch: 1 branch
BranchTrueFalseTotal
unless $ARGS->{"no_dots"} 2792 6 2798
401  
402 2798 $$str_ref =~ m{ \G \s* $QR_COMMENTS }gcxo;
403  
404 ### allow for interpolated variables in the middle - one.$foo.two
405 2798 ▶ if ($$str_ref =~ m{ \G \$ (\w+) \b }gcxo) {
Branch: 3 branches
BranchTrueFalseTotal
if ($$str_ref =~ / \G \$ (\w+) \b /cgox) { } 48 2750 2798
elsif ($$str_ref =~ / \G \$\{ /cgx) { } 27 2723 2750
elsif ($$str_ref =~ / \G (-? \w+) /cgx) { } 2723 0 2723
406 48 ▶ push @var, $self->{'V1DOLLAR'} ? $1 : [$1, 0];
Branch: 1 branch
BranchTrueFalseTotal
$self->{'V1DOLLAR'} ? : 6 42 48
407  
408 ### or one.${foo.bar}.two
409 } elsif ($$str_ref =~ m{ \G \$\{ }gcx) {
410 27 push @var, $self->parse_expr($str_ref);
411 27 ▶ $$str_ref =~ m{ \G \s* $QR_COMMENTS \} }gcxo
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS \} /cgox or $self->throw("parse", "Missing close \"}\" from \"\${\"", undef, pos $$str_ref) 27 0 27
412 || $self->throw('parse', 'Missing close "}" from "${"', undef, pos($$str_ref));
413  
414 ### allow for names (foo.bar or foo.0 or foo.-1)
415 } elsif ($$str_ref =~ m{ \G (-? \w+) }gcx) {
416 2723 push @var, $1;
417  
418 } else {
419 0 $self->throw('parse', "Not sure how to continue parsing", undef, pos($$str_ref));
420 }
421  
422 ### looks for args for the nested item
423 2798 ▶ if ($$str_ref =~ m{ \G \( }gcx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G \( /cgx) { } 563 2235 2798
424 563 local $self->{'_operator_precedence'} = 0; # reset precedence
425 563 my $args = $self->parse_args($str_ref, {is_parened => 1});
426 548 ▶ $$str_ref =~ m{ \G \s* $QR_COMMENTS \) }gcxo
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS \) /cgox or $self->throw("parse.missing.paren", "Missing close ) in args of nested item", undef, pos $$str_ref) 548 0 548
427 || $self->throw('parse.missing.paren', "Missing close \) in args of nested item", undef, pos($$str_ref));
428 548 push @var, $args;
429 } else {
430 2235 push @var, 0;
431 }
432  
433 }
434  
435 ### flatten literals and constants as much as possible
436 11845 my $var;
437 11845 ▶ if ($is_literal) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_literal) { } 4442 7403 11845
elsif ($is_namespace) { } 48 7355 7403
438 4442 $var = ${ $var[0] };
439 4442 ▶ if ($#var != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#var != 1) 114 4328 4442
440 114 $var[0] = [undef, '~', $var];
441 114 $var = \@var;
442 }
443 } elsif ($is_namespace) {
444 48 my $name = $var[0];
445 48 local $self->{'_vars'}->{$name} = $self->{'NAMESPACE'}->{$name};
446 48 $var = $self->play_expr(\@var, {is_namespace_during_compile => 1});
447 } else {
448 7355 $var = \@var;
449 }
450  
451 ### allow for all "operators"
452 11845 ▶ if (! $self->{'_operator_precedence'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_operator_precedence"}) 10482 1363 11845
453 10482 my $tree;
454 my $found;
455 10482 while (1) {
456 11558 my $mark = pos $$str_ref;
457  
458 11558 $$str_ref =~ m{ \G \s* $QR_COMMENTS }gcxo;
459  
460 11558 ▶ if ($self->{'_end_tag'} && $$str_ref =~ m{ \G [+=~-]? $self->{'_end_tag'} }gcx) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'_end_tag'} and $$str_ref =~ / \G [+=~-]? $self->{'_end_tag'} /cgx) { } 5435 6123 11558
elsif (not $$str_ref =~ / \G ($Template::Alloy::Parse::QR_OP) /cgox) { } 3342 2781 6123
Condition100%3/3
$self->{"_end_tag"} and $$str_ref =~ / \G [+=~-]? $self->{"_end_tag"} /cgx
!ll&&!rl&&r
1961045435
MC/DC100%2/2
$self->{"_end_tag"} and $$str_ref =~ / \G [+=~-]? $self->{"_end_tag"} /cgx
$self->{"_end_tag"} $$str_ref =~ / \G [+=~-]? $self->{"_end_tag"} /cgx
Truth table100%3/3
A and B
A= $self->{"_end_tag"}B= $$str_ref =~ / \G [+=~-]? $self->{"_end_tag"} /cgx
ABresult
0X0
100
111
461 5435 pos($$str_ref) = $mark;
462 5435 last;
463 } elsif ($$str_ref !~ m{ \G ($QR_OP) }gcxo) {
464 3342 pos($$str_ref) = $mark;
465 3342 last;
466 }
467 2781 ▶ if ($OP_ASSIGN->{$1} && ! $ARGS->{'allow_parened_ops'}) { # only allow assignment in parens
Branch: 1 branch
BranchTrueFalseTotal
if ($Template::Alloy::Parse::OP_ASSIGN->{$1} and not $ARGS->{"allow_parened_ops"}) 1697 1084 2781
Condition100%3/3
$Template::Alloy::Parse::OP_ASSIGN->{$1} and not $ARGS->{"allow_parened_ops"}
!ll&&!rl&&r
1012721697
MC/DC100%2/2
$Template::Alloy::Parse::OP_ASSIGN->{$1} and not $ARGS->{"allow_parened_ops"}
$Template::Alloy::Parse::OP_ASSIGN->{$1} not $ARGS->{"allow_parened_ops"}
Truth table100%3/3
A and not(B)
A= $Template::Alloy::Parse::OP_ASSIGN->{$1}B= not $ARGS->{"allow_parened_ops"}
ABresult
0X0
100
111
468 1697 pos($$str_ref) = $mark;
469 1697 last;
470 }
471 1084 local $self->{'_operator_precedence'} = 1;
472 1084 my $op = $1;
473 1084 ▶ $op = 'eq' if $op eq '==' && (! defined($self->{'V2EQUALS'}) || $self->{'V2EQUALS'});
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "==" and !defined($self->{"V2EQUALS"}) || $self->{"V2EQUALS"} 18 1066 1084
Condition100%6/6
$op eq "==" and !defined($self->{"V2EQUALS"}) || $self->{"V2EQUALS"}
!ll&&!rl&&r
10481818
not defined $self->{"V2EQUALS"} or $self->{"V2EQUALS"}
l!l&&r!l&&!r
12618
MC/DC100%3/3
$op eq "==" and !defined($self->{"V2EQUALS"}) || $self->{"V2EQUALS"}
$op eq "==" not defined $self->{"V2EQUALS"} $self->{"V2EQUALS"}
Truth table100%4/4
A and not(B) or C
A= $op eq "=="B= not defined $self->{"V2EQUALS"}C= $self->{"V2EQUALS"}
ABCresult
0XX0
1000
11X1
1011
474 1084 ▶ $op = 'ne' if $op eq '!=' && (! defined($self->{'V2EQUALS'}) || $self->{'V2EQUALS'});
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "!=" and !defined($self->{"V2EQUALS"}) || $self->{"V2EQUALS"} 6 1078 1084
Condition100%6/6
$op eq "!=" and !defined($self->{"V2EQUALS"}) || $self->{"V2EQUALS"}
!ll&&!rl&&r
107536
not defined $self->{"V2EQUALS"} or $self->{"V2EQUALS"}
l!l&&r!l&&!r
333
MC/DC100%3/3
$op eq "!=" and !defined($self->{"V2EQUALS"}) || $self->{"V2EQUALS"}
$op eq "!=" not defined $self->{"V2EQUALS"} $self->{"V2EQUALS"}
Truth table100%4/4
A and not(B) or C
A= $op eq "!="B= not defined $self->{"V2EQUALS"}C= $self->{"V2EQUALS"}
ABCresult
0XX0
1000
11X1
1011
475  
476 ### allow for postfix - doesn't check precedence - someday we might change - but not today (only affects post ++ and --)
477 1084 ▶ if ($OP_POSTFIX->{$op}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Template::Alloy::Parse::OP_POSTFIX->{$op}) { } 9 1075 1084
elsif ($has_prefix and $Template::Alloy::Parse::OP->{$op}[1] < $$Template::Alloy::Parse::OP_PREFIX{$has_prefix->[-1]}[1]) { } 9 2132 2141
478 9 $var = [[undef, $op, $var, 1], 0]; # cheat - give a "second value" to postfix ops
479 9 next;
480  
481 ### allow for prefix operator precedence
482 ▶ } elsif ($has_prefix && $OP->{$op}->[1] < $OP_PREFIX->{$has_prefix->[-1]}->[1]) {
Condition66%2/3
$has_prefix and $Template::Alloy::Parse::OP->{$op}[1] < $$Template::Alloy::Parse::OP_PREFIX{$has_prefix->[-1]}[1]
!ll&&!rl&&r
106609
MC/DC50%1/2
$has_prefix and $Template::Alloy::Parse::OP->{$op}[1] < $$Template::Alloy::Parse::OP_PREFIX{$has_prefix->[-1]}[1]
$has_prefix $Template::Alloy::Parse::OP->{$op}[1] < $$Template::Alloy::Parse::OP_PREFIX{$has_prefix->[-1]}[1]
Truth table66%2/3
A and B
A= $has_prefixB= $Template::Alloy::Parse::OP->{$op}[1] < $$Template::Alloy::Parse::OP_PREFIX{$has_prefix->[-1]}[1]
ABresult
0X0
100
111
483 9 ▶ if ($tree) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tree) 0 9 9
484 0 ▶ if ($#$tree == 1) { # only one operator - keep simple things fast
Branch: 1 branch
BranchTrueFalseTotal
if ($tree->$#* == 1) { } 0 0 0
485 0 $var = [[undef, $tree->[0], $var, $tree->[1]], 0];
486 } else {
487 0 unshift @$tree, $var;
488 0 $var = $self->apply_precedence($tree, $found, $str_ref);
489 }
490 0 undef $tree;
491 0 undef $found;
492 }
493 9 $var = [[undef, $has_prefix->[-1], $var ], 0];
494 9 pop @$has_prefix;
495 9 ▶ $has_prefix = undef if ! @$has_prefix;
Branch: 1 branch
BranchTrueFalseTotal
unless @$has_prefix 9 0 9
496 }
497  
498 ### add the operator to the tree
499 1075 my $var2 = $self->parse_expr($str_ref);
500 1073 ▶ $self->throw('parse', 'Missing variable after "'.$op.'"', undef, pos($$str_ref)) if ! defined $var2;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $var2 6 1067 1073
501 1067 ▶ push (@{ $tree ||= [] }, $op, $var2);
Condition100%2/2
$tree ||= []
l!l
210857
MC/DC100%1/1
$tree ||= []
$tree
Truth table100%2/2
A
A= $tree
Aresult
11
00
502 1067 $found->{$OP->{$op}->[1]}->{$op} = 1; # found->{precedence}->{op}
503 }
504  
505 ### if we found operators - tree the nodes by operator precedence
506 10474 ▶ if ($tree) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tree) 855 9619 10474
507 855 ▶ if (@$tree == 2) { # only one operator - keep simple things fast
Branch: 1 branch
BranchTrueFalseTotal
if (@$tree == 2) { } 736 119 855
508 736 ▶ if ($OP->{$tree->[0]}->[0] eq 'assign' && $tree->[0] =~ /(.+)=/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$Template::Alloy::Parse::OP{$tree->[0]}[0] eq 'assign' and $tree->[0] =~ /(.+)=/) { } 30 706 736
Condition100%3/3
$$Template::Alloy::Parse::OP{$tree->[0]}[0] eq "assign" and $tree->[0] =~ /(.+)=/
!ll&&!rl&&r
6792730
MC/DC100%2/2
$$Template::Alloy::Parse::OP{$tree->[0]}[0] eq "assign" and $tree->[0] =~ /(.+)=/
$$Template::Alloy::Parse::OP{$tree->[0]}[0] eq "assign" $tree->[0] =~ /(.+)=/
Truth table100%3/3
A and B
A= $$Template::Alloy::Parse::OP{$tree->[0]}[0] eq "assign"B= $tree->[0] =~ /(.+)=/
ABresult
0X0
100
111
509 30 $var = [[undef, '=', $var, [[undef, $1, $var, $tree->[1]], 0]], 0]; # "a += b" => "a = a + b"
510 } else {
511 706 $var = [[undef, $tree->[0], $var, $tree->[1]], 0];
512 }
513 } else {
514 119 unshift @$tree, $var;
515 119 $var = $self->apply_precedence($tree, $found, $str_ref);
516 }
517 }
518 }
519  
520 ### allow for prefix on non-chained variables
521 11837 ▶ if ($has_prefix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_prefix) 89 11748 11837
522 89 $var = [[undef, $_, $var], 0] for reverse @$has_prefix;
523 }
524  
525 11837 return $var;
526 }
527  
528 ### this is used to put the parsed variables into the correct operations tree
529 146 ▶sub apply_precedence {
Subroutine apply_precedence: called CC=23 SCAR=31.5
Pod undocumented
530 146 my ($self, $tree, $found, $str_ref) = @_;
531  
532 146 my @var;
533 my $trees;
534 ### look at the operators we found in the order we found them
535 146 for my $prec (sort keys %$found) {
536 146 my $ops = $found->{$prec};
537 146 local $found->{$prec};
538 146 delete $found->{$prec};
539  
540 ### split the array on the current operators for this level
541 146 my @ops;
542 my @exprs;
543 146 ▶ for (my $i = 1; $i <= $#$tree; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $tree->$#*) 383 146 529
544 383 ▶ next if ! $ops->{ $tree->[$i] };
Branch: 1 branch
BranchTrueFalseTotal
unless $$ops{$tree->[$i]} 93 290 383
545 290 push @ops, $tree->[$i];
546 290 push @exprs, [splice @$tree, 0, $i, ()];
547 290 shift @$tree;
548 290 $i = -1;
549 }
550 146 ▶ next if ! @exprs; # this iteration didn't have the current operator
Branch: 1 branch
BranchTrueFalseTotal
unless @exprs 0 146 146
551 146 ▶ push @exprs, $tree if scalar @$tree; # add on any remaining items
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$tree 146 0 146
552  
553 ### simplify sub expressions
554 146 for my $node (@exprs) {
555 436 ▶ if (@$node == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@$node == 1) { } 370 66 436
elsif (@$node == 3) { } 39 27 66
556 370 $node = $node->[0]; # single item - its not a tree
557 } elsif (@$node == 3) {
558 39 $node = [[undef, $node->[1], $node->[0], $node->[2]], 0]; # single operator - put it straight on
559 } else {
560 27 $node = $self->apply_precedence($node, $found, $str_ref); # more complicated - recurse
561 }
562 }
563  
564 ### assemble this current level
565  
566 ### some rules:
567 # 1) items at the same precedence level must all be either right or left or ternary associative
568 # 2) ternary items cannot share precedence with anybody else.
569 # 3) there really shouldn't be another operator at the same level as a postfix
570 146 my $type = $OP->{$ops[0]}->[0];
571  
572 146 ▶ if ($type eq 'ternary') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'ternary') { } 72 74 146
elsif ($type eq 'right' or $type eq 'assign') { } 27 47 74
573 72 my $op = $OP->{$ops[0]}->[2]->[0]; # use the first op as what we are using
574  
575 ### return simple ternary
576 72 ▶ if (@exprs == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (@exprs == 3) 57 15 72
577 57 ▶ $self->throw('parse', "Ternary operator mismatch", undef, pos($$str_ref)) if $ops[0] ne $op;
Branch: 1 branch
BranchTrueFalseTotal
if $ops[0] ne $op 0 57 57
578 57 ▶ $self->throw('parse', "Ternary operator mismatch", undef, pos($$str_ref)) if ! $ops[1] || $ops[1] eq $op;
Branch: 1 branch
BranchTrueFalseTotal
if not $ops[1] or $ops[1] eq $op 0 57 57
Condition33%1/3
not $ops[1] or $ops[1] eq $op
l!l&&r!l&&!r
0057
MC/DC0%0/2
not $ops[1] or $ops[1] eq $op
not $ops[1] $ops[1] eq $op
Truth table33%1/3
not(A) or B
A= not $ops[1]B= $ops[1] eq $op
ABresult
1X1
011
000
579 57 return [[undef, $op, @exprs], 0];
580 }
581  
582  
583 ### reorder complex ternary - rare case
584 15 ▶ while ($#ops >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#ops >= 1) 15 15 30
585 ### if we look starting from the back - the first lead ternary op will always be next to its matching op
586 15 ▶ for (my $i = $#ops; $i >= 0; $i --) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 60 15 75
587 60 ▶ next if $OP->{$ops[$i]}->[2]->[1] eq $ops[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $$Template::Alloy::Parse::OP{$ops[$i]}[2][1] eq $ops[$i] 30 30 60
588 30 my ($op, $op2) = splice @ops, $i, 2, (); # remove the pair of operators
589 30 my $node = [[undef, $op, @exprs[$i .. $i + 2]], 0];
590 30 splice @exprs, $i, 3, $node;
591 }
592 }
593 15 return $exprs[0]; # at this point the ternary has been reduced to a single operator
594  
595 ▶ } elsif ($type eq 'right' || $type eq 'assign') {
Condition100%3/3
$type eq "right" or $type eq "assign"
l!l&&r!l&&!r
151247
MC/DC100%2/2
$type eq "right" or $type eq "assign"
$type eq "right" $type eq "assign"
Truth table100%3/3
A or B
A= $type eq "right"B= $type eq "assign"
ABresult
1X1
011
000
596 27 my $val = $exprs[-1];
597 27 for (reverse (0 .. $#exprs - 1)) {
598 39 ▶ if ($type eq 'assign' && $ops[$_ - 1] =~ /(.+)=$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'assign' and $ops[$_ - 1] =~ /(.+)=$/) { } 9 30 39
Condition100%3/3
$type eq "assign" and $ops[$_ - 1] =~ /(.+)=$/
!ll&&!rl&&r
2469
MC/DC100%2/2
$type eq "assign" and $ops[$_ - 1] =~ /(.+)=$/
$type eq "assign" $ops[$_ - 1] =~ /(.+)=$/
Truth table100%3/3
A and B
A= $type eq "assign"B= $ops[$_ - 1] =~ /(.+)=$/
ABresult
0X0
100
111
599 9 $val = [[undef, '=', $exprs[$_], [[undef, $1, $exprs[$_], $val], 0]], 0];
600 } else {
601 30 $val = [[undef, $ops[$_ - 1], $exprs[$_], $val], 0];
602 }
603 }
604 27 return $val;
605  
606 } else {
607 47 my $val = $exprs[0];
608 47 $val = [[undef, $ops[$_ - 1], $val, $exprs[$_]], 0] for (1 .. $#exprs);
609 47 return $val;
610  
611 }
612 }
613  
614 0 $self->throw('parse', "Couldn't apply precedence", undef, pos($$str_ref));
615 }
616  
617 ### look for arguments - both positional and named
618 1873 ▶sub parse_args {
Subroutine parse_args: called CC=27 SCAR=33.7
Pod documented
619 1873 my $self = shift;
620 1873 my $str_ref = shift;
621 1873 ▶ my $ARGS = shift || {};
Condition50%1/2
shift() || {}
l!l
18730
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
622  
623 1873 my @args;
624 my @named;
625 1873 my $name;
626 1873 ▶ my $end = $self->{'_end_tag'} || '(?!)';
Condition100%2/2
$self->{'_end_tag'} || '(?!)'
l!l
185914
MC/DC100%1/1
$self->{'_end_tag'} || '(?!)'
$self->{'_end_tag'}
Truth table100%2/2
A
A= $self->{'_end_tag'}
Aresult
11
00
627 1873 while (1) {
628 4009 my $mark = pos $$str_ref;
629  
630 ### look to see if the next thing is a directive or a closing tag
631 4009 ▶ if (! $ARGS->{'is_parened'}
Branch: 2 branches
BranchTrueFalseTotal
if (not $ARGS->{"is_parened"} || $ARGS->{"require_arg"} and $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE (?: \s+ | (?: \s* $Template::Alloy::Parse::QR_COMMENTS (?: ;|[+=~-]?$end))) /cgox and (pos $$str_ref = $mark) || 1 and $$Template::Alloy::Parse::DIRECTIVES{$self->{"ANYCASE"} ? uc $1 : $1}) 24 3985 4009
$self->{'ANYCASE'} ? : 6 266 272
Condition85%12/14
not $ARGS->{"is_parened"} || $ARGS->{"require_arg"} and $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE (?: \s+ | (?: \s* $Template::Alloy::Parse::QR_COMMENTS (?: ;|[+=~-]?$end))) /cgox and (pos $$str_ref = $mark) || 1 and $$Template::Alloy::Parse::DIRECTIVES{$self->{"ANYCASE"} ? uc $1 : $1}
!ll&&!rl&&r
373724824
not $ARGS->{"is_parened"} || $ARGS->{"require_arg"} and $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE (?: \s+ | (?: \s* $Template::Alloy::Parse::QR_COMMENTS (?: ;|[+=~-]?$end))) /cgox and (pos $$str_ref = $mark) || 1
!ll&&!rl&&r
37370272
not $ARGS->{"is_parened"} || $ARGS->{"require_arg"} and $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE (?: \s+ | (?: \s* $Template::Alloy::Parse::QR_COMMENTS (?: ;|[+=~-]?$end))) /cgox
!ll&&!rl&&r
25531184272
$ARGS->{'is_parened'} || $ARGS->{'require_arg'}
l!l&&r!l&&!r
19995541456
pos $$str_ref = $mark or 1
l!l
2720
MC/DC80%4/5
not $ARGS->{"is_parened"} || $ARGS->{"require_arg"} and $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE (?: \s+ | (?: \s* $Template::Alloy::Parse::QR_COMMENTS (?: ;|[+=~-]?$end))) /cgox and (pos $$str_ref = $mark) || 1 and $$Template::Alloy::Parse::DIRECTIVES{$self->{"ANYCASE"} ? uc $1 : $1}
$ARGS->{'is_parened'} $ARGS->{'require_arg'} $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE (?: \s+ | (?: \s* $Template::Alloy::Parse::QR_COMMENTS (?: ;|[+=~-]?$end))) /cgox pos $$str_ref = $mark $$Template::Alloy::Parse::DIRECTIVES{$self->{"ANYCASE"} ? uc $1 : $1}
Truth table83%5/6
not(A || B) and C and D and E
A= $ARGS->{'is_parened'}B= $ARGS->{'require_arg'}C= $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE (?: \s+ | (?: \s* $Template::Alloy::Parse::QR_COMMENTS (?: ;|[+=~-]?$end))) /cgoxD= pos $$str_ref = $markE= $$Template::Alloy::Parse::DIRECTIVES{$self->{"ANYCASE"} ? uc $1 : $1}
ABCDEresult
1XXXX0
01XXX0
000XX0
0010X0
001100
001111
632 && ! $ARGS->{'require_arg'}
633 && $$str_ref =~ m{ \G \s* $QR_COMMENTS $QR_DIRECTIVE (?: \s+ | (?: \s* $QR_COMMENTS (?: ;|[+=~-]?$end))) }gcxo
634 && ((pos($$str_ref) = $mark) || 1) # always revert
635 && $DIRECTIVES->{$self->{'ANYCASE'} ? uc($1) : $1} # looks like a directive - we are done
636 ) {
637 24 last;
638 }
639 3985 ▶ if ($$str_ref =~ m{ \G [+=~-]? $end }gcx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G [+=~-]? $end /cgx) 601 3384 3985
640 601 pos($$str_ref) = $mark;
641 601 last;
642 }
643  
644 ### find the initial arg
645 3384 my $name;
646 3384 ▶ if ($ARGS->{'allow_bare_filenames'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ARGS->{"allow_bare_filenames"}) 739 2645 3384
647 739 $name = $self->parse_expr($str_ref, {auto_quote => "
648 ($QR_FILENAME # file name
649 | $QR_BLOCK # or block
650 (?= [+=~-]? $end # an end tag
651 | \\s*[+,;] # followed by explicit + , or ;
652 | \\s+ (?! [\\s=]) # or space not before an =
653 ) \\s* $QR_COMMENTS"});
654 # filenames can be separated with a "+" - why a "+" ?
655 739 ▶ if ($$str_ref =~ m{ \G \+ (?! \s* $QR_COMMENTS [+=~-]? $end) }gcxo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G \+ (?! \s* $Template::Alloy::Parse::QR_COMMENTS [+=~-]? $end) /cgox) 6 733 739
656 6 push @args, $name;
657 6 $ARGS->{'require_arg'} = 1;
658 6 next;
659 }
660 }
661 3378 ▶ if (! defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 2836 542 3378
662 2836 $name = $self->parse_expr($str_ref);
663 2821 ▶ if (! defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 1233 1588 2821
664 1233 ▶ if ($ARGS->{'require_arg'} && ! @args && ! $ARGS->{'positional_only'} && ! @named) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ARGS->{'require_arg'} and not @args and not $ARGS->{'positional_only'} and not @named) { } 0 1233 1233
Condition33%3/9
$ARGS->{"require_arg"} and not @args and not $ARGS->{"positional_only"} and not @named
!ll&&!rl&&r
123300
$ARGS->{"require_arg"} and not @args and not $ARGS->{"positional_only"}
!ll&&!rl&&r
123300
$ARGS->{"require_arg"} and not @args
!ll&&!rl&&r
123300
MC/DC0%0/4
$ARGS->{"require_arg"} and not @args and not $ARGS->{"positional_only"} and not @named
$ARGS->{"require_arg"} not @args not $ARGS->{"positional_only"} not @named
Truth table20%1/5
A and not(B) and not(C) and not(D)
A= $ARGS->{"require_arg"}B= not @argsC= not $ARGS->{"positional_only"}D= not @named
ABCDresult
0XXX0
10XX0
110X0
11100
11111
665 0 $self->throw('parse', 'Argument required', undef, pos($$str_ref));
666 } else {
667 1233 last;
668 }
669 }
670 }
671  
672 2130 $$str_ref =~ m{ \G \s* $QR_COMMENTS }gcxo;
673  
674 ### see if it is named or positional
675 2130 ▶ if ($$str_ref =~ m{ \G \s* $QR_COMMENTS = >? }gcxo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS = >? /cgox) { } 403 1727 2130
676 403 ▶ $self->throw('parse', 'Named arguments not allowed', undef, $mark) if $ARGS->{'positional_only'};
Branch: 1 branch
BranchTrueFalseTotal
if $ARGS->{"positional_only"} 0 403 403
677 403 my $val = $self->parse_expr($str_ref);
678 403 ▶ $name = $name->[0] if ref($name) && @$name == 2 && ! $name->[1]; # strip a level of indirection on named arguments
Branch: 1 branch
BranchTrueFalseTotal
if ref $name and @$name == 2 and not $name->[1] 397 6 403
Condition66%4/6
ref $name and @$name == 2 and not $name->[1]
!ll&&!rl&&r
60397
ref $name and @$name == 2
!ll&&!rl&&r
06397
MC/DC33%1/3
ref $name and @$name == 2 and not $name->[1]
ref $name @$name == 2 not $name->[1]
Truth table50%2/4
A and B and not(C)
A= ref $nameB= @$name == 2C= not $name->[1]
ABCresult
0XX0
10X0
1100
1111
679 403 push @named, $name, $val;
680 } else {
681 1727 push @args, $name;
682 }
683  
684 ### look for trailing comma
685 2130 ▶ $ARGS->{'require_arg'} = ($$str_ref =~ m{ \G \s* $QR_COMMENTS , }gcxo) || 0;
Condition100%2/2
$$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS , /cgox || 0
l!l
2331897
MC/DC100%1/1
$$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS , /cgox || 0
$$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS , /cgox
Truth table100%2/2
A
A= $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS , /cgox
Aresult
11
00
686 }
687  
688 ### allow for named arguments to be added at the front (if asked)
689 1858 ▶ if ($ARGS->{'named_at_front'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ARGS->{'named_at_front'}) { } 1050 808 1858
elsif (scalar @named) { } 36 772 808
690 1050 unshift @args, [[undef, '{}', @named], 0];
691 } elsif (scalar @named) { # only add at end - if there are some
692 36 push @args, [[undef, '{}', @named], 0]
693 }
694  
695 1858 return \@args;
696 }
697  
698 ###----------------------------------------------------------------###
699  
700 331 ▶sub parse_BLOCK {
Subroutine parse_BLOCK: called CC=6 SCAR=18.4
Pod undocumented
701 331 my ($self, $str_ref, $node) = @_;
702  
703 331 ▶ my $end = $self->{'_end_tag'} || '(?!)';
Condition50%1/2
$self->{'_end_tag'} || '(?!)'
l!l
3310
MC/DC0%0/1
$self->{'_end_tag'} || '(?!)'
$self->{'_end_tag'}
Truth table50%1/2
A
A= $self->{'_end_tag'}
Aresult
11
00
704 331 my $block_name = $self->parse_expr($str_ref, {auto_quote => "
705 ($QR_FILENAME # file name
706 | $QR_BLOCK # or block
707 (?= [+=~-]? $end # an end tag
708 | \\s*[+,;] # followed by explicit + , or ;
709 | \\s+ (?! [\\s=]) # or space not before an =
710 ) \\s* $QR_COMMENTS"});
711  
712 331 ▶ return '' if ! defined $block_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $block_name 68 263 331
713  
714 263 ▶ my $prepend = join "/", map {$_->[3]} grep {ref($_) && $_->[0] eq 'BLOCK'} @{ $self->{'_state'} || {} };
Condition40%2/5
ref $_ && $_->[0] eq 'BLOCK'
!ll&&!rl&&r
006
$self->{'_state'} || {}
l!l
2630
MC/DC0%0/2
ref $_ && $_->[0] eq 'BLOCK'
ref $_ $_->[0] eq 'BLOCK'
MC/DC0%0/1
$self->{'_state'} || {}
$self->{'_state'}
Truth table33%1/3
A && B
A= ref $_B= $_->[0] eq 'BLOCK'
ABresult
0X0
100
111
Truth table50%1/2
A
A= $self->{'_state'}
Aresult
11
00
715 263 ▶ return $prepend ? "$prepend/$block_name" : $block_name;
Branch: 1 branch
BranchTrueFalseTotal
$prepend ? : 6 257 263
716 }
717  
718 78 ▶sub parse_CALL { $DIRECTIVES->{'GET'}->[0]->(@_) }
Subroutine parse_CALL: called CC=1 SCAR=0.0
Pod undocumented
719  
720 30 ▶sub parse_CASE {
Subroutine parse_CASE: called CC=2 SCAR=6.9
Pod undocumented
721 30 my ($self, $str_ref) = @_;
722 30 ▶ return if $$str_ref =~ m{ \G DEFAULT \s* }gcx;
Branch: 1 branch
BranchTrueFalseTotal
if $$str_ref =~ / \G DEFAULT \s* /cgx 3 27 30
723 27 return $self->parse_expr($str_ref);
724 }
725  
726 121 ▶sub parse_CATCH {
Subroutine parse_CATCH: called CC=1 SCAR=0.0
Pod undocumented
727 121 my ($self, $str_ref) = @_;
728 121 return $self->parse_expr($str_ref, {auto_quote => "(\\w+\\b (?: \\.\\w+\\b)*) $QR_AQ_SPACE \\s* $QR_COMMENTS"});
729 }
730  
731 124 ▶sub parse_CONFIG {
Subroutine parse_CONFIG: called CC=10 SCAR=23.1
Pod undocumented
732 124 my ($self, $str_ref) = @_;
733  
734 124 my %ctime = map {$_ => 1} @Template::Alloy::CONFIG_COMPILETIME;
735 124 my %rtime = map {$_ => 1} @Template::Alloy::CONFIG_RUNTIME;
736  
737 124 my $mark = pos($$str_ref);
738 124 my $config = $self->parse_args($str_ref, {named_at_front => 1, is_parened => 1});
739 124 my $ref = $config->[0]->[0];
740 124 ▶ for (my $i = 2; $i < @$ref; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$ref) 109 121 230
741 109 my $key = $ref->[$i] = uc $ref->[$i];
742 109 my $val = $ref->[$i + 1];
743 109 ▶ if ($ctime{$key}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ctime{$key}) { } 52 57 109
elsif (not $rtime{$key}) { } 3 54 57
744 52 $self->{$key} = $self->play_expr($val);
745 52 ▶ if ($key eq 'INTERPOLATE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "INTERPOLATE") 7 45 52
746 7 ▶ $self->{'_start_tag'} = (! $self->{'INTERPOLATE'}) ? $self->{'START_TAG'} : qr{(?: $self->{'START_TAG'} | (\$))}sx;
Branch: 1 branch
BranchTrueFalseTotal
!$self->{'INTERPOLATE'} ? : 0 7 7
747 }
748 } elsif (! $rtime{$key}) {
749 3 $self->throw('parse', "Unknown CONFIG option \"$key\"", undef, pos($$str_ref));
750 }
751 }
752 121 ▶ for (my $i = 1; $i < @$config; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$config) 15 121 136
753 15 my $key = $config->[$i] = uc $config->[$i]->[0];
754 15 ▶ if ($ctime{$key}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ctime{$key}) { } 12 3 15
elsif (not $rtime{$key}) { } 0 3 3
755 12 ▶ $config->[$i] = "CONFIG $key = ".(defined($self->{$key}) ? $self->{$key} : 'undef');
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{$key} ? : 6 6 12
756 } elsif (! $rtime{$key}) {
757 0 $self->throw('parse', "Unknown CONFIG option \"$key\"", undef, pos($$str_ref));
758 }
759 }
760 121 return $config;
761 }
762  
763 3 ▶sub parse_DEBUG {
Subroutine parse_DEBUG: called CC=4 SCAR=14.3
Pod undocumented
764 3 my ($self, $str_ref) = @_;
765 3 ▶ $$str_ref =~ m{ \G ([Oo][Nn] | [Oo][Ff][Ff] | [Ff][Oo][Rr][Mm][Aa][Tt]) \s* }gcx
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G ([Oo][Nn] | [Oo][Ff][Ff] | [Ff][Oo][Rr][Mm][Aa][Tt]) \s* /cgx or $self->throw("parse", "Unknown DEBUG option", undef, pos $$str_ref) 3 0 3
766 || $self->throw('parse', "Unknown DEBUG option", undef, pos($$str_ref));
767 3 my $ret = [lc($1)];
768 3 ▶ if ($ret->[0] eq 'format') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret->[0] eq "format") 3 0 3
769 3 ▶ $$str_ref =~ m{ \G ([\"\']) (|.*?[^\\]) \1 \s* }gcxs
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G ([\"\']) (|.*?[^\\]) \1 \s* /cgsx or $self->throw("parse", "Missing format string", undef, pos $$str_ref) 3 0 3
770 || $self->throw('parse', "Missing format string", undef, pos($$str_ref));
771 3 $ret->[1] = $2;
772 }
773 3 return $ret;
774 }
775  
776 9 ▶sub parse_DEFAULT { $DIRECTIVES->{'SET'}->[0]->(@_) }
Subroutine parse_DEFAULT: called CC=1 SCAR=0.0
Pod undocumented
777  
778 84 ▶sub parse_DUMP {
Subroutine parse_DUMP: called CC=1 SCAR=0.0
Pod undocumented
779 84 my ($self, $str_ref) = @_;
780 84 return $self->parse_args($str_ref, {named_at_front => 1});
781 }
782  
783 22 ▶sub parse_EVAL {
Subroutine parse_EVAL: called CC=1 SCAR=0.0
Pod undocumented
784 22 my ($self, $str_ref) = @_;
785 22 return $self->parse_args($str_ref, {named_at_front => 1});
786 }
787  
788 72 ▶sub parse_FILTER {
Subroutine parse_FILTER: called CC=3 SCAR=11.0
Pod undocumented
789 72 my ($self, $str_ref) = @_;
790 72 my $name = '';
791 72 ▶ if ($$str_ref =~ m{ \G ([^\W\d]\w*) \s* = \s* }gcx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G ([^\W\d]\w*) \s* = \s* /cgx) 18 54 72
792 18 $name = $1;
793 }
794  
795 72 my $filter = $self->parse_expr($str_ref);
796 72 ▶ $filter = '' if ! defined $filter;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $filter 0 72 72
797  
798 72 return [$name, $filter];
799 }
800  
801 243 ▶sub parse_FOR {
Subroutine parse_FOR: called CC=2 SCAR=6.9
Pod undocumented
802 243 my ($self, $str_ref) = @_;
803 243 my $items = $self->parse_expr($str_ref);
804 243 my $var;
805 243 ▶ if ($$str_ref =~ m{ \G \s* $QR_COMMENTS (= | [Ii][Nn]\b) \s* }gcxo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS (= | [Ii][Nn]\b) \s* /cgox) 174 69 243
806 174 $var = [@$items];
807 174 $items = $self->parse_expr($str_ref);
808 }
809 243 return [$var, $items];
810 }
811  
812 385 ▶sub parse_GET {
Subroutine parse_GET: called CC=6 SCAR=17.9
Pod undocumented
813 385 my ($self, $str_ref) = @_;
814 385 my $ref = $self->parse_expr($str_ref);
815 385 ▶ $self->throw('parse', "Missing variable name", undef, pos($$str_ref)) if ! defined $ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ref 17 368 385
816 368 ▶ if ($self->{'AUTO_FILTER'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"AUTO_FILTER"}) 13 355 368
817 13 ▶ $ref = [[undef, '~', $ref], 0] if ! ref $ref;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ref 3 10 13
818 13 ▶ push @$ref, '|', $self->{'AUTO_FILTER'}, 0 if @$ref < 3 || $ref->[-3] ne '|';
Branch: 1 branch
BranchTrueFalseTotal
if @$ref < 3 or $ref->[-3] ne "|" 8 5 13
Condition66%2/3
@$ref < 3 or $ref->[-3] ne "|"
l!l&&r!l&&!r
805
MC/DC50%1/2
@$ref < 3 or $ref->[-3] ne "|"
@$ref < 3 $ref->[-3] ne "|"
Truth table66%2/3
A or B
A= @$ref < 3B= $ref->[-3] ne "|"
ABresult
1X1
011
000
819 }
820 368 return $ref;
821 }
822  
823 244 ▶sub parse_IF {
Subroutine parse_IF: called CC=1 SCAR=0.0
Pod undocumented
824 244 my ($self, $str_ref) = @_;
825 244 return $self->parse_expr($str_ref);
826 }
827  
828 111 ▶sub parse_INCLUDE { $DIRECTIVES->{'PROCESS'}->[0]->(@_) }
Subroutine parse_INCLUDE: called CC=1 SCAR=0.0
Pod undocumented
829  
830 21 ▶sub parse_INSERT { $DIRECTIVES->{'PROCESS'}->[0]->(@_) }
Subroutine parse_INSERT: called CC=1 SCAR=0.0
Pod undocumented
831  
832 18 ▶sub parse_LOOP {
Subroutine parse_LOOP: called CC=2 SCAR=8.1
Pod undocumented
833 18 my ($self, $str_ref, $node) = @_;
834 18 ▶ return $self->parse_expr($str_ref)
Condition33%1/3
$self->parse_expr($str_ref) || $self->throw('parse', 'Missing variable on LOOP directive', undef, pos $$str_ref)
l!l&&r!l&&!r
1800
MC/DC0%0/2
$self->parse_expr($str_ref) || $self->throw('parse', 'Missing variable on LOOP directive', undef, pos $$str_ref)
$self->parse_expr($str_ref) $self->throw('parse', 'Missing variable on LOOP directive', undef, pos $$str_ref)
Truth table33%1/3
A || B
A= $self->parse_expr($str_ref)B= $self->throw('parse', 'Missing variable on LOOP directive', undef, pos $$str_ref)
ABresult
1X1
011
000
835 || $self->throw('parse', 'Missing variable on LOOP directive', undef, pos($$str_ref));
836 }
837  
838 86 ▶sub parse_MACRO {
Subroutine parse_MACRO: called CC=8 SCAR=21.3
Pod undocumented
839 86 my ($self, $str_ref, $node) = @_;
840  
841 86 my $name = $self->parse_expr($str_ref, {auto_quote => "(\\w+\\b) (?! \\.)"});
842 86 ▶ $self->throw('parse', "Missing macro name", undef, pos($$str_ref)) if ! defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 86 86
843 86 ▶ if (! ref $name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $name) 86 0 86
844 86 $name = [ $name, 0 ];
845 }
846  
847 86 my $args;
848 86 ▶ if ($$str_ref =~ m{ \G \( \s* }gcx) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$str_ref =~ / \G \( \s* /cgx) { } 47 39 86
elsif ($self->{'V1DOLLAR'}) { } 24 15 39
849 47 $args = $self->parse_args($str_ref, {positional_only => 1});
850 47 ▶ $$str_ref =~ m{ \G \) \s* }gcx || $self->throw('parse.missing', "Missing close ')'", undef, pos($$str_ref));
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G \) \s* /cgx or $self->throw("parse.missing", "Missing close ')'", undef, pos $$str_ref) 47 0 47
851 } elsif ($self->{'V1DOLLAR'}) { # allow for Velocity style macro args (no parens - but dollars are fine)
852 24 ▶ while ($$str_ref =~ m{ \G (\s+ \$) }gcx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G (\s+ \$) /cgx) 22 24 46
853 22 my $lead = $1;
854 22 my $arg = $self->parse_expr($str_ref);
855 22 ▶ if (! defined $arg) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $arg) 0 22 22
856 0 pos($$str_ref) -= length($lead);
857 0 last;
858 }
859 22 push @$args, $arg;
860 }
861 }
862  
863 86 $node->[6] = 1; # set a flag to keep parsing
864 86 return [$name, $args];
865 }
866  
867 136 ▶sub parse_META {
Subroutine parse_META: called CC=3 SCAR=12.7
Pod undocumented
868 136 my ($self, $str_ref) = @_;
869 136 my $args = $self->parse_args($str_ref, {named_at_front => 1});
870 136 my $hash;
871 136 ▶ return [%$hash] if ($hash = $self->play_expr($args->[0])) && UNIVERSAL::isa($hash, 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if $hash = $self->play_expr($args->[0]) and UNIVERSAL::isa($hash, "HASH") 136 0 136
Condition33%1/3
$hash = $self->play_expr($args->[0]) and UNIVERSAL::isa($hash, "HASH")
!ll&&!rl&&r
00136
MC/DC0%0/2
$hash = $self->play_expr($args->[0]) and UNIVERSAL::isa($hash, "HASH")
$hash = $self->play_expr($args->[0]) UNIVERSAL::isa($hash, "HASH")
Truth table33%1/3
A and B
A= $hash = $self->play_expr($args->[0])B= UNIVERSAL::isa($hash, "HASH")
ABresult
0X0
100
111
872 0 return undef;
873 }
874  
875 536 ▶sub parse_PROCESS {
Subroutine parse_PROCESS: called CC=1 SCAR=0.0
Pod undocumented
876 536 my ($self, $str_ref) = @_;
877  
878 536 return $self->parse_args($str_ref, {
879 named_at_front => 1,
880 allow_bare_filenames => 1,
881 require_arg => 1,
882 });
883 }
884  
885 15 ▶sub parse_RETURN {
Subroutine parse_RETURN: called CC=1 SCAR=0.0
Pod undocumented
886 15 my ($self, $str_ref) = @_;
887 15 my $ref = $self->parse_expr($str_ref); # optional return value
888 15 return $ref;
889 }
890  
891 1166 ▶sub parse_SET {
Subroutine parse_SET: called CC=20 SCAR=30.6
Pod undocumented
892 1166 my ($self, $str_ref, $node, $initial_op, $initial_var) = @_;
893 1166 my @SET;
894 my $func;
895  
896 1166 ▶ if ($initial_op) {
Branch: 1 branch
BranchTrueFalseTotal
if ($initial_op) 750 416 1166
897 750 ▶ if ($initial_op eq '='
Branch: 2 branches
BranchTrueFalseTotal
if ($initial_op eq '=' and $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgx and (pos $$str_ref -= length $1) || 1 and $$Template::Alloy::Parse::DIRECTIVES{$self->{'ANYCASE'} ? uc $1 : $1}) { } 75 675 750
$self->{'ANYCASE'} ? : 0 126 126
Condition81%9/11
$initial_op eq "=" and $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgx and (pos $$str_ref -= length $1) || 1 and $$Template::Alloy::Parse::DIRECTIVES{$self->{"ANYCASE"} ? uc $1 : $1}
!ll&&!rl&&r
6245175
$initial_op eq "=" and $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgx and (pos $$str_ref -= length $1) || 1
!ll&&!rl&&r
6240126
$initial_op eq "=" and $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgx
!ll&&!rl&&r
33591126
pos $$str_ref -= length $1 or 1
l!l
1260
MC/DC75%3/4
$initial_op eq "=" and $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgx and (pos $$str_ref -= length $1) || 1 and $$Template::Alloy::Parse::DIRECTIVES{$self->{"ANYCASE"} ? uc $1 : $1}
$initial_op eq "=" $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgx pos $$str_ref -= length $1 $$Template::Alloy::Parse::DIRECTIVES{$self->{"ANYCASE"} ? uc $1 : $1}
Truth table80%4/5
A and B and C and D
A= $initial_op eq "="B= $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgxC= pos $$str_ref -= length $1D= $$Template::Alloy::Parse::DIRECTIVES{$self->{"ANYCASE"} ? uc $1 : $1}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
898 && $$str_ref =~ m{ \G \s* $QR_COMMENTS $QR_DIRECTIVE }gcx # find a word
899 && ((pos($$str_ref) -= length($1)) || 1) # always revert
900 && $DIRECTIVES->{$self->{'ANYCASE'} ? uc $1 : $1}) { # make sure its a directive - if so set up capturing
901 75 $node->[6] = 1; # set a flag to keep parsing
902 75 ▶ my $val = $node->[4] ||= []; # setup storage
Condition50%1/2
$node->[4] ||= []
l!l
075
MC/DC0%0/1
$node->[4] ||= []
$node->[4]
Truth table50%1/2
A
A= $node->[4]
Aresult
11
00
903 75 return [[$initial_op, $initial_var, $val]];
904 } else { # get a normal variable
905 675 my $val = $self->parse_expr($str_ref);
906 675 ▶ if ($initial_op =~ /(.+)=$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($initial_op =~ /(.+)=$/) 33 642 675
907 33 $initial_op = '=';
908 33 $val = [[undef, $1, $initial_var, $val], 0];
909 }
910 675 return [[$initial_op, $initial_var, $val]];
911 }
912 }
913  
914 416 while (1) {
915 829 my $set = $self->parse_expr($str_ref);
916 829 ▶ last if ! defined $set;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $set 403 426 829
917  
918 426 ▶ if ($$str_ref =~ m{ \G \s* $QR_COMMENTS ($QR_OP_ASSIGN) >? }gcx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS ($Template::Alloy::Parse::QR_OP_ASSIGN) >? /cgx) { } 399 27 426
919 399 my $op = $1;
920 399 ▶ if ($op eq '='
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '=' and $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgx and (pos $$str_ref -= length $1) || 1 and $$Template::Alloy::Parse::DIRECTIVES{$self->{'ANYCASE'} ? uc $1 : $1}) { } 7 392 399
$self->{'ANYCASE'} ? : 2 11 13
Condition72%8/11
$op eq "=" and $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgx and (pos $$str_ref -= length $1) || 1 and $$Template::Alloy::Parse::DIRECTIVES{$self->{"ANYCASE"} ? uc $1 : $1}
!ll&&!rl&&r
38667
$op eq "=" and $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgx and (pos $$str_ref -= length $1) || 1
!ll&&!rl&&r
386013
$op eq "=" and $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgx
!ll&&!rl&&r
038613
pos $$str_ref -= length $1 or 1
l!l
130
MC/DC50%2/4
$op eq "=" and $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgx and (pos $$str_ref -= length $1) || 1 and $$Template::Alloy::Parse::DIRECTIVES{$self->{"ANYCASE"} ? uc $1 : $1}
$op eq "=" $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgx pos $$str_ref -= length $1 $$Template::Alloy::Parse::DIRECTIVES{$self->{"ANYCASE"} ? uc $1 : $1}
Truth table60%3/5
A and B and C and D
A= $op eq "="B= $$str_ref =~ / \G \s* $Template::Alloy::Parse::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgxC= pos $$str_ref -= length $1D= $$Template::Alloy::Parse::DIRECTIVES{$self->{"ANYCASE"} ? uc $1 : $1}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
921 && $$str_ref =~ m{ \G \s* $QR_COMMENTS $QR_DIRECTIVE }gcx # find a word
922 && ((pos($$str_ref) -= length($1)) || 1) # always revert
923 && $DIRECTIVES->{$self->{'ANYCASE'} ? uc $1 : $1}) { # make sure its a directive - if so set up capturing
924 7 $node->[6] = 1; # set a flag to keep parsing
925 7 ▶ my $val = $node->[4] ||= []; # setup storage
Condition50%1/2
$node->[4] ||= []
l!l
07
MC/DC0%0/1
$node->[4] ||= []
$node->[4]
Truth table50%1/2
A
A= $node->[4]
Aresult
11
00
926 7 ▶ if ($op =~ /(.+)=$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op =~ /(.+)=$/) 0 7 7
927 0 $op = '=';
928 0 $val = [[undef, $1, $set, $val], 0];
929 }
930 7 push @SET, [$op, $set, $val];
931 7 last;
932 } else { # get a normal variable
933 392 push @SET, [$op, $set, $self->parse_expr($str_ref)];
934 }
935 } else {
936 27 push @SET, ['=', $set, undef];
937 }
938 }
939  
940 410 return \@SET;
941 }
942  
943 30 ▶sub parse_SWITCH { $DIRECTIVES->{'GET'}->[0]->(@_) }
Subroutine parse_SWITCH: called CC=1 SCAR=0.0
Pod undocumented
944  
945 78 ▶sub parse_TAGS {
Subroutine parse_TAGS: called CC=9 SCAR=22.7
Pod undocumented
946 78 my ($self, $str_ref, $node) = @_;
947  
948 78 my ($start, $end);
949 78 ▶ if ($$str_ref =~ m{ \G (\w+) }gcxs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G (\w+) /cgsx) { } 57 21 78
950 57 ▶ my $ref = $TAGS->{lc $1} || $self->throw('parse', "Invalid TAGS name \"$1\"", undef, pos($$str_ref));
Condition33%1/3
$$Template::Alloy::Parse::TAGS{lc $1} || $self->throw('parse', qq[Invalid TAGS name "$1"], undef, pos $$str_ref)
l!l&&r!l&&!r
5700
MC/DC0%0/2
$$Template::Alloy::Parse::TAGS{lc $1} || $self->throw('parse', qq[Invalid TAGS name "$1"], undef, pos $$str_ref)
$$Template::Alloy::Parse::TAGS{lc $1} $self->throw('parse', qq[Invalid TAGS name "$1"], undef, pos $$str_ref)
Truth table33%1/3
A || B
A= $$Template::Alloy::Parse::TAGS{lc $1}B= $self->throw('parse', qq[Invalid TAGS name "$1"], undef, pos $$str_ref)
ABresult
1X1
011
000
951 57 ($start, $end) = @$ref;
952  
953 } else {
954 21 local $self->{'_operator_precedence'} = 1; # prevent operator matching
955 21 ▶ $start = $$str_ref =~ m{ \G (?= \s* $QR_COMMENTS [\'\"\/]) }gcx
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ m[ \G (?= \s* $Template::Alloy::Parse::QR_COMMENTS [\'\"\/]) ]cgx ? : 12 9 21
Condition33%1/3
$self->parse_expr($str_ref, {"auto_quote", "(\\S+) \\s+ $Template::Alloy::Parse::QR_COMMENTS"}) or $self->throw("parse", "Invalid opening tag in TAGS", undef, pos $$str_ref)
l!l&&r!l&&!r
900
MC/DC0%0/2
$self->parse_expr($str_ref, {"auto_quote", "(\\S+) \\s+ $Template::Alloy::Parse::QR_COMMENTS"}) or $self->throw("parse", "Invalid opening tag in TAGS", undef, pos $$str_ref)
$self->parse_expr($str_ref, {"auto_quote", "(\\S+) \\s+ $Template::Alloy::Parse::QR_COMMENTS"}) $self->throw("parse", "Invalid opening tag in TAGS", undef, pos $$str_ref)
Truth table33%1/3
A or B
A= $self->parse_expr($str_ref, {"auto_quote", "(\\S+) \\s+ $Template::Alloy::Parse::QR_COMMENTS"})B= $self->throw("parse", "Invalid opening tag in TAGS", undef, pos $$str_ref)
ABresult
1X1
011
000
956 ? $self->parse_expr($str_ref)
957 : $self->parse_expr($str_ref, {auto_quote => "(\\S+) \\s+ $QR_COMMENTS"})
958 || $self->throw('parse', "Invalid opening tag in TAGS", undef, pos($$str_ref));
959 18 ▶ $end = $$str_ref =~ m{ \G (?= \s* $QR_COMMENTS [\'\"\/]) }gcx
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ m[ \G (?= \s* $Template::Alloy::Parse::QR_COMMENTS [\'\"\/]) ]cgx ? : 9 9 18
Condition33%1/3
$self->parse_expr($str_ref, {"auto_quote", "(\\S+) \\s* $Template::Alloy::Parse::QR_COMMENTS"}) or $self->throw("parse", "Invalid closing tag in TAGS", undef, pos $$str_ref)
l!l&&r!l&&!r
900
MC/DC0%0/2
$self->parse_expr($str_ref, {"auto_quote", "(\\S+) \\s* $Template::Alloy::Parse::QR_COMMENTS"}) or $self->throw("parse", "Invalid closing tag in TAGS", undef, pos $$str_ref)
$self->parse_expr($str_ref, {"auto_quote", "(\\S+) \\s* $Template::Alloy::Parse::QR_COMMENTS"}) $self->throw("parse", "Invalid closing tag in TAGS", undef, pos $$str_ref)
Truth table33%1/3
A or B
A= $self->parse_expr($str_ref, {"auto_quote", "(\\S+) \\s* $Template::Alloy::Parse::QR_COMMENTS"})B= $self->throw("parse", "Invalid closing tag in TAGS", undef, pos $$str_ref)
ABresult
1X1
011
000
960 ? $self->parse_expr($str_ref)
961 : $self->parse_expr($str_ref, {auto_quote => "(\\S+) \\s* $QR_COMMENTS"})
962 || $self->throw('parse', "Invalid closing tag in TAGS", undef, pos($$str_ref));
963 18 for my $tag ($start, $end) {
964 36 $tag = $self->play_expr($tag);
965 36 ▶ $tag = quotemeta($tag) if ! ref $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tag 30 6 36
966 }
967 }
968 75 return [$start, $end];
969 }
970  
971 109 ▶sub parse_THROW {
Subroutine parse_THROW: called CC=2 SCAR=7.0
Pod undocumented
972 109 my ($self, $str_ref, $node) = @_;
973 109 my $name = $self->parse_expr($str_ref, {auto_quote => "(\\w+\\b (?: \\.\\w+\\b)*) $QR_AQ_SPACE \\s* $QR_COMMENTS"});
974 109 ▶ $self->throw('parse.missing', "Missing name in THROW", $node, pos($$str_ref)) if ! $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 109 109
975 109 my $args = $self->parse_args($str_ref, {named_at_front => 1});
976 109 return [$name, $args];
977 }
978  
979 22 ▶sub parse_UNLESS {
Subroutine parse_UNLESS: called CC=1 SCAR=0.0
Pod undocumented
980 22 my $ref = $DIRECTIVES->{'IF'}->[0]->(@_);
981 22 return [[undef, '!', $ref], 0];
982 }
983  
984 39 ▶sub parse_USE {
Subroutine parse_USE: called CC=8 SCAR=21.0
Pod undocumented
985 39 my ($self, $str_ref) = @_;
986  
987 39 my $var;
988 39 my $mark = pos $$str_ref;
989 39 ▶ if (defined(my $_var = $self->parse_expr($str_ref, {auto_quote => "(\\w+\\b) (?! \\.) \\s* $QR_COMMENTS"}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $_var = $self->parse_expr($str_ref, {"auto_quote", "(\\w+\\b) (?! \\.) \\s* $Template::Alloy::Parse::QR_COMMENTS"})) and $$str_ref =~ / \G = >? \s* $Template::Alloy::Parse::QR_COMMENTS /cgox || (pos $$str_ref = $mark) && 0) 3 36 39
Condition75%6/8
defined(my $_var = $self->parse_expr($str_ref, {"auto_quote", "(\\w+\\b) (?! \\.) \\s* $Template::Alloy::Parse::QR_COMMENTS"})) and $$str_ref =~ / \G = >? \s* $Template::Alloy::Parse::QR_COMMENTS /cgox || (pos $$str_ref = $mark) && 0
!ll&&!rl&&r
3333
$$str_ref =~ / \G = >? \s* $Template::Alloy::Parse::QR_COMMENTS /cgox or pos $$str_ref = $mark and 0
l!l&&r!l&&!r
3033
pos $$str_ref = $mark and 0
!ll
033
MC/DC33%1/3
defined(my $_var = $self->parse_expr($str_ref, {"auto_quote", "(\\w+\\b) (?! \\.) \\s* $Template::Alloy::Parse::QR_COMMENTS"})) and $$str_ref =~ / \G = >? \s* $Template::Alloy::Parse::QR_COMMENTS /cgox || (pos $$str_ref = $mark) && 0
defined(my $_var = $self->parse_expr($str_ref, {"auto_quote", "(\\w+\\b) (?! \\.) \\s* $Template::Alloy::Parse::QR_COMMENTS"})) $$str_ref =~ / \G = >? \s* $Template::Alloy::Parse::QR_COMMENTS /cgox pos $$str_ref = $mark
Truth table75%3/4
A and B or C
A= defined(my $_var = $self->parse_expr($str_ref, {"auto_quote", "(\\w+\\b) (?! \\.) \\s* $Template::Alloy::Parse::QR_COMMENTS"}))B= $$str_ref =~ / \G = >? \s* $Template::Alloy::Parse::QR_COMMENTS /cgoxC= pos $$str_ref = $mark
ABCresult
0XX0
1000
11X1
1011
990 && ($$str_ref =~ m{ \G = >? \s* $QR_COMMENTS }gcxo # make sure there is assignment
991 || ((pos($$str_ref) = $mark) && 0)) # otherwise we need to rollback
992 ) {
993 3 $var = $_var;
994 }
995  
996 39 my $module = $self->parse_expr($str_ref, {auto_quote => "(\\w+\\b (?: (?:\\.|::) \\w+\\b)*) (?! \\.) \\s* $QR_COMMENTS"});
997 39 ▶ $self->throw('parse', "Missing plugin name while parsing $$str_ref", undef, pos($$str_ref)) if ! defined $module;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $module 0 39 39
998 39 $module =~ s/\./::/g;
999  
1000 39 my $args;
1001 39 my $open = $$str_ref =~ m{ \G \( \s* $QR_COMMENTS }gcxo;
1002 39 $args = $self->parse_args($str_ref, {is_parened => $open, named_at_front => 1});
1003  
1004 39 ▶ if ($open) {
Branch: 1 branch
BranchTrueFalseTotal
if ($open) 24 15 39
1005 24 ▶ $$str_ref =~ m{ \G \) \s* $QR_COMMENTS }gcxo || $self->throw('parse.missing', "Missing close ')'", undef, pos($$str_ref));
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G \) \s* $Template::Alloy::Parse::QR_COMMENTS /cgox or $self->throw("parse.missing", "Missing close ')'", undef, pos $$str_ref) 24 0 24
1006 }
1007  
1008 39 return [$var, $module, $args];
1009 }
1010  
1011 0 ▶sub parse_VIEW {
Subroutine parse_VIEW: not called CC=1 SCAR=6.9
Pod undocumented
1012 0 my ($self, $str_ref) = @_;
1013  
1014 0 my $ref = $self->parse_args($str_ref, {
1015 named_at_front => 1,
1016 require_arg => 1,
1017 });
1018  
1019 0 return $ref;
1020 }
1021  
1022 42 ▶sub parse_WHILE { $DIRECTIVES->{'IF'}->[0]->(@_) }
Subroutine parse_WHILE: called CC=1 SCAR=0.0
Pod undocumented
1023  
1024 30 ▶sub parse_WRAPPER { $DIRECTIVES->{'PROCESS'}->[0]->(@_) }
Subroutine parse_WRAPPER: called CC=1 SCAR=0.0
Pod undocumented
1025  
1026 ###----------------------------------------------------------------###
1027  
1028 0 ▶sub dump_parse_tree {
Subroutine dump_parse_tree: not called CC=3 SCAR=24.8
Pod documented
1029 0 my $self = shift;
1030 0 ▶ $self = $self->new if ! ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
1031 0 my $str = shift;
1032 0 ▶ my $ref = ref($str) ? $str : \$str;
Branch: 1 branch
BranchTrueFalseTotal
ref $str ? : 0 0 0
1033 0 my $sub;
1034 my $nest;
1035 0 ▶ $sub = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
1036 0 my ($tree, $indent) = @_;
1037 0 my $out = "[\n";
1038 0 foreach my $node (@$tree) {
1039 0 ▶ if (! ref($node) || (! $node->[4] && ! $node->[5])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $node and $node->[4] || $node->[5]) 0 0 0
Condition0%0/6
ref $node and $node->[4] || $node->[5]
!ll&&!rl&&r
000
$node->[4] or $node->[5]
l!l&&r!l&&!r
000
MC/DC0%0/3
ref $node and $node->[4] || $node->[5]
ref $node $node->[4] $node->[5]
Truth table0%0/4
A and B or C
A= ref $nodeB= $node->[4]C= $node->[5]
ABCresult
0XX0
1000
11X1
1011
1040 0 $out .= "$indent ".$self->ast_string($node).",\n";
1041 0 next;
1042 }
1043 0 $out .= "$indent " . $nest->($node, "$indent ");
1044 }
1045 0 $out .= "$indent]";
1046 0 };
1047 0 ▶ $nest = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
1048 0 my ($node, $indent) = @_;
1049 0 my $out = $self->ast_string([@{$node}[0..3]]);
1050 0 chop $out;
1051 0 ▶ if ($node->[4]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->[4]) 0 0 0
1052 0 $out .= ", ";
1053 0 $out .= $sub->($node->[4], "$indent");
1054 }
1055 0 ▶ if ($node->[5]) {
Branch: 2 branches
BranchTrueFalseTotal
if ($node->[5]) { } 0 0 0
elsif (@$node >= 6) { } 0 0 0
1056 0 $out .= ", ". $nest->($node->[5], "$indent") . $indent;
1057 } elsif (@$node >= 6) {
1058 0 $out .= ", ". $self->ast_string($node->[5]);
1059 }
1060 0 ▶ if (@$node >= 7) { $out.= ", ". $self->ast_string($node->[6]) };
Branch: 1 branch
BranchTrueFalseTotal
if (@$node >= 7) 0 0 0
1061 0 $out .= "],\n";
1062 0 return $out;
1063 0 };
1064  
1065 0 return $sub->($self->parse_tree($ref), '') ."\n";
1066 }
1067  
1068 0 ▶sub dump_parse_expr {
Subroutine dump_parse_expr: not called CC=3 SCAR=24.8
Pod documented
1069 0 my $self = shift;
1070 0 ▶ $self = $self->new if ! ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
1071 0 my $str = shift;
1072 0 ▶ my $ref = ref($str) ? $str : \$str;
Branch: 1 branch
BranchTrueFalseTotal
ref $str ? : 0 0 0
1073 0 return $self->ast_string($self->parse_expr($ref));
1074 }
1075  
1076 ###----------------------------------------------------------------###
1077  
1078 9 1;
1079  
1080 __END__
« Alloy.pm ↑ Summary Alloy/Context.pm »