Alloy/TT.pm

filter: Statementstmt 92.3% 326 / 353 Branchbran 82.1% 235 / 286 Conditioncond 74.6% 100 / 134 MC/DCmcdc 55.2% 42 / 76 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 3 totaltotal 82.5% 711 / 861 CC 198 SCAR 47.9
CC
198
Cov
86%
parse_tree_tt3
149.3
process
100.5
_load_template_meta
9.1
CRAP 120.6
« Alloy/Velocity.pm ↑ Summary Alloy.pm »
1 package Template::Alloy::TT;
2  
3 =head1 NAME
4  
5 Template::Alloy::TT - Template::Toolkit role
6  
7 =cut
8  
9 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 7 ▶use Template::Alloy;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use Template::Alloy::Operator qw($QR_OP_ASSIGN);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 7 our $VERSION = $Template::Alloy::VERSION;
15 7 our $QR_COMMENTS;
16 7 ▶use constant posessive => ($^V >= 5.009) || 0; # perl 5.10 allows possessive
Subroutine BEGIN: called CC=2 SCAR=7.1
Condition50%1/2
$^V >= 5.009 || 0
l!l
70
MC/DC0%0/1
$^V >= 5.009 || 0
$^V >= 5.009
Truth table50%1/2
A
A= $^V >= 5.009
Aresult
11
00
17  
18 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
19  
20 ###----------------------------------------------------------------###
21  
22 4209 ▶sub parse_tree_tt3 {
Subroutine parse_tree_tt3: called CC=116 SCAR=50.1
Pod undocumented
23 4209 my $self = shift;
24 4209 my $str_ref = shift;
25 4209 ▶ my $one_tag_only = shift() ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
shift() ? : 27 4182 4209
26 4209 ▶ if (! $str_ref || ! defined $$str_ref) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($str_ref and defined $$str_ref) 0 4209 4209
Condition33%1/3
$str_ref and defined $$str_ref
!ll&&!rl&&r
004209
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
27 0 $self->throw('parse.no_string', "No string or undefined during parse", undef, 1);
28 }
29  
30 4209 ▶ my $STYLE = $self->{'TAG_STYLE'} || 'default';
Condition100%2/2
$self->{'TAG_STYLE'} || 'default'
l!l
1064103
MC/DC100%1/1
$self->{'TAG_STYLE'} || 'default'
$self->{'TAG_STYLE'}
Truth table100%2/2
A
A= $self->{'TAG_STYLE'}
Aresult
11
00
31 4209 ▶ local $self->{'_end_tag'} = $self->{'END_TAG'} || $Template::Alloy::Parse::TAGS->{$STYLE}->[1];
Condition66%2/3
$self->{'END_TAG'} || $Template::Alloy::Parse::TAGS->{$STYLE}[1]
l!l&&r!l&&!r
13340760
MC/DC0%0/2
$self->{'END_TAG'} || $Template::Alloy::Parse::TAGS->{$STYLE}[1]
$self->{'END_TAG'} $Template::Alloy::Parse::TAGS->{$STYLE}[1]
Truth table66%2/3
A || B
A= $self->{'END_TAG'}B= $Template::Alloy::Parse::TAGS->{$STYLE}[1]
ABresult
1X1
011
000
32 4209 ▶ local $self->{'START_TAG'} = $self->{'START_TAG'} || $Template::Alloy::Parse::TAGS->{$STYLE}->[0];
Condition66%2/3
$self->{'START_TAG'} || $Template::Alloy::Parse::TAGS->{$STYLE}[0]
l!l&&r!l&&!r
13340760
MC/DC0%0/2
$self->{'START_TAG'} || $Template::Alloy::Parse::TAGS->{$STYLE}[0]
$self->{'START_TAG'} $Template::Alloy::Parse::TAGS->{$STYLE}[0]
Truth table66%2/3
A || B
A= $self->{'START_TAG'}B= $Template::Alloy::Parse::TAGS->{$STYLE}[0]
ABresult
1X1
011
000
33 4209 ▶ local $self->{'_start_tag'} = (! $self->{'INTERPOLATE'}) ? $self->{'START_TAG'} : qr{(?: $self->{'START_TAG'} | (\$))}sx;
Branch: 1 branch
BranchTrueFalseTotal
!$self->{'INTERPOLATE'} ? : 4132 77 4209
34  
35 4209 ▶ local $QR_COMMENTS = $QR_COMMENTS || (posessive() ? (local $Template::Alloy::Parse::QR_COMMENTS = "(?sm: \\s*+ \\# .*? (?: \$ | (?=$self->{'_end_tag'}) ) )*+ \\s*+") : $Template::Alloy::Parse::QR_COMMENTS);
Condition100%2/2
$Template::Alloy::TT::QR_COMMENTS || (local $Template::Alloy::Parse::QR_COMMENTS = "(?sm: \\s*+ \\# .*? (?: \$ | (?=$self->{'_end_tag'}) ) )*+ \\s*+")
l!l
274182
MC/DC100%1/1
$Template::Alloy::TT::QR_COMMENTS || (local $Template::Alloy::Parse::QR_COMMENTS = "(?sm: \\s*+ \\# .*? (?: \$ | (?=$self->{'_end_tag'}) ) )*+ \\s*+")
$Template::Alloy::TT::QR_COMMENTS
Truth table100%2/2
A
A= $Template::Alloy::TT::QR_COMMENTS
Aresult
11
00
36 4209 my $dirs = $Template::Alloy::Parse::DIRECTIVES;
37 4209 my $aliases = $Template::Alloy::Parse::ALIASES;
38 4209 local @{ $dirs }{ keys %$aliases } = values %$aliases; # temporarily add to the table
39 4209 local @{ $self }{@Template::Alloy::CONFIG_COMPILETIME} = @{ $self }{@Template::Alloy::CONFIG_COMPILETIME};
40 4209 ▶ delete $dirs->{'JS'} if ! $self->{'COMPILE_JS'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"COMPILE_JS"} 4209 0 4209
41  
42 4209 my @tree; # the parsed tree
43 4209 my $pointer = \@tree; # pointer to current tree to handle nested blocks
44 4209 my @state; # maintain block levels
45 4209 local $self->{'_state'} = \@state; # allow for items to introspect (usually BLOCKS)
46 4209 local $self->{'_no_interp'} = 0; # no interpolation in some blocks (usually PERL)
47 4209 my @in_view; # let us know if we are in a view
48 my @blocks; # store blocks for later moving to front
49 4209 my @meta; # place to store any found meta information (to go into META)
50 4209 my $post_chomp = 0; # previous post_chomp setting
51 4209 my $continue = 0; # flag for multiple directives in the same tag
52 4209 my $post_op = 0; # found a post-operative DIRECTIVE
53 4209 my $capture; # flag to start capture
54 my $func;
55 4209 my $node;
56 4209 ▶ pos($$str_ref) = 0 if ! $one_tag_only;
Branch: 1 branch
BranchTrueFalseTotal
unless $one_tag_only 4182 27 4209
57  
58 4209 while (1) {
59 ### continue looking for information in a semi-colon delimited tag
60 13083 ▶ if ($continue) {
Branch: 2 branches
BranchTrueFalseTotal
if ($continue) { } 1742 11341 13083
elsif ($one_tag_only) { } 27 11314 11341
61 1742 $node = [undef, $continue, undef];
62  
63 } elsif ($one_tag_only) {
64 27 $node = [undef, pos($$str_ref), undef];
65  
66 ### find the next opening tag
67 } else {
68 11314 ▶ $$str_ref =~ m{ \G (.*?) $self->{'_start_tag'} }gcxs
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G (.*?) $self->{"_start_tag"} /cgsx or last 7217 4097 11314
69 || last;
70 7217 my ($text, $dollar) = ($1, $2); # dollar is set only on an interpolated var
71  
72 ### found a text portion - chomp it and store it
73 7217 ▶ if (length $text) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $text) 1779 5438 7217
74 1779 ▶ if (! $post_chomp) { }
Branch: 4 branches
BranchTrueFalseTotal
if (not $post_chomp) { } 1677 102 1779
elsif ($post_chomp == 1) { } 12 90 102
elsif ($post_chomp == 2) { } 0 90 90
elsif ($post_chomp == 3) { } 90 0 90
75 12 elsif ($post_chomp == 1) { $text =~ s{ ^ [^\S\n]* \n }{}x }
76 0 elsif ($post_chomp == 2) { $text =~ s{ ^ \s+ }{ }x }
77 90 elsif ($post_chomp == 3) { $text =~ s{ ^ \s+ }{}x }
78 1779 ▶ push @$pointer, $text if length $text;
Branch: 1 branch
BranchTrueFalseTotal
if length $text 1683 96 1779
79 }
80  
81 ### handle variable interpolation ($2 eq $)
82 7217 ▶ if ($dollar) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dollar) 107 7110 7217
83 ### inspect previous text chunk for escape slashes
84 107 ▶ my $n = ($text =~ m{ (\\+) $ }x) ? length($1) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$text =~ / (\\+) $ /x ? : 9 98 107
85 107 ▶ if ($self->{'_no_interp'} || $n % 2) { # were there odd escapes
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_no_interp"} or $n % 2) 18 89 107
Condition100%3/3
$self->{"_no_interp"} or $n % 2
l!l&&r!l&&!r
12689
MC/DC100%2/2
$self->{"_no_interp"} or $n % 2
$self->{"_no_interp"} $n % 2
Truth table100%3/3
A or B
A= $self->{"_no_interp"}B= $n % 2
ABresult
1X1
011
000
86 18 my $prev_text;
87 18 ▶ $prev_text = \$pointer->[-1] if defined($pointer->[-1]) && ! ref($pointer->[-1]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $pointer->[-1] and not ref $pointer->[-1] 18 0 18
Condition33%1/3
defined $pointer->[-1] and not ref $pointer->[-1]
!ll&&!rl&&r
0018
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
88 18 ▶ chop($$prev_text) if $n % 2;
Branch: 1 branch
BranchTrueFalseTotal
if $n % 2 6 12 18
89 0 ▶ if ($prev_text) { $$prev_text .= $dollar } else { push @$pointer, $dollar }
Branch: 1 branch
BranchTrueFalseTotal
if ($prev_text) { } 18 0 18
90 18 next;
91 }
92  
93 89 my $not = $$str_ref =~ m{ \G ! }gcx;
94 89 my $mark = pos($$str_ref);
95 89 my $ref;
96 89 ▶ if ($$str_ref =~ m{ \G \{ }gcx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G \{ /cgx) { } 37 52 89
97 37 local $self->{'_operator_precedence'} = 0; # allow operators
98 37 $ref = $self->parse_expr($str_ref);
99 37 ▶ $$str_ref =~ m{ \G \s* $QR_COMMENTS \} }gcx
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G \s* $Template::Alloy::TT::QR_COMMENTS \} /cgx or $self->throw("parse", "Missing close }", undef, pos $$str_ref) 37 0 37
100 || $self->throw('parse', 'Missing close }', undef, pos($$str_ref));
101 } else {
102 52 local $self->{'_operator_precedence'} = 1; # no operators
103 52 local $QR_COMMENTS = local $Template::Alloy::Parse::QR_COMMENTS = qr{};
104 52 $ref = $self->parse_expr($str_ref);
105 }
106 89 ▶ $self->throw('parse', "Error while parsing for interpolated string", undef, pos($$str_ref))
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ref 0 89 89
107 if ! defined $ref;
108 89 ▶ if (! $not && $self->{'SHOW_UNDEFINED_INTERP'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $not and $self->{"SHOW_UNDEFINED_INTERP"}) 12 77 89
Condition100%3/3
not $not and $self->{"SHOW_UNDEFINED_INTERP"}
!ll&&!rl&&r
185912
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
109 12 $ref = [[undef, '//', $ref, '$'.substr($$str_ref, $mark, pos($$str_ref)-$mark)], 0];
110 }
111 89 push @$pointer, ['GET', $mark, pos($$str_ref), $ref];
112 89 $post_chomp = 0; # no chomping after dollar vars
113 89 next;
114 }
115  
116 7110 $node = [undef, pos($$str_ref), undef];
117  
118 ### take care of whitespace and comments flags
119 7110 ▶ my $pre_chomp = $$str_ref =~ m{ \G ([+=~-]) }gcx ? $1 : $self->{'PRE_CHOMP'};
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G ([+=~-]) /cgx ? : 179 6931 7110
120 7110 ▶ $pre_chomp =~ y/-=~+/1230/ if $pre_chomp;
Branch: 1 branch
BranchTrueFalseTotal
if $pre_chomp 182 6928 7110
121 7110 ▶ if ($pre_chomp && $pointer->[-1] && ! ref $pointer->[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre_chomp and $pointer->[-1] and not ref $pointer->[-1]) 65 7045 7110
Condition100%6/6
$pre_chomp and $pointer->[-1] and not ref $pointer->[-1]
!ll&&!rl&&r
70153065
$pre_chomp and $pointer->[-1]
!ll&&!rl&&r
69288795
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
122 65 ▶ if ($pre_chomp == 1) { $pointer->[-1] =~ s{ (?:\n|^) [^\S\n]* \z }{}x }
Branch: 3 branches
BranchTrueFalseTotal
if ($pre_chomp == 1) { } 35 30 65
elsif ($pre_chomp == 2) { } 0 30 30
elsif ($pre_chomp == 3) { } 30 0 30
123 0 elsif ($pre_chomp == 2) { $pointer->[-1] =~ s{ (\s+) \z }{ }x }
124 30 elsif ($pre_chomp == 3) { $pointer->[-1] =~ s{ (\s+) \z }{}x }
125 65 ▶ splice(@$pointer, -1, 1, ()) if ! length $pointer->[-1]; # remove the node if it is zero length
Branch: 1 branch
BranchTrueFalseTotal
unless length $pointer->[-1] 53 12 65
126 }
127  
128 ### leading # means to comment the entire section
129 7110 ▶ if ($$str_ref =~ m{ \G \# }gcx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G \# /cgx) 21 7089 7110
130 21 ▶ $$str_ref =~ m{ \G (.*?) ([+~=-]?) ($self->{'_end_tag'}) }gcxs # brute force - can't comment tags with nested %]
Branch: 1 branch
BranchTrueFalseTotal
$$str_ref =~ / \G (.*?) ([+~=-]?) ($self->{"_end_tag"}) /cgsx or $self->throw("parse", "Missing closing tag", undef, pos $$str_ref) 21 0 21
131 || $self->throw('parse', "Missing closing tag", undef, pos($$str_ref));
132 21 $node->[0] = '#';
133 21 $node->[2] = pos($$str_ref) - length($3) - length($2);
134 21 push @$pointer, $node;
135  
136 21 $post_chomp = $2;
137 21 ▶ $post_chomp ||= $self->{'POST_CHOMP'};
Condition33%1/3
$post_chomp ||= $self->{"POST_CHOMP"}
l!l&&r!l&&!r
0021
MC/DC0%0/2
$post_chomp ||= $self->{"POST_CHOMP"}
$post_chomp $self->{"POST_CHOMP"}
Truth table33%1/3
A ||= B
A= $post_chompB= $self->{"POST_CHOMP"}
ABresult
1X1
011
000
138 21 ▶ $post_chomp =~ y/-=~+/1230/ if $post_chomp;
Branch: 1 branch
BranchTrueFalseTotal
if $post_chomp 0 21 21
139 21 next;
140 }
141 #$$str_ref =~ m{ \G \s* $QR_COMMENTS }gcxo;
142 }
143  
144 ### look for DIRECTIVES
145 8858 ▶ if ($$str_ref =~ m{ \G \s* $QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE }gcxo # find a word
Branch: 3 branches
BranchTrueFalseTotal
if ($$str_ref =~ / \G \s* $Template::Alloy::TT::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgox and $func = $self->{'ANYCASE'} ? uc $1 : $1 and $dirs->{$func} || (pos $$str_ref -= length $1) && 0) { } 3938 4920 8858
elsif (defined(my $var = $self->parse_expr($str_ref))) { } 4700 199 4899
$self->{'ANYCASE'} ? : 256 7386 7642
Condition72%8/11
$$str_ref =~ / \G \s* $Template::Alloy::TT::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgox and $func = $self->{"ANYCASE"} ? uc $1 : $1 and $dirs->{$func} || (pos $$str_ref -= length $1) && 0
!ll&&!rl&&r
121637043938
$$str_ref =~ / \G \s* $Template::Alloy::TT::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgox and $func = $self->{"ANYCASE"} ? uc $1 : $1
!ll&&!rl&&r
121607642
$dirs->{$func} or pos $$str_ref -= length $1 and 0
l!l&&r!l&&!r
393803704
pos $$str_ref -= length $1 and 0
!ll
03704
MC/DC25%1/4
$$str_ref =~ / \G \s* $Template::Alloy::TT::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgox and $func = $self->{"ANYCASE"} ? uc $1 : $1 and $dirs->{$func} || (pos $$str_ref -= length $1) && 0
$$str_ref =~ / \G \s* $Template::Alloy::TT::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgox $func = $self->{"ANYCASE"} ? uc $1 : $1 $dirs->{$func} pos $$str_ref -= length $1
Truth table60%3/5
A and B and C or D
A= $$str_ref =~ / \G \s* $Template::Alloy::TT::QR_COMMENTS $Template::Alloy::Parse::QR_DIRECTIVE /cgoxB= $func = $self->{"ANYCASE"} ? uc $1 : $1C= $dirs->{$func}D= pos $$str_ref -= length $1
ABCDresult
0XXX0
10XX0
11000
111X1
11011
146 && ($func = $self->{'ANYCASE'} ? uc($1) : $1)
147 && ($dirs->{$func}
148 || ((pos($$str_ref) -= length $1) && 0))
149 ) { # is it a directive
150 3938 $$str_ref =~ m{ \G \s* $QR_COMMENTS }gcx;
151  
152 3938 ▶ $func = $aliases->{$func} if $aliases->{$func};
Branch: 1 branch
BranchTrueFalseTotal
if $aliases->{$func} 92 3846 3938
153 3938 $node->[0] = $func;
154  
155 ### store out this current node level to the appropriate tree location
156 # on a post operator - replace the original node with the new one - store the old in the new
157 3938 ▶ if ($dirs->{$func}->[3] && $post_op) {
Branch: 3 branches
BranchTrueFalseTotal
if ($dirs->{$func}[3] and $post_op) { } 150 3788 3938
elsif ($post_op and $self->{'SEMICOLONS'}) { } 3 3785 3788
elsif ($capture) { } 136 3649 3785
Condition100%3/3
$dirs->{$func}[3] and $post_op
!ll&&!rl&&r
3409379150
MC/DC100%2/2
$dirs->{$func}[3] and $post_op
$dirs->{$func}[3] $post_op
Truth table100%3/3
A and B
A= $dirs->{$func}[3]B= $post_op
ABresult
0X0
100
111
158 150 my @post_op = @$post_op;
159 150 @$post_op = @$node;
160 150 $node = $post_op;
161 150 $node->[4] = [\@post_op];
162 # if there was not a semi-colon - see if semis were required
163 ▶ } elsif ($post_op && $self->{'SEMICOLONS'}) {
Condition100%3/3
$post_op and $self->{"SEMICOLONS"}
!ll&&!rl&&r
377963
MC/DC100%2/2
$post_op and $self->{"SEMICOLONS"}
$post_op $self->{"SEMICOLONS"}
Truth table100%3/3
A and B
A= $post_opB= $self->{"SEMICOLONS"}
ABresult
0X0
100
111
164 3 $self->throw('parse', "Missing semi-colon with SEMICOLONS => 1", undef, $node->[1]);
165  
166 # handle directive captures for an item like "SET foo = BLOCK"
167 } elsif ($capture) {
168 136 push @{ $capture->[4] }, $node;
169 136 undef $capture;
170  
171 # normal nodes
172 } else{
173 3649 push @$pointer, $node;
174 }
175  
176 ### parse any remaining tag details
177 3935 $node->[3] = eval { $dirs->{$func}->[0]->($self, $str_ref, $node) };
178 3935 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 27 3908 3935
179 27 ▶ $err->node($node) if UNIVERSAL::can($err, 'node') && ! $err->node;
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($err, "node") and not $err->node 27 0 27
Condition33%1/3
UNIVERSAL::can($err, "node") and not $err->node
!ll&&!rl&&r
0027
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
180 27 die $err;
181 }
182 3908 $node->[2] = pos $$str_ref;
183  
184 ### anything that behaves as a block ending
185 3908 ▶ if ($func eq 'END' || $dirs->{$func}->[4]) { # [4] means it is a continuation block (ELSE, CATCH, etc)
Branch: 4 branches
BranchTrueFalseTotal
if ($func eq 'END' or $dirs->{$func}[4]) { } 1077 2831 3908
elsif ($dirs->{$func}[2] and not $post_op) { } 877 1954 2831
elsif ($func eq 'TAGS') { } 75 1879 1954
elsif ($func eq 'META') { } 134 1745 1879
Condition100%3/3
$func eq "END" or $dirs->{$func}[4]
l!l&&r!l&&!r
8682092831
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
186 1077 ▶ if (! @state) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@state) 9 1068 1077
187 9 $self->throw('parse', "Found an $func tag while not in a block", $node, pos($$str_ref));
188 }
189 1068 my $parent_node = pop @state;
190  
191 1068 ▶ if ($func ne 'END') {
Branch: 1 branch
BranchTrueFalseTotal
if ($func ne "END") 209 859 1068
192 209 pop @$pointer; # we will store the node in the parent instead
193 209 $parent_node->[5] = $node;
194 209 my $parent_type = $parent_node->[0];
195 209 ▶ if (! $dirs->{$func}->[4]->{$parent_type}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dirs->{$func}[4]{$parent_type}) 3 206 209
196 3 $self->throw('parse', "Found unmatched nested block", $node, pos($$str_ref));
197 }
198 }
199  
200 ### restore the pointer up one level (because we hit the end of a block)
201 1065 ▶ $pointer = (! @state) ? \@tree : $state[-1]->[4];
Branch: 1 branch
BranchTrueFalseTotal
!@state ? : 967 98 1065
202  
203 ### normal end block
204 1065 ▶ if ($func eq 'END') {
Branch: 1 branch
BranchTrueFalseTotal
if ($func eq 'END') { } 859 206 1065
205 859 ▶ if ($parent_node->[0] eq 'BLOCK') { # move BLOCKS to front
Branch: 3 branches
BranchTrueFalseTotal
if ($parent_node->[0] eq 'BLOCK') { } 305 554 859
elsif ($parent_node->[0] eq 'VIEW') { } 0 554 554
elsif ($$dirs{$parent_node->[0]}[5]) { } 21 533 554
206 305 ▶ if (defined($parent_node->[3]) && @in_view) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent_node->[3] and @in_view) { } 0 305 305
Condition33%1/3
defined $parent_node->[3] and @in_view
!ll&&!rl&&r
03050
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
207 0 push @{ $in_view[-1] }, $parent_node;
208 } else {
209 305 ▶ push @blocks, $parent_node
Branch: 1 branch
BranchTrueFalseTotal
if length $parent_node->[3] 249 56 305
210 if length $parent_node->[3]; # macro blocks may not have a name
211 }
212 305 ▶ if ($pointer->[-1] && ! $pointer->[-1]->[6]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pointer->[-1] and not $pointer->[-1][6]) 252 53 305
Condition66%2/3
$pointer->[-1] and not $pointer->[-1][6]
!ll&&!rl&&r
053252
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
213 252 splice(@$pointer, -1, 1, ());
214 }
215 } elsif ($parent_node->[0] eq 'VIEW') {
216 0 my $ref = { map {($_->[3] => $_->[4])} @{ pop @in_view }};
217 0 unshift @{ $parent_node->[3] }, $ref;
218 } elsif ($dirs->{$parent_node->[0]}->[5]) { # allow no_interp to turn on and off
219 21 $self->{'_no_interp'}--;
220 }
221  
222 ### continuation block - such as an elsif
223 } else {
224 206 push @state, $node;
225 206 ▶ $pointer = $node->[4] ||= [];
Condition50%1/2
$node->[4] ||= []
l!l
0206
MC/DC0%0/1
$node->[4] ||= []
$node->[4]
Truth table50%1/2
A
A= $node->[4]
Aresult
11
00
226 }
227  
228 ### handle block directives
229 ▶ } elsif ($dirs->{$func}->[2] && ! $post_op) {
Condition100%3/3
$dirs->{$func}[2] and not $post_op
!ll&&!rl&&r
1804150877
MC/DC100%2/2
$dirs->{$func}[2] and not $post_op
$dirs->{$func}[2] not $post_op
Truth table100%3/3
A and not(B)
A= $dirs->{$func}[2]B= not $post_op
ABresult
0X0
100
111
230 877 push @state, $node;
231 877 ▶ $pointer = $node->[4] ||= []; # allow future parsed nodes before END tag to end up in current node
Condition50%1/2
$node->[4] ||= []
l!l
0877
MC/DC0%0/1
$node->[4] ||= []
$node->[4]
Truth table50%1/2
A
A= $node->[4]
Aresult
11
00
232 877 ▶ push @in_view, [] if $func eq 'VIEW';
Branch: 1 branch
BranchTrueFalseTotal
if $func eq "VIEW" 0 877 877
233 877 ▶ $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] 21 856 877
234  
235 } elsif ($func eq 'TAGS') {
236 75 ($self->{'_start_tag'}, $self->{'_end_tag'}, my $old_end) = (@{ $node->[3] }[0,1], $self->{'_end_tag'});
237  
238 ### allow for one more closing tag of the old style
239 75 ▶ if ($$str_ref =~ m{ \G \s* $QR_COMMENTS ([+~=-]?) $old_end }gcxs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G \s* $Template::Alloy::TT::QR_COMMENTS ([+~=-]?) $old_end /cgsx) 66 9 75
240 66 $Template::Alloy::Parse::QR_COMMENTS = "(?sm: \\s*+ \\# .*? (?: \$ | (?=$self->{'_end_tag'}) ) )*+ \\s*+" if posessive();
241 66 $QR_COMMENTS = $Template::Alloy::Parse::QR_COMMENTS;
242 66 ▶ $post_chomp = $1 || $self->{'POST_CHOMP'};
Condition33%1/3
$1 || $self->{'POST_CHOMP'}
l!l&&r!l&&!r
0066
MC/DC0%0/2
$1 || $self->{'POST_CHOMP'}
$1 $self->{'POST_CHOMP'}
Truth table33%1/3
A || B
A= $1B= $self->{'POST_CHOMP'}
ABresult
1X1
011
000
243 66 ▶ $post_chomp =~ y/-=~+/1230/ if $post_chomp;
Branch: 1 branch
BranchTrueFalseTotal
if $post_chomp 0 66 66
244 66 $continue = 0;
245 66 $post_op = 0;
246 66 next;
247 }
248 9 $Template::Alloy::Parse::QR_COMMENTS = "(?sm: \\s*+ \\# .*? (?: \$ | (?=$self->{'_end_tag'}) ) )*+ \\s*+" if posessive();
249 9 $QR_COMMENTS = $Template::Alloy::Parse::QR_COMMENTS;
250  
251 } elsif ($func eq 'META') {
252 134 unshift @meta, @{ $node->[3] }; # first defined win
253 134 $node->[3] = undef; # only let these be defined once - at the front of the tree
254 }
255  
256 ### allow for bare variable getting and setting
257 } elsif (defined(my $var = $self->parse_expr($str_ref))) {
258 4700 ▶ if ($post_op && $self->{'SEMICOLONS'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($post_op and $self->{"SEMICOLONS"}) 15 4685 4700
Condition100%3/3
$post_op and $self->{"SEMICOLONS"}
!ll&&!rl&&r
46434215
MC/DC100%2/2
$post_op and $self->{"SEMICOLONS"}
$post_op $self->{"SEMICOLONS"}
Truth table100%3/3
A and B
A= $post_opB= $self->{"SEMICOLONS"}
ABresult
0X0
100
111
259 15 $self->throw('parse', "Missing semi-colon with SEMICOLONS => 1", undef, $node->[1]);
260 }
261 4685 push @$pointer, $node;
262 4685 ▶ if ($$str_ref =~ m{ \G \s* $QR_COMMENTS ($QR_OP_ASSIGN) >? (?! [+=~-]? $self->{'_end_tag'}) \s* $QR_COMMENTS }gcx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G \s* $Template::Alloy::TT::QR_COMMENTS ($Template::Alloy::TT::QR_OP_ASSIGN) >? (?! [+=~-]? $self->{'_end_tag'}) \s* $Template::Alloy::TT::QR_COMMENTS /cgx) { } 750 3935 4685
263 750 $node->[0] = 'SET';
264 750 $node->[3] = eval { $dirs->{'SET'}->[0]->($self, $str_ref, $node, $1, $var) };
265 750 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 750 750
266 0 ▶ $err->node($node) if UNIVERSAL::can($err, 'node') && ! $err->node;
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($err, "node") and not $err->node 0 0 0
Condition0%0/3
UNIVERSAL::can($err, "node") and not $err->node
!ll&&!rl&&r
000
MC/DC0%0/2
UNIVERSAL::can($err, "node") and not $err->node
UNIVERSAL::can($err, "node") not $err->node
Truth table0%0/3
A and not(B)
A= UNIVERSAL::can($err, "node")B= not $err->node
ABresult
0X0
100
111
267 0 die $err;
268 }
269 } else {
270 3935 ▶ if ($self->{'AUTO_FILTER'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"AUTO_FILTER"}) 21 3914 3935
271 21 ▶ $var = [[undef, '~', $var], 0] if ! ref $var;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $var 3 18 21
272 21 ▶ push @$var, '|', $self->{'AUTO_FILTER'}, 0 if @$var < 3 || $var->[-3] ne '|';
Branch: 1 branch
BranchTrueFalseTotal
if @$var < 3 or $var->[-3] ne "|" 15 6 21
Condition100%3/3
@$var < 3 or $var->[-3] ne "|"
l!l&&r!l&&!r
966
MC/DC100%2/2
@$var < 3 or $var->[-3] ne "|"
@$var < 3 $var->[-3] ne "|"
Truth table100%3/3
A or B
A= @$var < 3B= $var->[-3] ne "|"
ABresult
1X1
011
000
273 }
274 3935 $node->[0] = 'GET';
275 3935 $node->[3] = $var;
276 }
277 4685 $node->[2] = pos $$str_ref;
278 }
279  
280 ### look for the closing tag
281 8714 ▶ if ($$str_ref =~ m{ \G \s* $QR_COMMENTS (?: ; \s* $QR_COMMENTS)? ([+=~-]?) $self->{'_end_tag'} }gcxs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$str_ref =~ / \G \s* $Template::Alloy::TT::QR_COMMENTS (?: ; \s* $Template::Alloy::TT::QR_COMMENTS)? ([+=~-]?) $self->{"_end_tag"} /cgsx) 6965 1749 8714
282 6965 ▶ if ($one_tag_only) {
Branch: 1 branch
BranchTrueFalseTotal
if ($one_tag_only) 27 6938 6965
283 27 ▶ $self->throw('parse', "Invalid char \"$1\" found at end of block") if $1;
Branch: 1 branch
BranchTrueFalseTotal
if $1 0 27 27
284 27 ▶ $self->throw('parse', "Missing END directive", $state[-1], pos($$str_ref)) if @state > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @state > 0 0 27 27
285 27 return \@tree;
286 }
287  
288 6938 ▶ $post_chomp = $1 || $self->{'POST_CHOMP'};
Condition100%3/3
$1 || $self->{'POST_CHOMP'}
l!l&&r!l&&!r
1642086566
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
289 6938 ▶ $post_chomp =~ y/-=~+/1230/ if $post_chomp;
Branch: 1 branch
BranchTrueFalseTotal
if $post_chomp 372 6566 6938
290 6938 $continue = 0;
291 6938 $post_op = 0;
292 6938 next;
293 }
294  
295 ### semi-colon = end of statement - we will need to continue parsing this tag
296 1749 ▶ if ($$str_ref =~ m{ \G ; \s* $QR_COMMENTS }gcxo) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$str_ref =~ / \G ; \s* $Template::Alloy::TT::QR_COMMENTS /cgox) { } 1200 549 1749
elsif ($node->[6]) { } 136 413 549
297 1200 $post_op = 0;
298  
299 ### we are flagged to start capturing the output of the next directive - set it up
300 } elsif ($node->[6]) {
301 136 $post_op = 0;
302 136 $capture = $node;
303  
304 ### allow next directive to be post-operative (or not)
305 } else {
306 413 $post_op = $node;
307 }
308  
309 ### no closing tag yet - no need to get an opening tag on next loop
310 1749 ▶ $self->throw('parse', "Not sure how to handle tag", $node, pos($$str_ref)) if $continue == pos $$str_ref;
Branch: 1 branch
BranchTrueFalseTotal
if $continue == pos $$str_ref 7 1742 1749
311 1742 $continue = pos $$str_ref;
312 }
313  
314 ### cleanup the tree
315 4097 ▶ unshift(@tree, @blocks) if @blocks;
Branch: 1 branch
BranchTrueFalseTotal
if @blocks 201 3896 4097
316 4097 ▶ unshift(@tree, ['META', 1, 1, \@meta]) if @meta;
Branch: 1 branch
BranchTrueFalseTotal
if @meta 134 3963 4097
317 4097 ▶ $self->throw('parse', "Missing END directive", $state[-1], pos($$str_ref)) if @state > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @state > 0 15 4082 4097
318  
319 ### pull off the last text portion - if any
320 4082 ▶ if (pos($$str_ref) != length($$str_ref)) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $$str_ref != length $$str_ref) 1013 3069 4082
321 1013 my $text = substr $$str_ref, pos($$str_ref);
322 1013 ▶ if (! $post_chomp) { }
Branch: 4 branches
BranchTrueFalseTotal
if (not $post_chomp) { } 954 59 1013
elsif ($post_chomp == 1) { } 29 30 59
elsif ($post_chomp == 2) { } 0 30 30
elsif ($post_chomp == 3) { } 30 0 30
323 29 elsif ($post_chomp == 1) { $text =~ s{ ^ [^\S\n]* \n }{}x }
324 0 elsif ($post_chomp == 2) { $text =~ s{ ^ \s+ }{ }x }
325 30 elsif ($post_chomp == 3) { $text =~ s{ ^ \s+ }{}x }
326 1013 ▶ push @$pointer, $text if length $text;
Branch: 1 branch
BranchTrueFalseTotal
if length $text 969 44 1013
327 }
328  
329 4082 return \@tree;
330 }
331  
332 ###----------------------------------------------------------------###
333  
334 3623 ▶sub process {
Subroutine process: called CC=74 SCAR=46.1
Pod undocumented
335 3623 my ($self, $in, $swap, $out, @ARGS) = @_;
336 3623 delete $self->{'error'};
337  
338 3623 ▶ if ($self->{'DEBUG'}) { # "enable" some types of tt style debugging
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"DEBUG"}) 24 3599 3623
339 24 ▶ $self->{'_debug_dirs'} = 1 if $self->{'DEBUG'} =~ /^\d+$/ ? $self->{'DEBUG'} & 8 : $self->{'DEBUG'} =~ /dirs|all/;
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"DEBUG"} =~ /^\d+$/ ? $self->{"DEBUG"} & 8 : $self->{"DEBUG"} =~ /dirs|all/ 18 6 24
$self->{'DEBUG'} =~ /^\d+$/ ? : 24 0 24
340 24 ▶ $self->{'_debug_undef'} = 1 if $self->{'DEBUG'} =~ /^\d+$/ ? $self->{'DEBUG'} & 2 : $self->{'DEBUG'} =~ /undef|all/;
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"DEBUG"} =~ /^\d+$/ ? $self->{"DEBUG"} & 2 : $self->{"DEBUG"} =~ /undef|all/ 6 18 24
$self->{'DEBUG'} =~ /^\d+$/ ? : 24 0 24
341 }
342  
343 3623 my $args;
344 3623 ▶ $args = ($#ARGS == 0 && UNIVERSAL::isa($ARGS[0], 'HASH')) ? {%{$ARGS[0]}} : {@ARGS} if scalar @ARGS;
Branch: 2 branches
BranchTrueFalseTotal
if scalar @ARGS 1 3622 3623
$#ARGS == 0 && UNIVERSAL::isa($ARGS[0], 'HASH') ? : 1 0 1
Condition33%1/3
$#ARGS == 0 and UNIVERSAL::isa($ARGS[0], "HASH")
!ll&&!rl&&r
001
MC/DC0%0/2
$#ARGS == 0 and UNIVERSAL::isa($ARGS[0], "HASH")
$#ARGS == 0 UNIVERSAL::isa($ARGS[0], "HASH")
Truth table33%1/3
A and B
A= $#ARGS == 0B= UNIVERSAL::isa($ARGS[0], "HASH")
ABresult
0X0
100
111
345  
346 ### get the content
347 3623 my $content;
348 3623 ▶ if (ref $in) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $in) { } 3622 1 3623
349 3622 ▶ if (ref($in) eq 'SCALAR') { # reference to a string
Branch: 3 branches
BranchTrueFalseTotal
if (ref $in eq 'SCALAR') { } 3618 4 3622
elsif (UNIVERSAL::isa($in, 'CODE')) { } 1 3 4
elsif (ref $in eq 'HASH') { } 1 2 3
350 3618 $content = $in;
351 } elsif (UNIVERSAL::isa($in, 'CODE')) {
352 1 $in = $in->();
353 1 $content = \$in;
354 } elsif (ref($in) eq 'HASH') { # pre-prepared document
355 1 $content = $in;
356 } else { # should be a file handle
357 2 local $/ = undef;
358 2 $in = <$in>;
359 2 $content = \$in;
360 }
361 } else {
362 ### should be a filename
363 1 $content = $in;
364 }
365  
366  
367 ### prepare block localization
368 3623 ▶ my $blocks = $self->{'BLOCKS'} ||= {};
Condition100%2/2
$self->{"BLOCKS"} ||= {}
l!l
153608
MC/DC100%1/1
$self->{"BLOCKS"} ||= {}
$self->{"BLOCKS"}
Truth table100%2/2
A
A= $self->{"BLOCKS"}
Aresult
11
00
369  
370  
371 ### do the swap
372 3623 my $output = '';
373 3623 eval {
374  
375 ### localize the stash
376 3623 ▶ $swap ||= {};
Condition100%2/2
$swap ||= {}
l!l
36212
MC/DC100%1/1
$swap ||= {}
$swap
Truth table100%2/2
A
A= $swap
Aresult
11
00
377 3623 ▶ my $var1 = $self->{'_vars'} ||= {};
Condition100%2/2
$self->{"_vars"} ||= {}
l!l
153608
MC/DC100%1/1
$self->{"_vars"} ||= {}
$self->{"_vars"}
Truth table100%2/2
A
A= $self->{"_vars"}
Aresult
11
00
378 3623 ▶ my $var2 = $self->{'STASH'} || $self->{'VARIABLES'} || $self->{'PRE_DEFINE'} || {};
Condition100%8/8
$self->{'STASH'} || $self->{'VARIABLES'} || $self->{'PRE_DEFINE'} || {}
l!l
573566
$self->{"STASH"} or $self->{"VARIABLES"} or $self->{"PRE_DEFINE"}
l!l&&r!l&&!r
5433566
$self->{"STASH"} or $self->{"VARIABLES"}
l!l&&r!l&&!r
15393569
MC/DC100%3/3
$self->{'STASH'} || $self->{'VARIABLES'} || $self->{'PRE_DEFINE'} || {}
$self->{"STASH"} $self->{"VARIABLES"} $self->{"PRE_DEFINE"}
Truth table100%4/4
A or B or C
A= $self->{"STASH"}B= $self->{"VARIABLES"}C= $self->{"PRE_DEFINE"}
ABCresult
1XX1
01X1
0011
0000
379 3623 ▶ $var1->{'global'} ||= {}; # allow for the "global" namespace - that continues in between processing
Condition100%2/2
$var1->{"global"} ||= {}
l!l
153608
MC/DC100%1/1
$var1->{"global"} ||= {}
$var1->{"global"}
Truth table100%2/2
A
A= $var1->{"global"}
Aresult
11
00
380 3623 my $copy = {%$var2, %$var1, %$swap};
381  
382 3623 local $self->{'BLOCKS'} = $blocks = {%$blocks}; # localize blocks - but save a copy to possibly restore
383 3623 local $self->{'_template'};
384  
385 3623 delete $self->{'_debug_off'};
386 3623 delete $self->{'_debug_format'};
387  
388 ### handle pre process items that go before every document
389 3623 my $pre = '';
390 3623 ▶ if ($self->{'PRE_PROCESS'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PRE_PROCESS"}) 36 3587 3623
391 36 _load_template_meta($self, $content);
392 36 foreach my $name (@{ $self->split_paths($self->{'PRE_PROCESS'}) }) {
393 39 $self->_process($name, $copy, \$pre);
394 }
395 }
396  
397 ### process the central file now - catching errors to allow for the ERROR config
398 3620 eval {
399 3620 ▶ local $self->{'STREAM'} = undef if $self->{'WRAPPER'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"WRAPPER"} 39 3581 3620
400  
401 ### handle the PROCESS config - which loads another template in place of the real one
402 3620 ▶ if (exists $self->{'PROCESS'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'PROCESS'}) { } 33 3587 3620
403 33 _load_template_meta($self, $content);
404 33 foreach my $name (@{ $self->split_paths($self->{'PROCESS'}) }) {
405 39 ▶ next if ! length $name;
Branch: 1 branch
BranchTrueFalseTotal
unless length $name 0 39 39
406 39 $self->_process($name, $copy, \$output);
407 }
408  
409 ### handle "normal" content
410 } else {
411 3587 local $self->{'_start_top_level'} = 1;
412 3587 $self->_process($content, $copy, \$output);
413 }
414 };
415  
416 ### catch errors with ERROR config
417 3620 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 201 3419 3620
418 201 ▶ $err = $self->exception('undef', $err) if ! UNIVERSAL::can($err, 'type');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::can($err, "type") 0 201 201
419 201 ▶ die $err if $err->type =~ /stop|return/;
Branch: 1 branch
BranchTrueFalseTotal
if $err->type =~ /stop|return/ 0 201 201
420 201 ▶ my $catch = $self->{'ERRORS'} || $self->{'ERROR'} || die $err;
Condition100%5/5
$self->{'ERRORS'} || $self->{'ERROR'} || die($err)
l!l
45156
$self->{"ERRORS"} or $self->{"ERROR"}
l!l&&r!l&&!r
2124156
MC/DC100%2/2
$self->{'ERRORS'} || $self->{'ERROR'} || die($err)
$self->{"ERRORS"} $self->{"ERROR"}
Truth table100%3/3
A or B
A= $self->{"ERRORS"}B= $self->{"ERROR"}
ABresult
1X1
011
000
421 45 ▶ $catch = {default => $catch} if ! ref $catch;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $catch 24 21 45
422 45 my $type = $err->type;
423 45 my $last_found;
424 my $file;
425 45 foreach my $name (keys %$catch) {
426 60 ▶ my $_name = (! defined $name || lc($name) eq 'default') ? '' : $name;
Branch: 1 branch
BranchTrueFalseTotal
!defined($name) || lc $name eq 'default' ? : 45 15 60
Condition66%2/3
not defined $name or lc $name eq "default"
l!l&&r!l&&!r
04515
MC/DC50%1/2
not defined $name or lc $name eq "default"
not defined $name lc $name eq "default"
Truth table66%2/3
not(A) or B
A= not defined $nameB= lc $name eq "default"
ABresult
1X1
011
000
427 60 ▶ if ($type =~ / ^ \Q$_name\E \b /x
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ / ^ \Q$_name\E \b /x and !defined($last_found) || length $last_found < length $_name) 49 11 60
Condition100%6/6
$type =~ / ^ \Q$_name\E \b /x and !defined($last_found) || length $last_found < length $_name
!ll&&!rl&&r
3849
not defined $last_found or length $last_found < length $_name
l!l&&r!l&&!r
4548
MC/DC100%3/3
$type =~ / ^ \Q$_name\E \b /x and !defined($last_found) || length $last_found < length $_name
$type =~ / ^ \Q$_name\E \b /x not defined $last_found length $last_found < length $_name
Truth table100%4/4
A and not(B) or C
A= $type =~ / ^ \Q$_name\E \b /xB= not defined $last_foundC= length $last_found < length $_name
ABCresult
0XX0
1000
11X1
1011
428 && (! defined($last_found) || length($last_found) < length($_name))) { # more specific wins
429 49 $last_found = $_name;
430 49 $file = $catch->{$name};
431 }
432 }
433  
434 ### found error handler - try it out
435 45 ▶ if (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 45 0 45
436 45 $output = '';
437 45 ▶ local $copy->{'error'} = local $copy->{'e'} = $self->{'COMPILE_JS'} ? {type => $type, info => $err->info} : $err;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'COMPILE_JS'} ? : 0 45 45
438 45 ▶ local $self->{'STREAM'} = undef if $self->{'WRAPPER'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"WRAPPER"} 3 42 45
439 45 $self->_process($file, $copy, \$output);
440 }
441 }
442  
443 ### handle wrapper directives
444 3464 ▶ if (exists $self->{'WRAPPER'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"WRAPPER"}) 39 3425 3464
445 39 _load_template_meta($self, $content);
446 39 foreach my $name (reverse @{ $self->split_paths($self->{'WRAPPER'}) }) {
447 42 ▶ next if ! length $name;
Branch: 1 branch
BranchTrueFalseTotal
unless length $name 0 42 42
448 42 local $copy->{'content'} = $output;
449 42 my $out = '';
450 42 local $self->{'STREAM'} = undef;
451 42 $self->_process($name, $copy, \$out);
452 39 $output = $out;
453 }
454 36 ▶ if ($self->{'STREAM'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"STREAM"}) 12 24 36
455 12 print $output;
456 12 $output = 1;
457 }
458 }
459  
460 3461 ▶ $output = $pre . $output if length $pre;
Branch: 1 branch
BranchTrueFalseTotal
if length $pre 22 3439 3461
461  
462 ### handle post process items that go after every document
463 3461 ▶ if ($self->{'POST_PROCESS'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"POST_PROCESS"}) 36 3425 3461
464 36 _load_template_meta($self, $content);
465 36 foreach my $name (@{ $self->split_paths($self->{'POST_PROCESS'}) }) {
466 39 $self->_process($name, $copy, \$output);
467 }
468 }
469  
470 };
471  
472 ### clear blocks as asked (AUTO_RESET) defaults to on
473 3623 ▶ $self->{'BLOCKS'} = $blocks if exists($self->{'AUTO_RESET'}) && ! $self->{'AUTO_RESET'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"AUTO_RESET"} and not $self->{"AUTO_RESET"} 0 3623 3623
Condition33%1/3
exists $self->{"AUTO_RESET"} and not $self->{"AUTO_RESET"}
!ll&&!rl&&r
362300
MC/DC0%0/2
exists $self->{"AUTO_RESET"} and not $self->{"AUTO_RESET"}
exists $self->{"AUTO_RESET"} not $self->{"AUTO_RESET"}
Truth table33%1/3
A and not(B)
A= exists $self->{"AUTO_RESET"}B= not $self->{"AUTO_RESET"}
ABresult
0X0
100
111
474  
475 3623 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 165 3458 3623
476 165 ▶ $err = $self->exception('undef', $err) if ! UNIVERSAL::can($err, 'type');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::can($err, "type") 0 165 165
477 165 ▶ if ($err->type !~ /stop|return|next|last|break/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($err->type =~ /stop|return|next|last|break/) 165 0 165
478 165 $self->{'error'} = $err;
479 165 ▶ die $err if $self->{'RAISE_ERROR'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"RAISE_ERROR"} 0 165 165
480 165 return;
481 }
482 }
483  
484 ### send the content back out
485 3458 ▶ $out ||= $self->{'OUTPUT'};
Condition100%3/3
$out ||= $self->{"OUTPUT"}
l!l&&r!l&&!r
345611
MC/DC100%2/2
$out ||= $self->{"OUTPUT"}
$out $self->{"OUTPUT"}
Truth table100%3/3
A ||= B
A= $outB= $self->{"OUTPUT"}
ABresult
1X1
011
000
486 3458 ▶ if (ref $out) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $out) { } 3455 3 3458
elsif ($out) { } 2 1 3
487 3455 ▶ if (UNIVERSAL::isa($out, 'CODE')) {
Branch: 4 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($out, 'CODE')) { } 1 3454 3455
elsif (UNIVERSAL::can($out, 'print')) { } 1 3453 3454
elsif (UNIVERSAL::isa($out, 'SCALAR')) { } 3450 3 3453
elsif (UNIVERSAL::isa($out, 'ARRAY')) { } 1 2 3
488 1 $out->($output);
489 } elsif (UNIVERSAL::can($out, 'print')) {
490 1 $out->print($output);
491 } elsif (UNIVERSAL::isa($out, 'SCALAR')) { # reference to a string
492 3450 $$out = $output;
493 } elsif (UNIVERSAL::isa($out, 'ARRAY')) {
494 1 push @$out, $output;
495 } else { # should be a file handle
496 2 print {$out} $output;
497 }
498 } elsif ($out) { # should be a filename
499 2 my $file;
500 2 ▶ if ($out =~ m|^/|) {
Branch: 2 branches
BranchTrueFalseTotal
if ($out =~ m[^/]) { } 0 2 2
elsif ($out =~ m[^\.\.?/]) { } 0 2 2
501 0 ▶ if (! $self->{'ABSOLUTE'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'ABSOLUTE'}) { } 0 0 0
502 0 $self->throw($self->{'error'} = $self->exception('file', "ABSOLUTE paths disabled"));
503 } else {
504 0 $file = $out;
505 }
506 } elsif ($out =~ m|^\.\.?/|) {
507 0 ▶ if (! $self->{'RELATIVE'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'RELATIVE'}) { } 0 0 0
508 0 $self->throw($self->{'error'} = $self->exception('file', "RELATIVE paths disabled"));
509 } else {
510 0 $file = $out;
511 }
512 } else {
513 2 my $path = $self->{'OUTPUT_PATH'};
514 2 ▶ $path = '.' if ! defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 2 2
515 2 ▶ if (! -d $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $path) 0 2 2
516 0 require File::Path;
517 0 File::Path::mkpath($path);
518 }
519 2 $file = "$path/$out";
520 }
521 open(my $fh, '>', $file)
522 2 ▶ || $self->throw($self->{'error'} = $self->exception('file', "$out couldn't be opened for writing: $!"));
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $file or $self->throw($self->{"error"} = $self->exception("file", "$out couldn't be opened for writing: $!")) 2 0 2
523 2 ▶ if (my $bm = $args->{'binmode'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $bm = $args->{'binmode'}) { } 1 1 2
elsif ($self->{'ENCODING'}) { } 0 1 1
524 1 ▶ if (+$bm == 1) { binmode $fh }
Branch: 1 branch
BranchTrueFalseTotal
if ($bm == 1) { } 1 0 1
525 0 else { binmode $fh, $bm }
526 } elsif ($self->{'ENCODING'}) {
527 0 ▶ if (eval { require Encode } && defined &Encode::encode) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Encode } } and defined &Encode::encode) 0 0 0
Condition0%0/3
eval { do { require Encode } } and defined &Encode::encode
!ll&&!rl&&r
000
MC/DC0%0/2
eval { do { require Encode } } and defined &Encode::encode
eval { do { require Encode } } defined &Encode::encode
Truth table0%0/3
A and B
A= eval { do { require Encode } }B= defined &Encode::encode
ABresult
0X0
100
111
528 0 $output = Encode::encode($self->{'ENCODING'}, $output);
529 }
530 }
531 2 print {$fh} $output;
532 } else {
533 1 print $output;
534 }
535  
536 3458 ▶ return if $self->{'error'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"error"} 6 3452 3458
537 3452 return 1;
538 }
539  
540 144 ▶sub _load_template_meta {
Subroutine _load_template_meta: called CC=9 SCAR=22.1
541 144 my $self = shift;
542 144 ▶ return if $self->{'_template'}; # only do once as need
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_template"} 15 129 144
543  
544 129 eval {
545 ### load the meta data for the top document
546 ### this is needed by some of the custom handlers such as PRE_PROCESS and POST_PROCESS
547 129 my $content = shift;
548 129 ▶ my $doc = $self->{'_template'} = ref($content) eq 'HASH' ? $content : $self->load_template($content) || {};
Branch: 1 branch
BranchTrueFalseTotal
ref $content eq 'HASH' ? : 0 129 129
Condition50%1/2
$self->load_template($content) or {}
l!l
1290
MC/DC0%0/1
$self->load_template($content) or {}
$self->load_template($content)
Truth table50%1/2
A
A= $self->load_template($content)
Aresult
11
00
549 my $meta = $doc->{'_perl'} ? $doc->{'_perl'}->{'meta'}
550 129 ▶ : ($doc->{'_tree'} && ref($doc->{'_tree'}->[0]) && $doc->{'_tree'}->[0]->[0] eq 'META') ? $doc->{'_tree'}->[0]->[3]
Branch: 2 branches
BranchTrueFalseTotal
$doc->{'_perl'} ? : 43 86 129
$doc->{'_tree'} && ref $doc->{'_tree'}[0] && $doc->{'_tree'}[0][0] eq 'META' ? : 12 74 86
Condition83%5/6
$doc->{"_tree"} and ref $doc->{"_tree"}[0] and $doc->{"_tree"}[0][0] eq "META"
!ll&&!rl&&r
641012
$doc->{"_tree"} and ref $doc->{"_tree"}[0]
!ll&&!rl&&r
06422
MC/DC66%2/3
$doc->{"_tree"} and ref $doc->{"_tree"}[0] and $doc->{"_tree"}[0][0] eq "META"
$doc->{"_tree"} ref $doc->{"_tree"}[0] $doc->{"_tree"}[0][0] eq "META"
Truth table75%3/4
A and B and C
A= $doc->{"_tree"}B= ref $doc->{"_tree"}[0]C= $doc->{"_tree"}[0][0] eq "META"
ABCresult
0XX0
10X0
1100
1111
551 : {};
552 129 ▶ $meta = {@$meta} if ref($meta) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $meta eq "ARRAY" 12 117 129
553 129 $self->{'_template'} = $doc;
554 129 @{ $doc }{keys %$meta} = values %$meta;
555 };
556  
557 129 return;
558 }
559  
560 ###----------------------------------------------------------------###
561  
562 7 1;
563  
564 __END__
« Alloy/Velocity.pm ↑ Summary Alloy.pm »