Alloy/Velocity.pm

filter: Statementstmt 86.9% 180 / 207 Branchbran 70.0% 112 / 160 Conditioncond 65.5% 40 / 61 MC/DCmcdc 47.3% 18 / 38 Subroutinesub 83.3% 5 / 6 Podpod 66.6% 2 / 3 totaltotal 75.1% 357 / 475 CC 103 SCAR 53.7
CC
103
Cov
78%
parse_tree_velocity
226.5
merge
2.0
new
2.0
CRAP 214.0
« Alloy/HTE.pm ↑ Summary Alloy/TT.pm »
1 package Template::Alloy::Velocity;
2  
3 =head1 NAME
4  
5 Template::Alloy::Velocity - Velocity (VTL) role
6  
7 =cut
8  
9 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Template::Alloy;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 our $VERSION = $Template::Alloy::VERSION;
14  
15 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
16  
17 ###----------------------------------------------------------------###
18  
19 266 ▶sub parse_tree_velocity {
Subroutine parse_tree_velocity: called CC=102 SCAR=54.2
Pod documented
20 266 my $self = shift;
21 266 my $str_ref = shift;
22 266 ▶ if (! $str_ref || ! defined $$str_ref) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($str_ref and defined $$str_ref) 0 266 266
Condition33%1/3
$str_ref and defined $$str_ref
!ll&&!rl&&r
00266
MC/DC0%0/2
$str_ref and defined $$str_ref
$str_ref defined $$str_ref
Truth table33%1/3
A and B
A= $str_refB= defined $$str_ref
ABresult
0X0
100
111
23 0 $self->throw('parse.no_string', "No string or undefined during parse", undef, 1);
24 }
25  
26 266 ▶ local $self->{'V2EQUALS'} = $self->{'V2EQUALS'} || 0;
Condition50%1/2
$self->{'V2EQUALS'} || 0
l!l
0266
MC/DC0%0/1
$self->{'V2EQUALS'} || 0
$self->{'V2EQUALS'}
Truth table50%1/2
A
A= $self->{'V2EQUALS'}
Aresult
11
00
27 266 ▶ local $self->{'INTERPOLATE'} = defined($self->{'INTERPOLATE'}) ? $self->{'INTERPOLATE'} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'INTERPOLATE'} ? : 0 266 266
28 266 ▶ local $self->{'V1DOLLAR'} = defined($self->{'V1DOLLAR'}) ? $self->{'V1DOLLAR'} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'V1DOLLAR'} ? : 0 266 266
29 266 ▶ local $self->{'ANYCASE'} = defined($self->{'ANYCASE'}) ? $self->{'ANYCASE'} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'ANYCASE'} ? : 0 266 266
30 266 ▶ local $self->{'AUTO_EVAL'} = defined($self->{'AUTO_EVAL'}) ? $self->{'AUTO_EVAL'} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'AUTO_EVAL'} ? : 12 254 266
31 266 ▶ local $self->{'SHOW_UNDEFINED_INTERP'} = defined($self->{'SHOW_UNDEFINED_INTERP'}) ? $self->{'SHOW_UNDEFINED_INTERP'} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'SHOW_UNDEFINED_INTERP'} ? : 0 266 266
32  
33 266 local $self->{'START_TAG'} = qr{\#};
34 266 ▶ local $self->{'_start_tag'} = (! $self->{'INTERPOLATE'}) ? $self->{'START_TAG'} : qr{(?: $self->{'START_TAG'} | (\$))}sx;
Branch: 1 branch
BranchTrueFalseTotal
!$self->{'INTERPOLATE'} ? : 0 266 266
35 266 local $self->{'_end_tag'}; # changes over time
36  
37 266 local @{ $Template::Alloy::Parse::ALIASES }{qw(PARSE INCLUDE _INCLUDE ELSEIF)}
38 = qw(PROCESS INSERT INCLUDE ELSIF);
39 266 my $dirs = $Template::Alloy::Parse::DIRECTIVES;
40 266 my $aliases = $Template::Alloy::Parse::ALIASES;
41 266 local @{ $dirs }{ keys %$aliases } = values %$aliases; # temporarily add to the table
42 266 local @{ $self }{@Template::Alloy::CONFIG_COMPILETIME} = @{ $self }{@Template::Alloy::CONFIG_COMPILETIME};
43 266 ▶ delete $dirs->{'JS'} if ! $self->{'COMPILE_JS'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"COMPILE_JS"} 266 0 266
44  
45 266 my @tree; # the parsed tree
46 266 my $pointer = \@tree; # pointer to current tree to handle nested blocks
47 266 my @state; # maintain block levels
48 266 local $self->{'_state'} = \@state; # allow for items to introspect (usually BLOCKS)
49 266 local $self->{'_no_interp'} = 0; # no interpolation in perl
50 266 my @in_view; # let us know if we are in a view
51 my @blocks; # storage for defined blocks
52 266 my @meta; # place to store any found meta information (to go into META)
53 266 my $post_chomp = 0; # previous post_chomp setting
54 266 my $continue = 0; # flag for multiple directives in the same tag
55 266 my $post_op = 0; # found a post-operative DIRECTIVE
56 266 my $capture; # flag to start capture
57 my $func;
58 266 my $pre_chomp;
59 266 my $node;
60 266 my $macro_block;
61 266 pos($$str_ref) = 0;
62  
63 266 while (1) {
64 ### allow for #set(foo = PROCESS foo)
65 784 ▶ if ($capture) {
Branch: 1 branch
BranchTrueFalseTotal
if ($capture) { } 28 756 784
66 28 ▶ if ($macro_block) {
Branch: 2 branches
BranchTrueFalseTotal
if ($macro_block) { } 16 12 28
elsif ($$str_ref =~ / \G \s* (\w+)\b /cgx) { } 12 0 12
67 16 $macro_block = 0;
68 16 push @state, $capture;
69 16 ▶ $pointer = $capture->[4] ||= [];
Condition50%1/2
$capture->[4] ||= []
l!l
016
MC/DC0%0/1
$capture->[4] ||= []
$capture->[4]
Truth table50%1/2
A
A= $capture->[4]
Aresult
11
00
70 16 undef $capture;
71 16 next;
72 } elsif ($$str_ref =~ m{ \G \s* (\w+)\b }gcx) {
73 12 ▶ $func = $self->{'ANYCASE'} ? uc($1) : $1;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ANYCASE'} ? : 12 0 12
74 12 ▶ $func = $aliases->{$func} if $aliases->{$func};
Branch: 1 branch
BranchTrueFalseTotal
if $aliases->{$func} 0 12 12
75 $self->throw('parse', "Found unknown DIRECTIVE ($func)", undef, pos($$str_ref) - length($func))
76 12 ▶ if ! $dirs->{$func};
Branch: 1 branch
BranchTrueFalseTotal
unless $dirs->{$func} 0 12 12
77 12 $node = [$func, pos($$str_ref) - length($func), undef];
78 } else {
79 0 $self->throw('parse', "Error looking for block in capture DIRECTIVE", undef, pos($$str_ref));
80 }
81  
82 12 push @{ $capture->[4] }, $node;
83 12 undef $capture;
84  
85 ### handle all other
86 } else {
87 ### find the next opening tag
88 756 ▶ $$str_ref =~ m{ \G (.*?) $self->{'_start_tag'} }gcxs
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G (.*?) $self->{"_start_tag"} /cgsx or last 496 260 756
89 || last;
90 496 my ($text, $dollar) = ($1, $2);
91  
92 ### found a text portion - chomp it and store it
93 496 ▶ if (length $text) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $text) 160 336 496
94 160 ▶ if (! $post_chomp) { }
Branch: 4 branches
BranchTrueFalseTotal
if (not $post_chomp) { } 144 16 160
elsif ($post_chomp == 1) { } 0 16 16
elsif ($post_chomp == 2) { } 16 0 16
elsif ($post_chomp == 3) { } 0 0 0
95 0 elsif ($post_chomp == 1) { $text =~ s{ ^ [^\S\n]* \n }{}x }
96 16 elsif ($post_chomp == 2) { $text =~ s{ ^ \s+ }{ }x }
97 0 elsif ($post_chomp == 3) { $text =~ s{ ^ \s+ }{}x }
98 160 ▶ push @$pointer, $text if length $text;
Branch: 1 branch
BranchTrueFalseTotal
if length $text 160 0 160
99 }
100  
101 ### handle variable interpolation ($2 eq $)
102 496 ▶ if ($dollar) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dollar) 168 328 496
103 ### inspect previous text chunk for escape slashes
104 168 ▶ my $n = ($text =~ m{ (\\+) $ }x) ? length($1) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$text =~ / (\\+) $ /x ? : 12 156 168
105 168 ▶ if ($n && ! $self->{'_no_interp'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n and not $self->{"_no_interp"}) 12 156 168
Condition66%2/3
$n and not $self->{"_no_interp"}
!ll&&!rl&&r
156012
MC/DC50%1/2
$n and not $self->{"_no_interp"}
$n not $self->{"_no_interp"}
Truth table66%2/3
A and not(B)
A= $nB= not $self->{"_no_interp"}
ABresult
0X0
100
111
106 12 my $chop = int(($n + 1) / 2); # were there odd escapes
107 12 ▶ substr($pointer->[-1], -$chop, $chop, '') if defined($pointer->[-1]) && ! ref($pointer->[-1]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $pointer->[-1] and not ref $pointer->[-1] 12 0 12
Condition33%1/3
defined $pointer->[-1] and not ref $pointer->[-1]
!ll&&!rl&&r
0012
MC/DC0%0/2
defined $pointer->[-1] and not ref $pointer->[-1]
defined $pointer->[-1] not ref $pointer->[-1]
Truth table33%1/3
A and not(B)
A= defined $pointer->[-1]B= not ref $pointer->[-1]
ABresult
0X0
100
111
108 }
109 168 ▶ if ($self->{'_no_interp'} || $n % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_no_interp"} or $n % 2) 8 160 168
Condition66%2/3
$self->{"_no_interp"} or $n % 2
l!l&&r!l&&!r
08160
MC/DC50%1/2
$self->{"_no_interp"} or $n % 2
$self->{"_no_interp"} $n % 2
Truth table66%2/3
A or B
A= $self->{"_no_interp"}B= $n % 2
ABresult
1X1
011
000
110 8 push @$pointer, $dollar;
111 8 next;
112 }
113  
114 160 my $not = $$str_ref =~ m{ \G ! }gcx;
115 160 my $mark = pos($$str_ref);
116 160 my $ref;
117 160 ▶ if ($$str_ref =~ m{ \G \{ }gcx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G \{ /cgx) { } 8 152 160
118 8 local $self->{'_operator_precedence'} = 0; # allow operators
119 8 local $self->{'_end_tag'} = qr{\}};
120 8 $ref = $self->parse_expr($str_ref);
121 8 ▶ $$str_ref =~ m{ \G \s* $Template::Alloy::Parse::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) 8 0 8
122 || $self->throw('parse', 'Missing close }', undef, pos($$str_ref));
123 } else {
124 152 local $self->{'_operator_precedence'} = 1; # no operators
125 152 local $Template::Alloy::Parse::QR_COMMENTS = qr{};
126 152 $ref = $self->parse_expr($str_ref);
127 }
128 160 ▶ $self->throw('parse', "Error while parsing for interpolated string", undef, pos($$str_ref))
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ref 0 160 160
129 if ! defined $ref;
130 160 ▶ if (! $not && $self->{'SHOW_UNDEFINED_INTERP'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $not and $self->{"SHOW_UNDEFINED_INTERP"}) 148 12 160
Condition66%2/3
not $not and $self->{"SHOW_UNDEFINED_INTERP"}
!ll&&!rl&&r
120148
MC/DC50%1/2
not $not and $self->{"SHOW_UNDEFINED_INTERP"}
not $not $self->{"SHOW_UNDEFINED_INTERP"}
Truth table66%2/3
not(A) and B
A= not $notB= $self->{"SHOW_UNDEFINED_INTERP"}
ABresult
0X0
100
111
131 148 $ref = [[undef, '//', $ref, '$'.substr($$str_ref, $mark, pos($$str_ref)-$mark)], 0];
132 }
133 160 push @$pointer, ['GET', $mark, pos($$str_ref), $ref];
134 160 $post_chomp = 0; # no chomping after dollar vars
135 160 next;
136 }
137  
138 ### allow for escaped #
139 328 ▶ my $n = ($text =~ m{ (\\+) $ }x) ? length($1) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$text =~ / (\\+) $ /x ? : 0 328 328
140 328 ▶ if ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) 0 328 328
141 0 my $chop = int(($n + 1) / 2); # were there odd escapes
142 0 ▶ substr($pointer->[-1], -$chop, $chop, '') if defined($pointer->[-1]) && ! ref($pointer->[-1]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $pointer->[-1] and not ref $pointer->[-1] 0 0 0
Condition0%0/3
defined $pointer->[-1] and not ref $pointer->[-1]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pointer->[-1] and not ref $pointer->[-1]
defined $pointer->[-1] not ref $pointer->[-1]
Truth table0%0/3
A and not(B)
A= defined $pointer->[-1]B= not ref $pointer->[-1]
ABresult
0X0
100
111
143 0 ▶ if ($n % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n % 2) 0 0 0
144 0 push @$pointer, '#';
145 0 next;
146 }
147 }
148 328 ▶ if ($$str_ref =~ m{ \G \# .*\n? }gcx # single line comment
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G \# .*\n? /cgx or $$str_ref =~ / \G \* .*? \*\# /cgsx) 10 318 328
Condition100%3/3
$$str_ref =~ / \G \# .*\n? /cgx or $$str_ref =~ / \G \* .*? \*\# /cgsx
l!l&&r!l&&!r
64318
MC/DC100%2/2
$$str_ref =~ / \G \# .*\n? /cgx or $$str_ref =~ / \G \* .*? \*\# /cgsx
$$str_ref =~ / \G \# .*\n? /cgx $$str_ref =~ / \G \* .*? \*\# /cgsx
Truth table100%3/3
A or B
A= $$str_ref =~ / \G \# .*\n? /cgxB= $$str_ref =~ / \G \* .*? \*\# /cgsx
ABresult
1X1
011
000
149 || $$str_ref =~ m{ \G \* .*? \*\# }gcxs) { # multi-line comment
150 10 next;
151 }
152  
153 318 ▶ $$str_ref =~ m{ \G (\w+) }gcx
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G (\w+) /cgx or $$str_ref =~ / \G \{ (\w+) (\}) /cgx or $self->throw("parse", "Missing directive name", undef, pos $$str_ref) 316 2 318
Condition100%3/3
$$str_ref =~ / \G (\w+) /cgx or $$str_ref =~ / \G \{ (\w+) (\}) /cgx
l!l&&r!l&&!r
278382
MC/DC100%2/2
$$str_ref =~ / \G (\w+) /cgx or $$str_ref =~ / \G \{ (\w+) (\}) /cgx
$$str_ref =~ / \G (\w+) /cgx $$str_ref =~ / \G \{ (\w+) (\}) /cgx
Truth table100%3/3
A or B
A= $$str_ref =~ / \G (\w+) /cgxB= $$str_ref =~ / \G \{ (\w+) (\}) /cgx
ABresult
1X1
011
000
154 || $$str_ref =~ m{ \G \{ (\w+) (\}) }gcx
155 || $self->throw('parse', 'Missing directive name', undef, pos($$str_ref));
156 316 ▶ $func = $self->{'ANYCASE'} ? uc($1) : $1;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ANYCASE'} ? : 316 0 316
157  
158 ### make sure we know this directive - if we don't then allow fallback to macros (velocity allows them as directives)
159 316 ▶ $func = $aliases->{$func} if $aliases->{$func};
Branch: 1 branch
BranchTrueFalseTotal
if $aliases->{$func} 26 290 316
160 316 ▶ if (! $dirs->{$func}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dirs->{$func}) 12 304 316
161 12 my $name = $1;
162 12 ▶ my $mark = pos($$str_ref) - length($func) - ($2 ? 2 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$2 ? : 0 12 12
163 12 my $args = 0;
164 12 ▶ if ($$str_ref =~ m{ \G \( }gcx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G \( /cgx) 12 0 12
165 12 local $self->{'_operator_precedence'} = 0; # reset precedence
166 12 $args = $self->parse_args($str_ref, {is_parened => 1});
167 12 ▶ $$str_ref =~ m{ \G \s* $Template::Alloy::Parse::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 directive args", undef, pos $$str_ref) 12 0 12
168 || $self->throw('parse.missing.paren', "Missing close \) in directive args", undef, pos($$str_ref));
169 }
170 12 $node = ['GET', $mark, pos($$str_ref), [$name, $args]];
171 12 push @$pointer, $node;
172 12 next;
173 #$self->throw('parse', "Found unknow DIRECTIVE ($func)", undef, pos($$str_ref) - length($func));
174 }
175 304 $node = [$func, pos($$str_ref), undef];
176  
177 304 ▶ if ($$str_ref =~ m{ \G \( ([+=~-]?) }gcx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G \( ([+=~-]?) /cgx) { } 198 106 304
178 198 $self->{'_end_tag'} = qr{\s*([+=~-]?)\)};
179 198 $pre_chomp = $1;
180 } else {
181 106 $self->{'_end_tag'} = '';
182 106 $pre_chomp = '';
183 }
184  
185 ### take care of chomping (this is an extention to velocity
186 304 ▶ $pre_chomp ||= $self->{'PRE_CHOMP'};
Condition100%3/3
$pre_chomp ||= $self->{"PRE_CHOMP"}
l!l&&r!l&&!r
224278
MC/DC100%2/2
$pre_chomp ||= $self->{"PRE_CHOMP"}
$pre_chomp $self->{"PRE_CHOMP"}
Truth table100%3/3
A ||= B
A= $pre_chompB= $self->{"PRE_CHOMP"}
ABresult
1X1
011
000
187 304 ▶ $pre_chomp =~ y/-=~+/1230/ if $pre_chomp;
Branch: 1 branch
BranchTrueFalseTotal
if $pre_chomp 26 278 304
188 304 ▶ if ($pre_chomp && $pointer->[-1] && ! ref $pointer->[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre_chomp and $pointer->[-1] and not ref $pointer->[-1]) 14 290 304
Condition100%6/6
$pre_chomp and $pointer->[-1] and not ref $pointer->[-1]
!ll&&!rl&&r
282814
$pre_chomp and $pointer->[-1]
!ll&&!rl&&r
278422
MC/DC100%3/3
$pre_chomp and $pointer->[-1] and not ref $pointer->[-1]
$pre_chomp $pointer->[-1] not ref $pointer->[-1]
Truth table100%4/4
A and B and not(C)
A= $pre_chompB= $pointer->[-1]C= not ref $pointer->[-1]
ABCresult
0XX0
10X0
1100
1111
189 14 ▶ if ($pre_chomp == 1) { $pointer->[-1] =~ s{ (?:\n|^) [^\S\n]* \z }{}x }
Branch: 3 branches
BranchTrueFalseTotal
if ($pre_chomp == 1) { } 2 12 14
elsif ($pre_chomp == 2) { } 0 12 12
elsif ($pre_chomp == 3) { } 12 0 12
190 0 elsif ($pre_chomp == 2) { $pointer->[-1] =~ s{ (\s+) \z }{ }x }
191 12 elsif ($pre_chomp == 3) { $pointer->[-1] =~ s{ (\s+) \z }{}x }
192 14 ▶ splice(@$pointer, -1, 1, ()) if ! length $pointer->[-1]; # remove the node if it is zero length
Branch: 1 branch
BranchTrueFalseTotal
unless length $pointer->[-1] 14 0 14
193 }
194  
195 304 push @$pointer, $node;
196 }
197  
198 316 $$str_ref =~ m{ \G \s+ }gcx;
199  
200 ### parse remaining tag details
201 316 ▶ if ($func ne 'END') {
Branch: 1 branch
BranchTrueFalseTotal
if ($func ne "END") 236 80 316
202 236 $node->[3] = eval { $dirs->{$func}->[0]->($self, $str_ref, $node) };
203 236 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 2 234 236
204 2 ▶ $err->node($node) if UNIVERSAL::can($err, 'node') && ! $err->node;
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($err, "node") and not $err->node 2 0 2
Condition33%1/3
UNIVERSAL::can($err, "node") and not $err->node
!ll&&!rl&&r
002
MC/DC0%0/2
UNIVERSAL::can($err, "node") and not $err->node
UNIVERSAL::can($err, "node") not $err->node
Truth table33%1/3
A and not(B)
A= UNIVERSAL::can($err, "node")B= not $err->node
ABresult
0X0
100
111
205 2 die $err;
206 }
207 234 $node->[2] = pos $$str_ref;
208 }
209  
210 ### handle ending tags - or continuation blocks
211 314 ▶ if ($func eq 'END' || $dirs->{$func}->[4]) {
Branch: 3 branches
BranchTrueFalseTotal
if ($func eq 'END' or $dirs->{$func}[4]) { } 96 218 314
elsif ($dirs->{$func}[2]) { } 64 154 218
elsif ($func eq 'META') { } 0 154 154
Condition100%3/3
$func eq "END" or $dirs->{$func}[4]
l!l&&r!l&&!r
8016218
MC/DC100%2/2
$func eq "END" or $dirs->{$func}[4]
$func eq "END" $dirs->{$func}[4]
Truth table100%3/3
A or B
A= $func eq "END"B= $dirs->{$func}[4]
ABresult
1X1
011
000
212 96 ▶ if (! @state) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@state) 0 96 96
213 0 print Data::Dumper::Dumper(\@tree);
214 0 $self->throw('parse', "Found an $func tag while not in a block", $node, pos($$str_ref));
215 }
216 96 my $parent_node = pop @state;
217  
218 ### handle continuation blocks such as elsif, else, catch etc
219 96 ▶ if ($dirs->{$func}->[4]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirs->{$func}[4]) 16 80 96
220 16 pop @$pointer; # we will store the node in the parent instead
221 16 $parent_node->[5] = $node;
222 16 my $parent_type = $parent_node->[0];
223 16 ▶ if (! $dirs->{$func}->[4]->{$parent_type}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dirs->{$func}[4]{$parent_type}) 0 16 16
224 0 $self->throw('parse', "Found unmatched nested block", $node, pos($$str_ref));
225 }
226 }
227  
228 ### restore the pointer up one level (because we hit the end of a block)
229 96 ▶ $pointer = (! @state) ? \@tree : $state[-1]->[4];
Branch: 1 branch
BranchTrueFalseTotal
!@state ? : 90 6 96
230  
231 ### normal end block
232 96 ▶ if (! $dirs->{$func}->[4]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $dirs->{$func}[4]) { } 80 16 96
233 80 ▶ if ($parent_node->[0] eq 'BLOCK') { # move BLOCKS to front
Branch: 3 branches
BranchTrueFalseTotal
if ($parent_node->[0] eq 'BLOCK') { } 14 66 80
elsif ($parent_node->[0] eq 'VIEW') { } 0 66 66
elsif ($$dirs{$parent_node->[0]}[5]) { } 0 66 66
234 14 ▶ if (defined($parent_node->[3]) && @in_view) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent_node->[3] and @in_view) { } 0 14 14
Condition33%1/3
defined $parent_node->[3] and @in_view
!ll&&!rl&&r
0140
MC/DC0%0/2
defined $parent_node->[3] and @in_view
defined $parent_node->[3] @in_view
Truth table33%1/3
A and B
A= defined $parent_node->[3]B= @in_view
ABresult
0X0
100
111
235 0 push @{ $in_view[-1] }, $parent_node;
236 } else {
237 14 push @blocks, $parent_node;
238 }
239 14 ▶ if ($pointer->[-1] && ! $pointer->[-1]->[6]) { # capturing doesn't remove the var
Branch: 1 branch
BranchTrueFalseTotal
if ($pointer->[-1] and not $pointer->[-1][6]) 4 10 14
Condition66%2/3
$pointer->[-1] and not $pointer->[-1][6]
!ll&&!rl&&r
0104
MC/DC50%1/2
$pointer->[-1] and not $pointer->[-1][6]
$pointer->[-1] not $pointer->[-1][6]
Truth table66%2/3
A and not(B)
A= $pointer->[-1]B= not $pointer->[-1][6]
ABresult
0X0
100
111
240 4 splice(@$pointer, -1, 1, ());
241 }
242 } elsif ($parent_node->[0] eq 'VIEW') {
243 0 my $ref = { map {($_->[3] => $_->[4])} @{ pop @in_view }};
244 0 unshift @{ $parent_node->[3] }, $ref;
245 } elsif ($dirs->{$parent_node->[0]}->[5]) { # allow no_interp to turn on and off
246 0 $self->{'_no_interp'}--;
247 }
248  
249  
250 ### continuation block - such as an elsif
251 } else {
252 16 push @state, $node;
253 16 ▶ $pointer = $node->[4] ||= [];
Condition50%1/2
$node->[4] ||= []
l!l
016
MC/DC0%0/1
$node->[4] ||= []
$node->[4]
Truth table50%1/2
A
A= $node->[4]
Aresult
11
00
254 }
255 96 $node->[2] = pos $$str_ref;
256  
257 ### handle block directives
258 } elsif ($dirs->{$func}->[2]) {
259 64 push @state, $node;
260 64 ▶ $pointer = $node->[4] ||= []; # allow future parsed nodes before END tag to end up in current node
Condition50%1/2
$node->[4] ||= []
l!l
064
MC/DC0%0/1
$node->[4] ||= []
$node->[4]
Truth table50%1/2
A
A= $node->[4]
Aresult
11
00
261 64 ▶ push @in_view, [] if $func eq 'VIEW';
Branch: 1 branch
BranchTrueFalseTotal
if $func eq "VIEW" 0 64 64
262 64 ▶ $self->{'_no_interp'}++ if $dirs->{$node->[0]}->[5] # allow no_interp to turn on and off
Branch: 1 branch
BranchTrueFalseTotal
if $$dirs{$node->[0]}[5] 0 64 64
263  
264 } elsif ($func eq 'META') {
265 0 unshift @meta, @{ $node->[3] }; # first defined win
266 0 $node->[3] = undef; # only let these be defined once - at the front of the tree
267 }
268  
269  
270 ### look for the closing tag
271 314 ▶ if ($$str_ref =~ m{ \G $self->{'_end_tag'} }gcxs) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$str_ref =~ / \G $self->{'_end_tag'} /cgsx) { } 300 14 314
elsif ($node->[6]) { } 12 2 14
272 300 ▶ $post_chomp = $1 || $self->{'POST_CHOMP'};
Condition100%3/3
$1 || $self->{'POST_CHOMP'}
l!l&&r!l&&!r
224274
MC/DC100%2/2
$1 || $self->{'POST_CHOMP'}
$1 $self->{'POST_CHOMP'}
Truth table100%3/3
A || B
A= $1B= $self->{'POST_CHOMP'}
ABresult
1X1
011
000
273 300 ▶ $post_chomp =~ y/-=~+/1230/ if $post_chomp;
Branch: 1 branch
BranchTrueFalseTotal
if $post_chomp 26 274 300
274 300 $continue = 0;
275 300 $post_op = 0;
276  
277 300 ▶ if ($node->[6] && $node->[0] eq 'MACRO') { # allow for MACRO's without a BLOCK
Branch: 1 branch
BranchTrueFalseTotal
if ($node->[6] and $node->[0] eq "MACRO") 16 284 300
Condition66%2/3
$node->[6] and $node->[0] eq "MACRO"
!ll&&!rl&&r
284016
MC/DC50%1/2
$node->[6] and $node->[0] eq "MACRO"
$node->[6] $node->[0] eq "MACRO"
Truth table66%2/3
A and B
A= $node->[6]B= $node->[0] eq "MACRO"
ABresult
0X0
100
111
278 16 $capture = $node;
279 16 $macro_block = 1;
280 }
281 300 next;
282  
283 ### setup capturing
284 } elsif ($node->[6]) {
285 12 $capture = $node;
286 12 next;
287  
288 ### no closing tag
289 } else {
290 2 $self->throw('parse', "Not sure how to handle tag", $node, pos($$str_ref));
291 }
292 }
293  
294 ### cleanup the tree
295 260 ▶ unshift(@tree, @blocks) if @blocks;
Branch: 1 branch
BranchTrueFalseTotal
if @blocks 14 246 260
296 260 ▶ unshift(@tree, ['META', 1, 1, \@meta]) if @meta;
Branch: 1 branch
BranchTrueFalseTotal
if @meta 0 260 260
297 260 ▶ $self->throw('parse', "Missing end tag", $state[-1], pos($$str_ref)) if @state > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @state > 0 0 260 260
298  
299 ### pull off the last text portion - if any
300 260 ▶ if (pos($$str_ref) != length($$str_ref)) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $$str_ref != length $$str_ref) 80 180 260
301 80 my $text = substr $$str_ref, pos($$str_ref);
302 80 ▶ if (! $post_chomp) { }
Branch: 4 branches
BranchTrueFalseTotal
if (not $post_chomp) { } 78 2 80
elsif ($post_chomp == 1) { } 2 0 2
elsif ($post_chomp == 2) { } 0 0 0
elsif ($post_chomp == 3) { } 0 0 0
303 2 elsif ($post_chomp == 1) { $text =~ s{ ^ [^\S\n]* \n }{}x }
304 0 elsif ($post_chomp == 2) { $text =~ s{ ^ \s+ }{ }x }
305 0 elsif ($post_chomp == 3) { $text =~ s{ ^ \s+ }{}x }
306 80 ▶ push @$pointer, $text if length $text;
Branch: 1 branch
BranchTrueFalseTotal
if length $text 78 2 80
307 }
308  
309 260 return \@tree;
310 }
311  
312 200 ▶sub merge {
Subroutine merge: called CC=2 SCAR=7.1
Pod documented
313 200 my ($self, $in, $swap, $out) = @_;
314 200 ▶ local $self->{'SYNTAX'} = $self->{'SYNTAX'} || 'velocity';
Condition50%1/2
$self->{'SYNTAX'} || 'velocity'
l!l
0200
MC/DC0%0/1
$self->{'SYNTAX'} || 'velocity'
$self->{'SYNTAX'}
Truth table50%1/2
A
A= $self->{'SYNTAX'}
Aresult
11
00
315 200 return $self->process_simple($in, $swap, $out);
316 }
317  
318 ###----------------------------------------------------------------###
319  
320 3 1;
321  
322 __END__
« Alloy/HTE.pm ↑ Summary Alloy/TT.pm »