Alloy.pm

filter: Statementstmt 90.2% 574 / 636 Branchbran 78.4% 403 / 514 Conditioncond 69.4% 252 / 363 MC/DCmcdc 40.2% 83 / 206 Subroutinesub 94.8% 37 / 39 Podpod 75.0% 21 / 28 totaltotal 76.7% 1370 / 1786 CC 394 SCAR 46.1
CC
394
Cov
81%
play_expr
213.5
set_variable
145.3
load_template
106.2
CRAP 100.9
« Alloy/TT.pm ↑ Summary Alloy/Parse.pm »
1 package Template::Alloy;
2  
3 ###----------------------------------------------------------------###
4 # See the perldoc in Template/Alloy.pod #
5 # Copyright 2007 - 2013 - Paul Seamons #
6 # Distributed under the Perl Artistic License without warranty #
7 ###----------------------------------------------------------------###
8  
9 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 10 ▶use Template::Alloy::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶use Template::Alloy::Operator qw(play_operator define_operator);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 10 ▶use Template::Alloy::VMethod qw(define_vmethod $SCALAR_OPS $ITEM_OPS $ITEM_METHODS $FILTER_OPS $LIST_OPS $HASH_OPS $VOBJS);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 10 our $VERSION = '1.022';
16  
17 10 our $QR_PRIVATE = qr/^[_.]/;
18 10 our $WHILE_MAX = 1000;
19 10 our $MAX_EVAL_RECURSE = 50;
20 10 our $MAX_MACRO_RECURSE = 50;
21 10 our $STAT_TTL = 1;
22 10 our $QR_INDEX = '(?:\d*\.\d+ | \d+)';
23 10 our @CONFIG_COMPILETIME = qw(SYNTAX CACHE_STR_REFS ANYCASE INTERPOLATE PRE_CHOMP POST_CHOMP ENCODING
24 SEMICOLONS V1DOLLAR V2PIPE V2EQUALS AUTO_EVAL SHOW_UNDEFINED_INTERP AUTO_FILTER);
25 10 our @CONFIG_RUNTIME = qw(ADD_LOCAL_PATH CALL_CONTEXT DUMP VMETHOD_FUNCTIONS STRICT);
26 10 our $EVAL_CONFIG = {map {$_ => 1} @CONFIG_COMPILETIME, @CONFIG_RUNTIME};
27 10 our $EXTRA_COMPILE_EXT = '.sto';
28 10 our $PERL_COMPILE_EXT = '.pl';
29 10 our $JS_COMPILE_EXT = '.js';
30 10 our $GLOBAL_CACHE = {};
31  
32 ###----------------------------------------------------------------###
33  
34 10 our $AUTOROLE = {
35 Compile => [qw(load_perl compile_template compile_tree compile_expr)],
36 HTE => [qw(parse_tree_hte param output register_function clear_param query new_file new_scalar_ref new_array_ref new_filehandle)],
37 Parse => [qw(parse_tree parse_expr apply_precedence parse_args dump_parse_tree dump_parse_expr define_directive define_syntax)],
38 Play => [qw(play_tree _macro_sub)],
39 Stream => [qw(stream_tree)],
40 JS => [qw(load_js compile_template_js compile_tree_js play_js js_context process_js parse_tree_js process_jsr parse_tree_jsr)],
41 TT => [qw(parse_tree_tt3 process)],
42 Tmpl => [qw(parse_tree_tmpl set_delimiters set_strip set_value set_values parse_string set_dir parse_file loop_iteration fetch_loop_iteration)],
43 Velocity => [qw(parse_tree_velocity merge)],
44 };
45 10 my $ROLEMAP = { map { my $type = $_; map { ($_ => $type) } @{ $AUTOROLE->{$type} } } keys %$AUTOROLE };
46 10 my %STANDIN = ('Template' => 'TT', 'Template::Toolkit' => 'TT', 'HTML::Template' => 'HTE', 'HTML::Template::Expr' => 'HTE', 'Text::Tmpl' => 'Tmpl');
47  
48 10 our $AUTOLOAD;
49 39 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=13.9
50 39 my $self = shift;
51 39 ▶ my $meth = ($AUTOLOAD && $AUTOLOAD =~ /::(\w+)$/) ? $1 : $self->throw('autoload', "Invalid method $AUTOLOAD");
Branch: 1 branch
BranchTrueFalseTotal
$Template::Alloy::AUTOLOAD && $Template::Alloy::AUTOLOAD =~ /::(\w+)$/ ? : 37 2 39
Condition66%2/3
$Template::Alloy::AUTOLOAD and $Template::Alloy::AUTOLOAD =~ /::(\w+)$/
!ll&&!rl&&r
0237
MC/DC50%1/2
$Template::Alloy::AUTOLOAD and $Template::Alloy::AUTOLOAD =~ /::(\w+)$/
$Template::Alloy::AUTOLOAD $Template::Alloy::AUTOLOAD =~ /::(\w+)$/
Truth table66%2/3
A and B
A= $Template::Alloy::AUTOLOADB= $Template::Alloy::AUTOLOAD =~ /::(\w+)$/
ABresult
0X0
100
111
52 37 ▶ if (! $self->can($meth)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->can($meth)) 1 36 37
53 1 require Carp;
54 1 Carp::croak("Can't locate object method \"$meth\" via package ".ref($self));
55 }
56 36 return $self->$meth(@_);
57 }
58  
59 38 ▶sub can {
Subroutine can: called CC=2 SCAR=6.9
Pod undocumented
60 38 my ($self, $meth) = @_;
61 38 ▶ __PACKAGE__->import($ROLEMAP->{$meth}) if $ROLEMAP->{$meth};
Branch: 1 branch
BranchTrueFalseTotal
if $ROLEMAP->{$meth} 37 1 38
62 38 return $self->SUPER::can($meth);
63 }
64  
65 0 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
66  
67 117 ▶sub import {
Subroutine import: called CC=13 SCAR=25.7
68 117 my $class = shift;
69 117 foreach my $item (@_) {
70 74 ▶ next if $item =~ /^(load|1)$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $item =~ /^(load|1)$/i 6 68 74
71 68 ▶ if (lc $item eq 'all') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $item eq "all") 2 66 68
72 2 local $AUTOROLE->{'JS'}; delete $AUTOROLE->{'JS'};
73 2 return $class->import(keys %$AUTOROLE);
74 }
75  
76 66 my $type;
77 66 ▶ if ($type = $STANDIN{$item}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type = $STANDIN{$item}) 7 59 66
78 7 (my $file = "$item.pm") =~ s|::|/|g;
79 7 ▶ if (! $INC{$file} || ! $item->isa(__PACKAGE__)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($INC{$file} and $item->isa(__PACKAGE__)) 4 3 7
Condition100%3/3
$INC{$file} and $item->isa(__PACKAGE__)
!ll&&!rl&&r
313
MC/DC100%2/2
$INC{$file} and $item->isa(__PACKAGE__)
$INC{$file} $item->isa(__PACKAGE__)
Truth table100%3/3
A and B
A= $INC{$file}B= $item->isa(__PACKAGE__)
ABresult
0X0
100
111
80 4 ▶ if ($INC{$file}) { require Carp; Carp::croak("Class $item is already loaded - can't override") }
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{$file}) 1 3 4
81 3 eval "{package $item; our \@ISA = qw(".__PACKAGE__.");}";
82 3 $INC{$file} = __FILE__;
83 3 ▶ next if ! $AUTOROLE->{$type}; # already imported
Branch: 1 branch
BranchTrueFalseTotal
unless $Template::Alloy::AUTOROLE->{$type} 0 3 3
84 }
85 }
86 65 ▶ $type ||= $AUTOROLE->{$item} ? $item : $ROLEMAP->{$item} || do { require Carp; Carp::croak("Invalid import option \"$item\"") };
Branch: 1 branch
BranchTrueFalseTotal
$Template::Alloy::AUTOROLE->{$item} ? : 57 2 59
Condition66%4/6
$type ||= $Template::Alloy::AUTOROLE->{$item} ? $item : $ROLEMAP->{$item} || do { require Carp; Carp::croak(qq[Invalid import option "$item"]) }
l!l&&r!l&&!r
6590
$ROLEMAP->{$item} or do { require Carp; Carp::croak(qq[Invalid import option "$item"]) }
l!l&&r!l&&!r
110
MC/DC0%0/2
$type ||= $Template::Alloy::AUTOROLE->{$item} ? $item : $ROLEMAP->{$item} || do { require Carp; Carp::croak(qq[Invalid import option "$item"]) }
$type $Template::Alloy::AUTOROLE->{$item} ? $item : $ROLEMAP->{$item} || do { require Carp; Carp::croak(qq[Invalid import option "$item"]) }
MC/DC0%0/2
$ROLEMAP->{$item} or do { require Carp; Carp::croak(qq[Invalid import option "$item"]) }
$ROLEMAP->{$item} do { require Carp; Carp::croak(qq[Invalid import option "$item"]) }
Truth table66%2/3
A ||= B
A= $typeB= $Template::Alloy::AUTOROLE->{$item} ? $item : $ROLEMAP->{$item} || do { require Carp; Carp::croak(qq[Invalid import option "$item"]) }
ABresult
1X1
011
000
Truth table66%2/3
A or B
A= $ROLEMAP->{$item}B= do { require Carp; Carp::croak(qq[Invalid import option "$item"]) }
ABresult
1X1
011
000
87  
88 64 my $pkg = __PACKAGE__."::$type";
89 64 (my $file = "$pkg.pm") =~ s|::|/|g;
90 64 require $file;
91  
92 10 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
93 64 *{__PACKAGE__."::$_"} = \&{"$pkg\::$_"} for @{ $AUTOROLE->{$type} };
94 64 $AUTOROLE->{$type} = [];
95 }
96 113 return 1;
97 }
98  
99 ###----------------------------------------------------------------###
100  
101 4197 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
102 4197 my $class = shift;
103 4197 ▶ my $args = ref($_[0]) ? { %{ shift() } } : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 1 4196 4197
104  
105 ### allow for lowercase args
106 4197 ▶ if (my @keys = grep {/^[a-z][a-z_]+$/} keys %$args) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@keys) = grep({/^[a-z][a-z_]+$/;} keys %$args)) 253 3944 4197
107 253 @{ $args }{ map { uc $_ } @keys } = delete @{ $args }{ @keys };
108 }
109  
110 4197 return bless $args, $class;
111 }
112  
113 ###----------------------------------------------------------------###
114  
115 0 ▶sub run { shift->process_simple(@_) }
Subroutine run: not called CC=1 SCAR=6.9
Pod undocumented
116  
117 773 ▶sub process_simple {
Subroutine process_simple: called CC=10 SCAR=24.8
Pod documented
118 773 my $self = shift;
119 773 ▶ my $in = shift || die "Missing input";
Condition100%2/2
shift() || die('Missing input')
l!l
7721
MC/DC100%1/1
shift() || die('Missing input')
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
120 772 ▶ my $swap = shift || die "Missing variable hash";
Condition100%2/2
shift() || die('Missing variable hash')
l!l
7711
MC/DC100%1/1
shift() || die('Missing variable hash')
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
121 771 ▶ my $out = shift || ($self->{'STREAM'} ? \ "" : die "Missing output string ref");
Branch: 1 branch
BranchTrueFalseTotal
$self->{'STREAM'} ? : 0 1 1
Condition66%2/3
shift() || ($self->{'STREAM'} ? \'' : die('Missing output string ref'))
l!l&&r!l&&!r
77010
MC/DC0%0/2
shift() || ($self->{'STREAM'} ? \'' : die('Missing output string ref'))
shift() ($self->{'STREAM'} ? \'' : die('Missing output string ref'))
Truth table33%1/3
A || B
A= shift()B= ($self->{'STREAM'} ? \'' : die('Missing output string ref'))
ABresult
1X1
011
000
122 770 delete $self->{'error'};
123  
124 770 eval {
125 770 delete $self->{'_debug_off'};
126 770 delete $self->{'_debug_format'};
127 770 local $self->{'_start_top_level'} = 1;
128 770 $self->_process($in, $swap, $out);
129 };
130 770 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 40 730 770
131 40 ▶ if ($err->type !~ /stop|return|next|last|break/) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $err->type =~ /stop|return|next|last|break/) { } 40 0 40
elsif ($err->type eq 'return' and UNIVERSAL::isa($err->info, 'HASH')) { } 0 0 0
132 40 $self->{'error'} = $err;
133 40 ▶ die $err if $self->{'RAISE_ERROR'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"RAISE_ERROR"} 0 40 40
134 40 return;
135 ▶ } elsif ($err->type eq 'return' && UNIVERSAL::isa($err->info, 'HASH')) {
Condition0%0/3
$err->type eq "return" and UNIVERSAL::isa($err->info, "HASH")
!ll&&!rl&&r
000
MC/DC0%0/2
$err->type eq "return" and UNIVERSAL::isa($err->info, "HASH")
$err->type eq "return" UNIVERSAL::isa($err->info, "HASH")
Truth table0%0/3
A and B
A= $err->type eq "return"B= UNIVERSAL::isa($err->info, "HASH")
ABresult
0X0
100
111
136 0 return $err->info->{'return_val'};
137 }
138 }
139 730 return 1;
140 }
141  
142 5094 ▶sub _process {
Subroutine _process: called CC=23 SCAR=31.4
143 5094 my $self = shift;
144 5094 my $file = shift;
145 5094 ▶ local $self->{'_vars'} = shift || {};
Condition100%2/2
shift() || {}
l!l
50886
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
146 5094 ▶ my $out_ref = shift || $self->throw('undef', "Missing output ref");
Condition66%2/3
shift() || $self->throw('undef', 'Missing output ref')
l!l&&r!l&&!r
509310
MC/DC0%0/2
shift() || $self->throw('undef', 'Missing output ref')
shift() $self->throw('undef', 'Missing output ref')
Truth table33%1/3
A || B
A= shift()B= $self->throw('undef', 'Missing output ref')
ABresult
1X1
011
000
147 5093 local $self->{'_top_level'} = delete $self->{'_start_top_level'};
148 5093 my $i = length $$out_ref;
149  
150 ### parse and execute
151 5093 my $doc;
152 5093 eval {
153 5093 ▶ $doc = (ref($file) eq 'HASH') ? $file : $self->load_template($file);
Branch: 1 branch
BranchTrueFalseTotal
ref $file eq 'HASH' ? : 3 5090 5093
154  
155 ### prevent recursion
156 $self->throw('file', "recursion into '$doc->{name}'")
157 4919 ▶ if ! $self->{'RECURSION'} && $self->{'_in'}->{$doc->{'name'}} && $doc->{'name'} ne 'input text';
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"RECURSION"} and $self->{"_in"}{$doc->{"name"}} and $doc->{"name"} ne "input text" 6 4913 4919
Condition100%6/6
not $self->{"RECURSION"} and $self->{"_in"}{$doc->{"name"}} and $doc->{"name"} ne "input text"
!ll&&!rl&&r
47251886
not $self->{"RECURSION"} and $self->{"_in"}{$doc->{"name"}}
!ll&&!rl&&r
124713194
MC/DC100%3/3
not $self->{"RECURSION"} and $self->{"_in"}{$doc->{"name"}} and $doc->{"name"} ne "input text"
not $self->{"RECURSION"} $self->{"_in"}{$doc->{"name"}} $doc->{"name"} ne "input text"
Truth table100%4/4
not(A) and B and C
A= not $self->{"RECURSION"}B= $self->{"_in"}{$doc->{"name"}}C= $doc->{"name"} ne "input text"
ABCresult
0XX0
10X0
1100
1111
158  
159 4913 local $self->{'_in'}->{$doc->{'name'}} = 1;
160 4913 local $self->{'_component'} = $doc;
161 4913 ▶ local $self->{'_template'} = $self->{'_top_level'} ? $doc : $self->{'_template'};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_top_level'} ? : 4225 688 4913
162 4913 local @{ $self }{@CONFIG_RUNTIME} = @{ $self }{@CONFIG_RUNTIME};
163  
164 ### run the document however we can
165 4913 ▶ if ($self->{'STREAM'}) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->{'STREAM'}) { } 1356 3557 4913
elsif ($self->{'COMPILE_JS'}) { } 0 3557 3557
elsif ($doc->{'_perl'}) { } 1742 1815 3557
elsif ($doc->{'_tree'}) { } 1814 1 1815
166 1356 ▶ $self->throw('process', 'No _tree found') if ! $doc->{'_tree'};
Branch: 1 branch
BranchTrueFalseTotal
unless $doc->{"_tree"} 0 1356 1356
167 1356 $self->stream_tree($doc->{'_tree'});
168 } elsif ($self->{'COMPILE_JS'}) {
169 0 $self->play_js($doc, $out_ref);
170 } elsif ($doc->{'_perl'}) {
171 1742 $doc->{'_perl'}->{'code'}->($self, $out_ref);
172 } elsif ($doc->{'_tree'}) {
173 1814 $self->play_tree($doc->{'_tree'}, $out_ref);
174 } else {
175 1 $self->throw('process', 'No _perl and no _tree found');
176 }
177  
178 ### trim whitespace from the beginning and the end of a block or template
179 4718 ▶ if ($self->{'TRIM'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"TRIM"}) 27 4691 4718
180 27 substr($$out_ref, $i, length($$out_ref) - $i) =~ s{ \s+ $ }{}x; # tail first
181 27 substr($$out_ref, $i, length($$out_ref) - $i) =~ s{ ^ \s+ }{}x;
182 }
183 };
184  
185 ### handle exceptions
186 5093 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 375 4718 5093
187 375 ▶ $err = $self->exception('undef', $err) if ! UNIVERSAL::can($err, 'type');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::can($err, "type") 2 373 375
188 375 ▶ $err->doc($doc) if $doc && $err->can('doc') && ! $err->doc;
Branch: 1 branch
BranchTrueFalseTotal
if $doc and $err->can("doc") and not $err->doc 161 214 375
Condition83%5/6
$doc and $err->can("doc") and not $err->doc
!ll&&!rl&&r
17440161
$doc and $err->can("doc")
!ll&&!rl&&r
1740201
MC/DC66%2/3
$doc and $err->can("doc") and not $err->doc
$doc $err->can("doc") not $err->doc
Truth table75%3/4
A and B and not(C)
A= $docB= $err->can("doc")C= not $err->doc
ABCresult
0XX0
10X0
1100
1111
189 375 ▶ die $err if ! $self->{'_top_level'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_top_level"} 102 273 375
190 273 ▶ die $err if $err->type ne 'stop' && ($err->type ne 'return' || $err->info);
Branch: 1 branch
BranchTrueFalseTotal
if $err->type ne "stop" and $err->type ne "return" || $err->info 235 38 273
Condition83%5/6
$err->type ne "stop" and $err->type ne "return" || $err->info
!ll&&!rl&&r
2612235
$err->type ne "return" or $err->info
l!l&&r!l&&!r
235012
MC/DC66%2/3
$err->type ne "stop" and $err->type ne "return" || $err->info
$err->type ne "stop" $err->type ne "return" $err->info
Truth table75%3/4
A and B or C
A= $err->type ne "stop"B= $err->type ne "return"C= $err->info
ABCresult
0XX0
1000
11X1
1011
191 }
192  
193 4756 return 1;
194 }
195  
196 ###----------------------------------------------------------------###
197  
198 5245 ▶sub load_template {
Subroutine load_template: called CC=71 SCAR=46.6
Pod documented
199 5245 my ($self, $file) = @_;
200 5245 ▶ $self->throw('undef', 'Undefined file passed to load_template') if ! defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 1 5244 5245
201  
202 5244 ▶ my $docs = $self->{'GLOBAL_CACHE'} || ($self->{'_documents'} ||= {});
Condition80%4/5
$self->{'GLOBAL_CACHE'} || ($self->{'_documents'} ||= {})
l!l&&r!l&&!r
1452300
$self->{"_documents"} ||= {}
l!l
10584172
MC/DC0%0/2
$self->{'GLOBAL_CACHE'} || ($self->{'_documents'} ||= {})
$self->{'GLOBAL_CACHE'} ($self->{'_documents'} ||= {})
MC/DC100%1/1
$self->{"_documents"} ||= {}
$self->{"_documents"}
Truth table66%2/3
A || B
A= $self->{'GLOBAL_CACHE'}B= ($self->{'_documents'} ||= {})
ABresult
1X1
011
000
Truth table100%2/2
A
A= $self->{"_documents"}
Aresult
11
00
203 5244 ▶ $docs = $GLOBAL_CACHE if ! ref $docs;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $docs 13 5231 5244
204  
205 ### looks like a scalar ref
206 5244 my $doc;
207 5244 ▶ if (ref $file) {
Branch: 4 branches
BranchTrueFalseTotal
if (ref $file) { } 4477 767 5244
elsif ($docs->{$file}) { } 19 748 767
elsif ($self->{'_not_found'}{$file}) { } 9 739 748
elsif ($self->{'BLOCKS'}{$file}) { } 227 512 739
208 4477 ▶ return $file if ref $file eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $file eq "HASH" 1 4476 4477
209  
210 4476 ▶ if (! defined($self->{'CACHE_STR_REFS'}) || $self->{'CACHE_STR_REFS'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'CACHE_STR_REFS'} or $self->{'CACHE_STR_REFS'}) { } 4473 3 4476
Condition66%2/3
not defined $self->{"CACHE_STR_REFS"} or $self->{"CACHE_STR_REFS"}
l!l&&r!l&&!r
447303
MC/DC50%1/2
not defined $self->{"CACHE_STR_REFS"} or $self->{"CACHE_STR_REFS"}
not defined $self->{"CACHE_STR_REFS"} $self->{"CACHE_STR_REFS"}
Truth table66%2/3
not(A) or B
A= not defined $self->{"CACHE_STR_REFS"}B= $self->{"CACHE_STR_REFS"}
ABresult
1X1
011
000
211 4473 my $_file = $self->string_id($file);
212 4473 ▶ if ($docs->{$_file}) { # no-ttl necessary
Branch: 1 branch
BranchTrueFalseTotal
if ($docs->{$_file}) 193 4280 4473
213 193 $doc = $docs->{$_file};
214 193 ▶ $doc->{'_perl'} = $self->load_perl($doc) if ! $doc->{'_perl'} && $self->{'COMPILE_PERL'}; # second hit
Branch: 1 branch
BranchTrueFalseTotal
if not $doc->{"_perl"} and $self->{"COMPILE_PERL"} 2 191 193
Condition100%3/3
not $doc->{"_perl"} and $self->{"COMPILE_PERL"}
!ll&&!rl&&r
611302
MC/DC100%2/2
not $doc->{"_perl"} and $self->{"COMPILE_PERL"}
not $doc->{"_perl"} $self->{"COMPILE_PERL"}
Truth table100%3/3
not(A) and B
A= not $doc->{"_perl"}B= $self->{"COMPILE_PERL"}
ABresult
0X0
100
111
215 193 return $doc;
216 }
217 4280 $doc->{'_filename'} = $_file;
218 } else {
219 3 ▶ $doc->{'_no_perl'} = $self->{'FORCE_STR_REF_PERL'} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'FORCE_STR_REF_PERL'} ? : 1 2 3
220 }
221 4283 $doc->{'_is_str_ref'} = 1;
222 4283 $doc->{'_content'} = $file;
223 4283 $doc->{'name'} = 'input text';
224 4283 $doc->{'modtime'} = time;
225  
226 ### looks like a previously cached document
227 } elsif ($docs->{$file}) {
228 19 $doc = $docs->{$file};
229 19 ▶ if (time - $doc->{'cache_time'} < ($self->{'STAT_TTL'} || $STAT_TTL) # don't stat more than once a second
Branch: 1 branch
BranchTrueFalseTotal
if (time - $doc->{"cache_time"} < ($self->{"STAT_TTL"} || $Template::Alloy::STAT_TTL) or $doc->{"modtime"} == (stat $doc->{"_filename"})[9]) 19 0 19
Condition33%2/6
time - $doc->{"cache_time"} < ($self->{"STAT_TTL"} || $Template::Alloy::STAT_TTL) or $doc->{"modtime"} == (stat $doc->{"_filename"})[9]
l!l&&r!l&&!r
1900
$self->{'STAT_TTL'} || $Template::Alloy::STAT_TTL
l!l&&r!l&&!r
0190
MC/DC0%0/2
time - $doc->{"cache_time"} < ($self->{"STAT_TTL"} || $Template::Alloy::STAT_TTL) or $doc->{"modtime"} == (stat $doc->{"_filename"})[9]
time - $doc->{"cache_time"} < ($self->{"STAT_TTL"} || $Template::Alloy::STAT_TTL) $doc->{"modtime"} == (stat $doc->{"_filename"})[9]
MC/DC0%0/2
$self->{'STAT_TTL'} || $Template::Alloy::STAT_TTL
$self->{'STAT_TTL'} $Template::Alloy::STAT_TTL
Truth table33%1/3
A or B
A= time - $doc->{"cache_time"} < ($self->{"STAT_TTL"} || $Template::Alloy::STAT_TTL)B= $doc->{"modtime"} == (stat $doc->{"_filename"})[9]
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $self->{'STAT_TTL'}B= $Template::Alloy::STAT_TTL
ABresult
1X1
011
000
230 || $doc->{'modtime'} == (stat $doc->{'_filename'})[9]) { # otherwise see if the file was modified
231 19 ▶ $doc->{'_perl'} = $self->load_perl($doc) if ! $doc->{'_perl'} && $self->{'COMPILE_PERL'}; # second hit
Branch: 1 branch
BranchTrueFalseTotal
if not $doc->{"_perl"} and $self->{"COMPILE_PERL"} 1 18 19
Condition100%3/3
not $doc->{"_perl"} and $self->{"COMPILE_PERL"}
!ll&&!rl&&r
6121
MC/DC100%2/2
not $doc->{"_perl"} and $self->{"COMPILE_PERL"}
not $doc->{"_perl"} $self->{"COMPILE_PERL"}
Truth table100%3/3
not(A) and B
A= not $doc->{"_perl"}B= $self->{"COMPILE_PERL"}
ABresult
0X0
100
111
232 19 return $doc;
233 }
234 0 delete @$doc{qw(_tree modtime _content _line_offsets _perl _js)};
235  
236 ### looks like a previously cached not-found
237 } elsif ($self->{'_not_found'}->{$file}) {
238 9 $doc = $self->{'_not_found'}->{$file};
239 9 ▶ if (time - $doc->{'cache_time'} < ($self->{'NEGATIVE_STAT_TTL'} || $self->{'STAT_TTL'} || $STAT_TTL)) { # negative cache for a second
Branch: 1 branch
BranchTrueFalseTotal
if (time - $doc->{"cache_time"} < ($self->{"NEGATIVE_STAT_TTL"} || $self->{"STAT_TTL"} || $Template::Alloy::STAT_TTL)) 3 6 9
Condition50%3/6
$self->{'NEGATIVE_STAT_TTL'} || $self->{'STAT_TTL'} || $Template::Alloy::STAT_TTL
l!l&&r!l&&!r
900
$self->{"NEGATIVE_STAT_TTL"} or $self->{"STAT_TTL"}
l!l&&r!l&&!r
630
MC/DC0%0/3
$self->{'NEGATIVE_STAT_TTL'} || $self->{'STAT_TTL'} || $Template::Alloy::STAT_TTL
$self->{"NEGATIVE_STAT_TTL"} $self->{"STAT_TTL"} $Template::Alloy::STAT_TTL
Truth table50%2/4
A or B || C
A= $self->{"NEGATIVE_STAT_TTL"}B= $self->{"STAT_TTL"}C= $Template::Alloy::STAT_TTL
ABCresult
1XX1
01X1
0011
0000
240 3 die $doc->{'exception'};
241 }
242 6 delete $self->{'_not_found'}->{$file}; # clear cache on failure
243  
244 ### looks like a block passed in at runtime
245 } elsif ($self->{'BLOCKS'}->{$file}) {
246 227 my $block = $self->{'BLOCKS'}->{$file};
247 227 ▶ $block = $block->() if UNIVERSAL::isa($block, 'CODE');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($block, "CODE") 1 226 227
248 227 ▶ if (! UNIVERSAL::isa($block, 'HASH')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($block, "HASH")) 4 223 227
249 4 ▶ $self->throw('block', "Unsupported BLOCK type \"$block\"") if ref $block;
Branch: 1 branch
BranchTrueFalseTotal
if ref $block 1 3 4
250 3 ▶ $block = eval { $self->load_template(\$block) } || $self->throw('block', 'Parse error on predefined block');
Condition66%2/3
eval { do { $self->load_template(\$block) } } || $self->throw('block', 'Parse error on predefined block')
l!l&&r!l&&!r
201
MC/DC0%0/2
eval { do { $self->load_template(\$block) } } || $self->throw('block', 'Parse error on predefined block')
eval { do { $self->load_template(\$block) } } $self->throw('block', 'Parse error on predefined block')
Truth table33%1/3
A || B
A= eval { do { $self->load_template(\$block) } }B= $self->throw('block', 'Parse error on predefined block')
ABresult
1X1
011
000
251 }
252 225 ▶ $doc->{'name'} = ($block->{'name'} && $block->{'name'} ne 'input text') ? $block->{'name'} : $file;
Branch: 1 branch
BranchTrueFalseTotal
$block->{'name'} && $block->{'name'} ne 'input text' ? : 221 4 225
Condition100%3/3
$block->{"name"} and $block->{"name"} ne "input text"
!ll&&!rl&&r
13221
MC/DC100%2/2
$block->{"name"} and $block->{"name"} ne "input text"
$block->{"name"} $block->{"name"} ne "input text"
Truth table100%3/3
A and B
A= $block->{"name"}B= $block->{"name"} ne "input text"
ABresult
0X0
100
111
253 225 ▶ $doc->{'_filename'} = $block->{'_filename'} if $block->{'_filename'};
Branch: 1 branch
BranchTrueFalseTotal
if $block->{"_filename"} 224 1 225
254 225 ▶ if ($block->{'_perl'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($block->{'_perl'}) { } 77 148 225
elsif ($block->{'_tree'}) { } 147 1 148
255 77 $doc->{'_perl'} = $block->{'_perl'};
256 } elsif ($block->{'_tree'}) {
257 147 $doc->{'_tree'} = $block->{'_tree'};
258 } else {
259 1 $self->throw('block', "Invalid block definition (missing tree)");
260 }
261 224 return $doc;
262 }
263  
264 ### lookup the filename
265 4801 ▶ if (! $doc->{'_filename'} && ! ref $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($doc->{"_filename"} or ref $file) 518 4283 4801
Condition100%3/3
$doc->{"_filename"} or ref $file
l!l&&r!l&&!r
42803518
MC/DC100%2/2
$doc->{"_filename"} or ref $file
$doc->{"_filename"} ref $file
Truth table100%3/3
A or B
A= $doc->{"_filename"}B= ref $file
ABresult
1X1
011
000
266 518 $doc->{'name'} = $file;
267 518 $doc->{'_filename'} = eval { $self->include_filename($file) };
268 518 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 51 467 518
269 ### allow for blocks in other files
270 51 ▶ if ($self->{'EXPOSE_BLOCKS'} && ! $self->{'_looking_in_block_file'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'EXPOSE_BLOCKS'} and not $self->{'_looking_in_block_file'}) { } 18 33 51
elsif ($self->{'DEFAULT'}) { } 0 33 33
Condition66%2/3
$self->{"EXPOSE_BLOCKS"} and not $self->{"_looking_in_block_file"}
!ll&&!rl&&r
33018
MC/DC50%1/2
$self->{"EXPOSE_BLOCKS"} and not $self->{"_looking_in_block_file"}
$self->{"EXPOSE_BLOCKS"} not $self->{"_looking_in_block_file"}
Truth table66%2/3
A and not(B)
A= $self->{"EXPOSE_BLOCKS"}B= not $self->{"_looking_in_block_file"}
ABresult
0X0
100
111
271 18 local $self->{'_looking_in_block_file'} = 1;
272 18 my $block_name = '';
273 18 ▶ OUTER: while ($file =~ s|/([^/.]+)$||) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ s[/([^/.]+)$][]) 12 6 18
274 12 ▶ $block_name = length($block_name) ? "$1/$block_name" : $1;
Branch: 1 branch
BranchTrueFalseTotal
length $block_name ? : 0 12 12
275 12 ▶ my $ref = eval { $self->load_template($file) } || next;
Condition50%1/2
eval { do { $self->load_template($file) } } || (next)
l!l
120
MC/DC0%0/1
eval { do { $self->load_template($file) } } || (next)
eval { do { $self->load_template($file) } }
Truth table50%1/2
A
A= eval { do { $self->load_template($file) } }
Aresult
11
00
276 12 my $_tree = $ref->{'_tree'};
277 12 foreach my $node (@$_tree) {
278 30 ▶ last if ! ref $node;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $node 0 30 30
279 30 ▶ next if $node->[0] eq 'META';
Branch: 1 branch
BranchTrueFalseTotal
if $node->[0] eq "META" 12 18 30
280 18 ▶ last if $node->[0] ne 'BLOCK';
Branch: 1 branch
BranchTrueFalseTotal
if $node->[0] ne "BLOCK" 0 18 18
281 18 ▶ next if $block_name ne $node->[3];
Branch: 1 branch
BranchTrueFalseTotal
if $block_name ne $node->[3] 6 12 18
282 12 $doc->{'_tree'} = $node->[4];
283 12 @{$doc}{qw(modtime _content)} = @{$ref}{qw(modtime _content)};
284 $doc->{'_perl'} = {
285 meta => {},
286 blocks => {},
287 code => $ref->{'_perl'}->{'blocks'}->{$block_name}->{'_perl'}->{'code'},
288 12 ▶ } if $ref->{'_perl'} && $ref->{'_perl'}->{'blocks'} && $ref->{'_perl'}->{'blocks'}->{$block_name};
Branch: 1 branch
BranchTrueFalseTotal
if $ref->{"_perl"} and $ref->{"_perl"}{"blocks"} and $ref->{"_perl"}{"blocks"}{$block_name} 4 8 12
Condition66%4/6
$ref->{"_perl"} and $ref->{"_perl"}{"blocks"} and $ref->{"_perl"}{"blocks"}{$block_name}
!ll&&!rl&&r
804
$ref->{"_perl"} and $ref->{"_perl"}{"blocks"}
!ll&&!rl&&r
804
MC/DC33%1/3
$ref->{"_perl"} and $ref->{"_perl"}{"blocks"} and $ref->{"_perl"}{"blocks"}{$block_name}
$ref->{"_perl"} $ref->{"_perl"}{"blocks"} $ref->{"_perl"}{"blocks"}{$block_name}
Truth table50%2/4
A and B and C
A= $ref->{"_perl"}B= $ref->{"_perl"}{"blocks"}C= $ref->{"_perl"}{"blocks"}{$block_name}
ABCresult
0XX0
10X0
1100
1111
289 12 ▶ $doc->{'_js'} = $self->load_js($doc) if $self->{'COMPILE_JS'} && $ref->{'_js'}; # have to regenerate because block is buried in js
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"COMPILE_JS"} and $ref->{"_js"} 0 12 12
Condition33%1/3
$self->{"COMPILE_JS"} and $ref->{"_js"}
!ll&&!rl&&r
1200
MC/DC0%0/2
$self->{"COMPILE_JS"} and $ref->{"_js"}
$self->{"COMPILE_JS"} $ref->{"_js"}
Truth table33%1/3
A and B
A= $self->{"COMPILE_JS"}B= $ref->{"_js"}
ABresult
0X0
100
111
290 12 return $doc;
291 }
292 }
293 } elsif ($self->{'DEFAULT'}) {
294 0 ▶ $err = '' if ($doc->{'_filename'} = eval { $self->include_filename($self->{'DEFAULT'}) });
Branch: 1 branch
BranchTrueFalseTotal
if $doc->{"_filename"} = eval { do { $self->include_filename($self->{"DEFAULT"}) } } 0 0 0
295 }
296 39 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 39 0 39
297 ### cache the negative error
298 39 ▶ if (! defined($self->{'NEGATIVE_STAT_TTL'}) || $self->{'NEGATIVE_STAT_TTL'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"NEGATIVE_STAT_TTL"} or $self->{"NEGATIVE_STAT_TTL"}) 39 0 39
Condition66%2/3
not defined $self->{"NEGATIVE_STAT_TTL"} or $self->{"NEGATIVE_STAT_TTL"}
l!l&&r!l&&!r
3090
MC/DC0%0/2
not defined $self->{"NEGATIVE_STAT_TTL"} or $self->{"NEGATIVE_STAT_TTL"}
not defined $self->{"NEGATIVE_STAT_TTL"} $self->{"NEGATIVE_STAT_TTL"}
Truth table66%2/3
not(A) or B
A= not defined $self->{"NEGATIVE_STAT_TTL"}B= $self->{"NEGATIVE_STAT_TTL"}
ABresult
1X1
011
000
299 39 ▶ $err = $self->exception('undef', $err) if ! UNIVERSAL::can($err, 'type');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::can($err, "type") 0 39 39
300 39 $self->{'_not_found'}->{$file} = {
301 cache_time => time,
302 exception => $self->exception($err->type, $err->info." (cached)"),
303 };
304 }
305 39 die $err;
306 }
307 }
308 }
309  
310 ### return perl - if they want perl - otherwise - the ast
311 4750 ▶ if (! $doc->{'_no_perl'} && $self->{'COMPILE_PERL'} && ($self->{'COMPILE_PERL'} ne '2' || $self->{'_tree'})) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $doc->{'_no_perl'} and $self->{'COMPILE_PERL'} and $self->{'COMPILE_PERL'} ne '2' || $self->{'_tree'}) { } 1690 3060 4750
elsif ($self->{'COMPILE_JS'}) { } 0 3060 3060
Condition88%8/9
not $doc->{"_no_perl"} and $self->{"COMPILE_PERL"} and $self->{"COMPILE_PERL"} ne 2 || $self->{"_tree"}
!ll&&!rl&&r
305821690
not $doc->{"_no_perl"} and $self->{"COMPILE_PERL"}
!ll&&!rl&&r
230561692
$self->{"COMPILE_PERL"} ne 2 or $self->{"_tree"}
l!l&&r!l&&!r
169002
MC/DC75%3/4
not $doc->{"_no_perl"} and $self->{"COMPILE_PERL"} and $self->{"COMPILE_PERL"} ne 2 || $self->{"_tree"}
not $doc->{"_no_perl"} $self->{"COMPILE_PERL"} $self->{"COMPILE_PERL"} ne 2 $self->{"_tree"}
Truth table80%4/5
not(A) and B and C or D
A= not $doc->{"_no_perl"}B= $self->{"COMPILE_PERL"}C= $self->{"COMPILE_PERL"} ne 2D= $self->{"_tree"}
ABCDresult
0XXX0
10XX0
11000
111X1
11011
312 1690 $doc->{'_perl'} = $self->load_perl($doc);
313 } elsif ($self->{'COMPILE_JS'}) {
314 0 $self->load_js($doc);
315 } else {
316 3060 $doc->{'_tree'} = $self->load_tree($doc);
317 }
318  
319 ### cache parsed_tree in memory unless asked not to do so
320 4617 ▶ if (! defined($self->{'CACHE_SIZE'}) || $self->{'CACHE_SIZE'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"CACHE_SIZE"} or $self->{"CACHE_SIZE"}) 4365 252 4617
Condition66%2/3
not defined $self->{"CACHE_SIZE"} or $self->{"CACHE_SIZE"}
l!l&&r!l&&!r
43650252
MC/DC50%1/2
not defined $self->{"CACHE_SIZE"} or $self->{"CACHE_SIZE"}
not defined $self->{"CACHE_SIZE"} $self->{"CACHE_SIZE"}
Truth table66%2/3
not(A) or B
A= not defined $self->{"CACHE_SIZE"}B= $self->{"CACHE_SIZE"}
ABresult
1X1
011
000
321 4365 $doc->{'cache_time'} = time;
322 4365 ▶ if (ref $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $file) { } 3920 445 4365
323 3920 ▶ $docs->{$doc->{'_filename'}} = $doc if $doc->{'_filename'};
Branch: 1 branch
BranchTrueFalseTotal
if $doc->{"_filename"} 3917 3 3920
324 } else {
325 445 ▶ $docs->{$file} ||= $doc;
Condition33%1/3
$docs->{$file} ||= $doc
l!l&&r!l&&!r
04450
MC/DC0%0/2
$docs->{$file} ||= $doc
$docs->{$file} $doc
Truth table33%1/3
A ||= B
A= $docs->{$file}B= $doc
ABresult
1X1
011
000
326 }
327  
328 ### allow for config option to keep the cache size down
329 4365 ▶ if ($self->{'CACHE_SIZE'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CACHE_SIZE"}) 0 4365 4365
330 0 ▶ if (scalar(keys %$docs) > $self->{'CACHE_SIZE'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$docs > $self->{"CACHE_SIZE"}) 0 0 0
331 0 my $n = 0;
332 0 foreach my $file (sort {$docs->{$b}->{'cache_time'} <=> $docs->{$a}->{'cache_time'}} keys %$docs) {
333 0 ▶ delete($docs->{$file}) if ++$n > $self->{'CACHE_SIZE'};
Branch: 1 branch
BranchTrueFalseTotal
if ++$n > $self->{"CACHE_SIZE"} 0 0 0
334 }
335 }
336 }
337 }
338  
339 4617 return $doc;
340 }
341  
342 4474 ▶sub string_id {
Subroutine string_id: called CC=5 SCAR=16.2
Pod undocumented
343 4474 my ($self, $ref) = @_;
344 4474 require Digest::MD5;
345 my $str = ref($self)
346 && $self->{'ENCODING'} # ENCODING is defined
347 1 && eval { require Encode } # Encode.pm is available
348 && defined &Encode::encode
349 4474 ▶ ? Encode::encode($self->{'ENCODING'}, $$ref)
Branch: 1 branch
BranchTrueFalseTotal
ref $self && $self->{'ENCODING'} && eval { do { require Encode } } && defined &Encode::encode ? : 1 4473 4474
Condition77%7/9
ref $self and $self->{"ENCODING"} and eval { do { require Encode } } and defined &Encode::encode
!ll&&!rl&&r
447301
ref $self and $self->{"ENCODING"} and eval { do { require Encode } }
!ll&&!rl&&r
447301
ref $self and $self->{"ENCODING"}
!ll&&!rl&&r
144721
MC/DC50%2/4
ref $self and $self->{"ENCODING"} and eval { do { require Encode } } and defined &Encode::encode
ref $self $self->{"ENCODING"} eval { do { require Encode } } defined &Encode::encode
Truth table60%3/5
A and B and C and D
A= ref $selfB= $self->{"ENCODING"}C= eval { do { require Encode } }D= defined &Encode::encode
ABCDresult
0XXX0
10XX0
110X0
11100
11111
350 : $$ref;
351 4474 my $sum = Digest::MD5::md5_hex($str);
352 4474 return 'Alloy_str_ref_cache/'.substr($sum,0,3).'/'.$sum;
353 }
354  
355 4749 ▶sub load_tree {
Subroutine load_tree: called CC=23 SCAR=32.3
Pod documented
356 4749 my ($self, $doc) = @_;
357  
358 ### first look for a compiled optree
359 4749 ▶ if ($doc->{'_filename'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doc->{"_filename"}) 4746 3 4749
360 4746 ▶ $doc->{'modtime'} ||= (stat $doc->{'_filename'})[9];
Condition66%2/3
$doc->{"modtime"} ||= (stat $doc->{"_filename"})[9]
l!l&&r!l&&!r
44433030
MC/DC0%0/2
$doc->{"modtime"} ||= (stat $doc->{"_filename"})[9]
$doc->{"modtime"} (stat $doc->{"_filename"})[9]
Truth table66%2/3
A ||= B
A= $doc->{"modtime"}B= (stat $doc->{"_filename"})[9]
ABresult
1X1
011
000
361 4746 ▶ if ($self->{'COMPILE_DIR'} || $self->{'COMPILE_EXT'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"COMPILE_DIR"} or $self->{"COMPILE_EXT"}) 16 4730 4746
Condition100%3/3
$self->{"COMPILE_DIR"} or $self->{"COMPILE_EXT"}
l!l&&r!l&&!r
884730
MC/DC100%2/2
$self->{"COMPILE_DIR"} or $self->{"COMPILE_EXT"}
$self->{"COMPILE_DIR"} $self->{"COMPILE_EXT"}
Truth table100%3/3
A or B
A= $self->{"COMPILE_DIR"}B= $self->{"COMPILE_EXT"}
ABresult
1X1
011
000
362 16 my $file = $doc->{'_filename'};
363 16 ▶ if ($self->{'COMPILE_DIR'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'COMPILE_DIR'}) { } 8 8 16
elsif ($doc->{'_is_str_ref'}) { } 2 6 8
364 8 ▶ $file =~ y|:|/| if $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 8 8
365 8 $file = $self->{'COMPILE_DIR'} .'/'. $file;
366 } elsif ($doc->{'_is_str_ref'}) {
367 2 ▶ $file = ($self->include_paths->[0] || '.') .'/'. $file;
Condition50%1/2
$self->include_paths->[0] || '.'
l!l
20
MC/DC0%0/1
$self->include_paths->[0] || '.'
$self->include_paths->[0]
Truth table50%1/2
A
A= $self->include_paths->[0]
Aresult
11
00
368 }
369 16 ▶ $file .= $self->{'COMPILE_EXT'} if defined($self->{'COMPILE_EXT'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"COMPILE_EXT"} 12 4 16
370 16 ▶ $file .= $EXTRA_COMPILE_EXT if defined $EXTRA_COMPILE_EXT;
Branch: 1 branch
BranchTrueFalseTotal
if defined $Template::Alloy::EXTRA_COMPILE_EXT 16 0 16
371  
372 16 ▶ if (-e $file && ($doc->{'_is_str_ref'} || (stat $file)[9] == $doc->{'modtime'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $file and $doc->{"_is_str_ref"} || (stat $file)[9] == $doc->{"modtime"}) 1 15 16
Condition50%3/6
-e $file and $doc->{"_is_str_ref"} || (stat $file)[9] == $doc->{"modtime"}
!ll&&!rl&&r
1501
$doc->{"_is_str_ref"} or (stat $file)[9] == $doc->{"modtime"}
l!l&&r!l&&!r
010
MC/DC33%1/3
-e $file and $doc->{"_is_str_ref"} || (stat $file)[9] == $doc->{"modtime"}
-e $file $doc->{"_is_str_ref"} (stat $file)[9] == $doc->{"modtime"}
Truth table50%2/4
A and B or C
A= -e $fileB= $doc->{"_is_str_ref"}C= (stat $file)[9] == $doc->{"modtime"}
ABCresult
0XX0
1000
11X1
1011
373 1 require Storable;
374 1 return Storable::retrieve($file);
375 }
376 15 $doc->{'_storable_filename'} = $file;
377 }
378 }
379  
380 ### no cached tree - we will need to load our own
381 4748 ▶ $doc->{'_content'} ||= $self->slurp($doc->{'_filename'});
Condition66%2/3
$doc->{"_content"} ||= $self->slurp($doc->{"_filename"})
l!l&&r!l&&!r
42834650
MC/DC0%0/2
$doc->{"_content"} ||= $self->slurp($doc->{"_filename"})
$doc->{"_content"} $self->slurp($doc->{"_filename"})
Truth table66%2/3
A ||= B
A= $doc->{"_content"}B= $self->slurp($doc->{"_filename"})
ABresult
1X1
011
000
382  
383 4748 ▶ if ($self->{'CONSTANTS'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CONSTANTS"}) 33 4715 4748
384 33 ▶ my $key = $self->{'CONSTANT_NAMESPACE'} || 'constants';
Condition50%1/2
$self->{'CONSTANT_NAMESPACE'} || 'constants'
l!l
033
MC/DC0%0/1
$self->{'CONSTANT_NAMESPACE'} || 'constants'
$self->{'CONSTANT_NAMESPACE'}
Truth table50%1/2
A
A= $self->{'CONSTANT_NAMESPACE'}
Aresult
11
00
385 33 ▶ $self->{'NAMESPACE'}->{$key} ||= $self->{'CONSTANTS'};
Condition33%1/3
$self->{"NAMESPACE"}{$key} ||= $self->{"CONSTANTS"}
l!l&&r!l&&!r
0330
MC/DC0%0/2
$self->{"NAMESPACE"}{$key} ||= $self->{"CONSTANTS"}
$self->{"NAMESPACE"}{$key} $self->{"CONSTANTS"}
Truth table33%1/3
A ||= B
A= $self->{"NAMESPACE"}{$key}B= $self->{"CONSTANTS"}
ABresult
1X1
011
000
386 }
387  
388 4748 local $self->{'_component'} = $doc;
389 4748 my $tree = eval { $self->parse_tree($doc->{'_content'}) }
390 4748 ▶ || do { my $e = $@; $e->doc($doc) if UNIVERSAL::can($e, 'doc') && ! $e->doc; die $e }; # errors die
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($e, "doc") and not $e->doc 133 0 133
Condition66%4/6
eval { do { $self->parse_tree($doc->{'_content'}) } } || do { my $e = $@; $e->doc($doc) if UNIVERSAL::can($e, 'doc') and not $e->doc; die $e }
l!l&&r!l&&!r
46151321
UNIVERSAL::can($e, "doc") and not $e->doc
!ll&&!rl&&r
00133
MC/DC0%0/2
eval { do { $self->parse_tree($doc->{'_content'}) } } || do { my $e = $@; $e->doc($doc) if UNIVERSAL::can($e, 'doc') and not $e->doc; die $e }
eval { do { $self->parse_tree($doc->{'_content'}) } } do { my $e = $@; $e->doc($doc) if UNIVERSAL::can($e, 'doc') and not $e->doc; die $e }
MC/DC0%0/2
UNIVERSAL::can($e, "doc") and not $e->doc
UNIVERSAL::can($e, "doc") not $e->doc
Truth table33%1/3
A || B
A= eval { do { $self->parse_tree($doc->{'_content'}) } }B= do { my $e = $@; $e->doc($doc) if UNIVERSAL::can($e, 'doc') and not $e->doc; die $e }
ABresult
1X1
011
000
Truth table33%1/3
A and not(B)
A= UNIVERSAL::can($e, "doc")B= not $e->doc
ABresult
0X0
100
111
391  
392 ### save a cache on the fileside as asked
393 4615 ▶ if ($doc->{'_storable_filename'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doc->{"_storable_filename"}) 15 4600 4615
394 15 my $dir = $doc->{'_storable_filename'};
395 15 $dir =~ s|/[^/]+$||;
396 15 ▶ if (! -d $dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir) 10 5 15
397 10 require File::Path;
398 10 File::Path::mkpath($dir);
399 }
400 15 require Storable;
401 15 Storable::store($tree, $doc->{'_storable_filename'});
402 15 utime $doc->{'modtime'}, $doc->{'modtime'}, $doc->{'_storable_filename'};
403 }
404  
405 4615 return $tree;
406 }
407  
408 ###----------------------------------------------------------------###
409  
410 ### allow for resolving full expression ASTs
411 27283 ▶sub play_expr {
Subroutine play_expr: called CC=118 SCAR=53.6
Pod documented
412 27283 ▶ return $_[1] if ! ref $_[1]; # allow for the parse tree to store literals
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[1] 9037 18246 27283
413  
414 18246 my $self = shift;
415 18246 my $var = shift;
416 18246 ▶ my $ARGS = shift || {};
Condition100%2/2
shift() || {}
l!l
10518141
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
417 18246 my $i = 0;
418  
419 ### determine the top level of this particular variable access
420 18246 my $ref;
421 18246 my $name = $var->[$i++];
422 18246 my $args = $var->[$i++];
423 18246 ▶ if (ref $name) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $name) { } 9142 9104 18246
elsif (defined $name) { } 9104 0 9104
424 9142 ▶ if (! defined $name->[0]) { # operator
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $name->[0]) { } 8968 174 9142
425 8968 ▶ return $self->play_operator($name) if wantarray && $name->[1] eq '..';
Branch: 1 branch
BranchTrueFalseTotal
if wantarray and $name->[1] eq ".." 192 8776 8968
Condition100%3/3
wantarray and $name->[1] eq ".."
!ll&&!rl&&r
8461315192
MC/DC100%2/2
wantarray and $name->[1] eq ".."
wantarray $name->[1] eq ".."
Truth table100%3/3
A and B
A= wantarrayB= $name->[1] eq ".."
ABresult
0X0
100
111
426 8776 ▶ $ref = ($name->[1] eq '-temp-') ? $name->[2] : $self->play_operator($name);
Branch: 1 branch
BranchTrueFalseTotal
$name->[1] eq '-temp-' ? : 108 8668 8776
427 } else { # a named variable access (ie via $name.foo)
428 174 $name = $self->play_expr($name);
429 174 ▶ if (defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) 174 0 174
430 174 ▶ return if $QR_PRIVATE && $name =~ $QR_PRIVATE; # don't allow vars that begin with _
Branch: 1 branch
BranchTrueFalseTotal
if $Template::Alloy::QR_PRIVATE and $name =~ /$Template::Alloy::QR_PRIVATE/ 3 171 174
Condition66%2/3
$Template::Alloy::QR_PRIVATE and $name =~ /$Template::Alloy::QR_PRIVATE/
!ll&&!rl&&r
01713
MC/DC50%1/2
$Template::Alloy::QR_PRIVATE and $name =~ /$Template::Alloy::QR_PRIVATE/
$Template::Alloy::QR_PRIVATE $name =~ /$Template::Alloy::QR_PRIVATE/
Truth table66%2/3
A and B
A= $Template::Alloy::QR_PRIVATEB= $name =~ /$Template::Alloy::QR_PRIVATE/
ABresult
0X0
100
111
431 171 ▶ return \$self->{'_vars'}->{$name} if $i >= $#$var && $ARGS->{'return_ref'} && ! ref $self->{'_vars'}->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $var->$#* and $ARGS->{"return_ref"} and not ref $self->{"_vars"}{$name} 0 171 171
Condition50%3/6
$i >= $var->$#* and $ARGS->{"return_ref"} and not ref $self->{"_vars"}{$name}
!ll&&!rl&&r
17100
$i >= $var->$#* and $ARGS->{"return_ref"}
!ll&&!rl&&r
601110
MC/DC0%0/3
$i >= $var->$#* and $ARGS->{"return_ref"} and not ref $self->{"_vars"}{$name}
$i >= $var->$#* $ARGS->{"return_ref"} not ref $self->{"_vars"}{$name}
Truth table50%2/4
A and B and not(C)
A= $i >= $var->$#*B= $ARGS->{"return_ref"}C= not ref $self->{"_vars"}{$name}
ABCresult
0XX0
10X0
1100
1111
432 171 $ref = $self->{'_vars'}->{$name};
433 }
434 }
435 } elsif (defined $name) {
436 9104 ▶ return if $QR_PRIVATE && $name =~ $QR_PRIVATE; # don't allow vars that begin with _
Branch: 1 branch
BranchTrueFalseTotal
if $Template::Alloy::QR_PRIVATE and $name =~ /$Template::Alloy::QR_PRIVATE/ 15 9089 9104
Condition100%3/3
$Template::Alloy::QR_PRIVATE and $name =~ /$Template::Alloy::QR_PRIVATE/
!ll&&!rl&&r
526856315
MC/DC100%2/2
$Template::Alloy::QR_PRIVATE and $name =~ /$Template::Alloy::QR_PRIVATE/
$Template::Alloy::QR_PRIVATE $name =~ /$Template::Alloy::QR_PRIVATE/
Truth table100%3/3
A and B
A= $Template::Alloy::QR_PRIVATEB= $name =~ /$Template::Alloy::QR_PRIVATE/
ABresult
0X0
100
111
437 9089 ▶ return \$self->{'_vars'}->{$name} if $i >= $#$var && $ARGS->{'return_ref'} && ! ref $self->{'_vars'}->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $var->$#* and $ARGS->{"return_ref"} and not ref $self->{"_vars"}{$name} 6 9083 9089
Condition100%6/6
$i >= $var->$#* and $ARGS->{"return_ref"} and not ref $self->{"_vars"}{$name}
!ll&&!rl&&r
9068156
$i >= $var->$#* and $ARGS->{"return_ref"}
!ll&&!rl&&r
2209685921
MC/DC100%3/3
$i >= $var->$#* and $ARGS->{"return_ref"} and not ref $self->{"_vars"}{$name}
$i >= $var->$#* $ARGS->{"return_ref"} not ref $self->{"_vars"}{$name}
Truth table100%4/4
A and B and not(C)
A= $i >= $var->$#*B= $ARGS->{"return_ref"}C= not ref $self->{"_vars"}{$name}
ABCresult
0XX0
10X0
1100
1111
438 9083 $ref = $self->{'_vars'}->{$name};
439 9083 ▶ if (! defined $ref) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ref) 811 8272 9083
440 811 ▶ $ref = ($name eq 'template' || $name eq 'component') ? $self->{"_$name"} : $VOBJS->{$name};
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'template' || $name eq 'component' ? : 175 636 811
Condition100%3/3
$name eq "template" or $name eq "component"
l!l&&r!l&&!r
13639636
MC/DC100%2/2
$name eq "template" or $name eq "component"
$name eq "template" $name eq "component"
Truth table100%3/3
A or B
A= $name eq "template"B= $name eq "component"
ABresult
1X1
011
000
441 811 ▶ $ref = $ITEM_METHODS->{$name} || $ITEM_OPS->{$name} if ! $ref && (! defined($self->{'VMETHOD_FUNCTIONS'}) || $self->{'VMETHOD_FUNCTIONS'});
Branch: 1 branch
BranchTrueFalseTotal
if not $ref and !defined($self->{"VMETHOD_FUNCTIONS"}) || $self->{"VMETHOD_FUNCTIONS"} 603 208 811
Condition88%8/9
not $ref and !defined($self->{"VMETHOD_FUNCTIONS"}) || $self->{"VMETHOD_FUNCTIONS"}
!ll&&!rl&&r
2026603
not defined $self->{"VMETHOD_FUNCTIONS"} or $self->{"VMETHOD_FUNCTIONS"}
l!l&&r!l&&!r
60036
$Template::Alloy::ITEM_METHODS->{$name} || $Template::Alloy::ITEM_OPS->{$name}
l!l&&r!l&&!r
036567
MC/DC0%0/3
not $ref and !defined($self->{"VMETHOD_FUNCTIONS"}) || $self->{"VMETHOD_FUNCTIONS"}
not $ref not defined $self->{"VMETHOD_FUNCTIONS"} $self->{"VMETHOD_FUNCTIONS"}
MC/DC50%1/2
$Template::Alloy::ITEM_METHODS->{$name} || $Template::Alloy::ITEM_OPS->{$name}
$Template::Alloy::ITEM_METHODS->{$name} $Template::Alloy::ITEM_OPS->{$name}
Truth table0%0/4
not(A) and not(B) or C
A= not $refB= not defined $self->{"VMETHOD_FUNCTIONS"}C= $self->{"VMETHOD_FUNCTIONS"}
ABCresult
0XX0
1000
11X1
1011
Truth table66%2/3
A || B
A= $Template::Alloy::ITEM_METHODS->{$name}B= $Template::Alloy::ITEM_OPS->{$name}
ABresult
1X1
011
000
442 811 ▶ $ref = $self->{'_vars'}->{lc $name} if ! defined $ref && $self->{'LOWER_CASE_VAR_FALLBACK'};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ref and $self->{"LOWER_CASE_VAR_FALLBACK"} 59 752 811
Condition100%3/3
not defined $ref and $self->{"LOWER_CASE_VAR_FALLBACK"}
!ll&&!rl&&r
23851459
MC/DC100%2/2
not defined $ref and $self->{"LOWER_CASE_VAR_FALLBACK"}
not defined $ref $self->{"LOWER_CASE_VAR_FALLBACK"}
Truth table100%3/3
not(A) and B
A= not defined $refB= $self->{"LOWER_CASE_VAR_FALLBACK"}
ABresult
0X0
100
111
443 }
444 }
445  
446 18030 my %seen_filters;
447 18030 ▶ while (defined $ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref) 20225 762 20987
448  
449 ### check at each point if the returned thing was a code
450 20225 ▶ if (UNIVERSAL::isa($ref, 'CODE')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($ref, "CODE")) 547 19678 20225
451 547 ▶ return $ref if $i >= $#$var && $ARGS->{'return_ref'};
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $var->$#* and $ARGS->{"return_ref"} 15 532 547
Condition100%3/3
$i >= $var->$#* and $ARGS->{"return_ref"}
!ll&&!rl&&r
2750515
MC/DC100%2/2
$i >= $var->$#* and $ARGS->{"return_ref"}
$i >= $var->$#* $ARGS->{"return_ref"}
Truth table100%3/3
A and B
A= $i >= $var->$#*B= $ARGS->{"return_ref"}
ABresult
0X0
100
111
452 532 ▶ my @args = $args ? map { $self->play_expr($_) } @$args : ();
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 161 371 532
453 532 ▶ my $type = $self->{'CALL_CONTEXT'} || '';
Condition100%2/2
$self->{'CALL_CONTEXT'} || ''
l!l
81451
MC/DC100%1/1
$self->{'CALL_CONTEXT'} || ''
$self->{'CALL_CONTEXT'}
Truth table100%2/2
A
A= $self->{'CALL_CONTEXT'}
Aresult
11
00
454 532 ▶ if ($type eq 'item') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'item') { } 39 493 532
455 39 $ref = $ref->(@args);
456 } else {
457 493 my @results = $ref->(@args);
458 490 ▶ if ($type eq 'list') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'list') { } 33 457 490
elsif (defined $results[0]) { } 453 4 457
elsif (defined $results[1]) { } 0 4 4
459 33 $ref = \@results;
460 } elsif (defined $results[0]) {
461 453 ▶ $ref = ($#results > 0) ? \@results : $results[0];
Branch: 1 branch
BranchTrueFalseTotal
$#results > 0 ? : 21 432 453
462 } elsif (defined $results[1]) {
463 0 die $results[1]; # TT behavior - why not just throw ?
464 } else {
465 4 $ref = undef;
466 4 last;
467 }
468 }
469 }
470  
471 ### descend one chained level
472 20203 ▶ last if $i >= $#$var;
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $var->$#* 17172 3031 20203
473 3031 ▶ my $was_dot_call = $ARGS->{'no_dots'} ? 1 : $var->[$i++] eq '.';
Branch: 1 branch
BranchTrueFalseTotal
$ARGS->{'no_dots'} ? : 0 3031 3031
474 3031 $name = $var->[$i++];
475 3031 $args = $var->[$i++];
476  
477 ### allow for named portions of a variable name (foo.$name.bar)
478 3031 ▶ if (ref $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $name) 48 2983 3031
479 48 ▶ if (ref($name) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $name eq 'ARRAY') { } 48 0 48
480 48 $name = $self->play_expr($name);
481 48 ▶ if (! defined($name) || ($QR_PRIVATE && $name =~ $QR_PRIVATE) || $name =~ /^\./) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $name or $Template::Alloy::QR_PRIVATE and $name =~ /$Template::Alloy::QR_PRIVATE/ or $name =~ /^\./) 0 48 48
Condition33%3/9
not defined $name or $Template::Alloy::QR_PRIVATE and $name =~ /$Template::Alloy::QR_PRIVATE/ or $name =~ /^\./
l!l&&r!l&&!r
0048
not defined $name or $Template::Alloy::QR_PRIVATE and $name =~ /$Template::Alloy::QR_PRIVATE/
l!l&&r!l&&!r
0048
$Template::Alloy::QR_PRIVATE and $name =~ /$Template::Alloy::QR_PRIVATE/
!ll&&!rl&&r
0480
MC/DC0%0/4
not defined $name or $Template::Alloy::QR_PRIVATE and $name =~ /$Template::Alloy::QR_PRIVATE/ or $name =~ /^\./
not defined $name $Template::Alloy::QR_PRIVATE $name =~ /$Template::Alloy::QR_PRIVATE/ $name =~ /^\./
Truth table16%1/6
not(A) or B and C or D
A= not defined $nameB= $Template::Alloy::QR_PRIVATEC= $name =~ /$Template::Alloy::QR_PRIVATE/D= $name =~ /^\./
ABCDresult
1XXX1
011X1
00X11
01011
00X00
01000
482 0 $ref = undef;
483 0 last;
484 }
485 } else {
486 0 die "Shouldn't get a ". ref($name) ." during a vivify on chain";
487 }
488 }
489 3031 ▶ if (! defined $name || ($QR_PRIVATE && $name =~ $QR_PRIVATE)) { # don't allow vars that begin with _
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $name or $Template::Alloy::QR_PRIVATE and $name =~ /$Template::Alloy::QR_PRIVATE/) 3 3028 3031
Condition83%5/6
not defined $name or $Template::Alloy::QR_PRIVATE and $name =~ /$Template::Alloy::QR_PRIVATE/
l!l&&r!l&&!r
033028
$Template::Alloy::QR_PRIVATE and $name =~ /$Template::Alloy::QR_PRIVATE/
!ll&&!rl&&r
3829903
MC/DC66%2/3
not defined $name or $Template::Alloy::QR_PRIVATE and $name =~ /$Template::Alloy::QR_PRIVATE/
not defined $name $Template::Alloy::QR_PRIVATE $name =~ /$Template::Alloy::QR_PRIVATE/
Truth table75%3/4
not(A) or B and C
A= not defined $nameB= $Template::Alloy::QR_PRIVATEC= $name =~ /$Template::Alloy::QR_PRIVATE/
ABCresult
1XX1
0111
00X0
0100
490 3 $ref = undef;
491 3 last;
492 }
493  
494 ### allow for scalar and filter access (this happens for every non virtual method call)
495 3028 ▶ if (! ref $ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $ref) { } 935 2093 3028
496 935 ▶ if ($ITEM_METHODS->{$name}) { # normal scalar op
Branch: 4 branches
BranchTrueFalseTotal
if ($Template::Alloy::ITEM_METHODS->{$name}) { } 223 712 935
elsif ($Template::Alloy::ITEM_OPS->{$name}) { } 661 51 712
elsif ($Template::Alloy::LIST_OPS->{$name}) { } 9 42 51
elsif (my $filter = $self->{'FILTERS'}{$name} || $Template::Alloy::FILTER_OPS->{$name} || UNIVERSAL::isa($name, 'CODE') && $name || $self->list_filters->{$name}) { } 36 6 42
497 223 ▶ $ref = $ITEM_METHODS->{$name}->($self, $ref, $args ? map { $self->play_expr($_) } @$args : ());
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 60 163 223
498  
499 } elsif ($ITEM_OPS->{$name}) { # normal scalar op
500 661 ▶ $ref = $ITEM_OPS->{$name}->($ref, $args ? map { $self->play_expr($_) } @$args : ());
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 339 322 661
501  
502 } elsif ($LIST_OPS->{$name}) { # auto-promote to list and use list op
503 0 ▶ $ref = $LIST_OPS->{$name}->([$ref], $args ? map { $self->play_expr($_) } @$args : ());
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 0 9 9
504  
505 ▶ } elsif (my $filter = $self->{'FILTERS'}->{$name} # filter configured in Template args
Condition83%10/12
$self->{'FILTERS'}{$name} || $Template::Alloy::FILTER_OPS->{$name} || UNIVERSAL::isa($name, 'CODE') && $name || $self->list_filters->{$name}
l!l&&r!l&&!r
3336
$self->{"FILTERS"}{$name} or $Template::Alloy::FILTER_OPS->{$name} or UNIVERSAL::isa($name, "CODE") and $name
l!l&&r!l&&!r
2769
$self->{"FILTERS"}{$name} or $Template::Alloy::FILTER_OPS->{$name}
l!l&&r!l&&!r
27015
UNIVERSAL::isa($name, "CODE") and $name
!ll&&!rl&&r
906
MC/DC60%3/5
$self->{'FILTERS'}{$name} || $Template::Alloy::FILTER_OPS->{$name} || UNIVERSAL::isa($name, 'CODE') && $name || $self->list_filters->{$name}
$self->{"FILTERS"}{$name} $Template::Alloy::FILTER_OPS->{$name} UNIVERSAL::isa($name, "CODE") $name $self->list_filters->{$name}
Truth table57%4/7
A or B or C and D || E
A= $self->{"FILTERS"}{$name}B= $Template::Alloy::FILTER_OPS->{$name}C= UNIVERSAL::isa($name, "CODE")D= $nameE= $self->list_filters->{$name}
ABCDEresult
1XXXX1
01XXX1
0011X1
000X11
001011
000X00
001000
506 || $FILTER_OPS->{$name} # predefined filters in Alloy
507 || (UNIVERSAL::isa($name, 'CODE') && $name) # looks like a filter sub passed in the stash
508 || $self->list_filters->{$name}) { # filter defined in Template::Filters
509  
510 36 ▶ if (UNIVERSAL::isa($filter, 'CODE')) {
Branch: 3 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($filter, 'CODE')) { } 9 27 36
elsif (not UNIVERSAL::isa($filter, 'ARRAY')) { } 0 27 27
elsif (@$filter == 2 and UNIVERSAL::isa($filter->[0], 'CODE')) { } 9 18 27
511 9 $ref = eval { $filter->($ref) }; # non-dynamic filter - no args
512 9 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 9 9
513 0 ▶ $self->throw('filter', $err) if ! UNIVERSAL::can($err, 'type');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::can($err, "type") 0 0 0
514 0 die $err;
515 }
516 } elsif (! UNIVERSAL::isa($filter, 'ARRAY')) {
517 0 $self->throw('filter', "invalid FILTER entry for '$name' (not a CODE ref)");
518  
519 ▶ } elsif (@$filter == 2 && UNIVERSAL::isa($filter->[0], 'CODE')) { # these are the TT style filters
Condition66%2/3
@$filter == 2 and UNIVERSAL::isa($filter->[0], "CODE")
!ll&&!rl&&r
0189
MC/DC50%1/2
@$filter == 2 and UNIVERSAL::isa($filter->[0], "CODE")
@$filter == 2 UNIVERSAL::isa($filter->[0], "CODE")
Truth table66%2/3
A and B
A= @$filter == 2B= UNIVERSAL::isa($filter->[0], "CODE")
ABresult
0X0
100
111
520 9 eval {
521 9 my $sub = $filter->[0];
522 9 ▶ if ($filter->[1]) { # it is a "dynamic filter" that will return a sub
Branch: 1 branch
BranchTrueFalseTotal
if ($filter->[1]) 6 3 9
523 6 ▶ ($sub, my $err) = $sub->($self->context, $args ? map { $self->play_expr($_) } @$args : ());
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 3 3 6
524 6 ▶ if (! $sub && $err) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $sub and $err) { } 0 6 6
elsif (not UNIVERSAL::isa($sub, 'CODE')) { } 0 6 6
Condition33%1/3
not $sub and $err
!ll&&!rl&&r
600
MC/DC0%0/2
not $sub and $err
not $sub $err
Truth table33%1/3
not(A) and B
A= not $subB= $err
ABresult
0X0
100
111
525 0 ▶ $self->throw('filter', $err) if ! UNIVERSAL::can($err, 'type');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::can($err, "type") 0 0 0
526 0 die $err;
527 } elsif (! UNIVERSAL::isa($sub, 'CODE')) {
528 0 ▶ $self->throw('filter', "invalid FILTER for '$name' (not a CODE ref)")
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::can($sub, "type") 0 0 0
529 if ! UNIVERSAL::can($sub, 'type');
530 0 die $sub;
531 }
532 }
533 9 $ref = $sub->($ref);
534 };
535 9 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 9 9
536 0 ▶ $self->throw('filter', $err) if ! UNIVERSAL::can($err, 'type');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::can($err, "type") 0 0 0
537 0 die $err;
538 }
539 } else { # this looks like our vmethods turned into "filters" (a filter stored under a name)
540 18 ▶ $self->throw('filter', 'Recursive filter alias \"$name\"') if $seen_filters{$name} ++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_filters{$name}++ 0 18 18
541 18 $var = [$name, 0, '|', @$filter, @{$var}[$i..$#$var]]; # splice the filter into our current tree
542 18 $i = 2;
543 }
544 36 ▶ if (scalar keys %seen_filters
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %seen_filters and $seen_filters{$$var[$i - 5] or ""}) 0 36 36
Condition60%3/5
scalar keys %seen_filters and $seen_filters{$$var[$i - 5] or ""}
!ll&&!rl&&r
18180
$$var[$i - 5] || ''
l!l
180
MC/DC0%0/2
scalar keys %seen_filters and $seen_filters{$$var[$i - 5] or ""}
scalar keys %seen_filters $seen_filters{$$var[$i - 5] or ""}
MC/DC0%0/1
$$var[$i - 5] || ''
$$var[$i - 5]
Truth table66%2/3
A and B
A= scalar keys %seen_filtersB= $seen_filters{$$var[$i - 5] or ""}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $$var[$i - 5]
Aresult
11
00
545 && $seen_filters{$var->[$i - 5] || ''}) {
546 0 $self->throw('filter', "invalid FILTER entry for '".$var->[$i - 5]."' (not a CODE ref)");
547 }
548 } else {
549 6 $ref = undef;
550 }
551  
552 } else {
553  
554 ### method calls on objects
555 2093 ▶ if ($was_dot_call && UNIVERSAL::can($ref, 'can')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($was_dot_call and UNIVERSAL::can($ref, "can")) 535 1558 2093
Condition100%3/3
$was_dot_call and UNIVERSAL::can($ref, "can")
!ll&&!rl&&r
121546535
MC/DC100%2/2
$was_dot_call and UNIVERSAL::can($ref, "can")
$was_dot_call UNIVERSAL::can($ref, "can")
Truth table100%3/3
A and B
A= $was_dot_callB= UNIVERSAL::can($ref, "can")
ABresult
0X0
100
111
556 535 ▶ return $ref if $i >= $#$var && $ARGS->{'return_ref'};
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $var->$#* and $ARGS->{"return_ref"} 0 535 535
Condition66%2/3
$i >= $var->$#* and $ARGS->{"return_ref"}
!ll&&!rl&&r
185170
MC/DC0%0/2
$i >= $var->$#* and $ARGS->{"return_ref"}
$i >= $var->$#* $ARGS->{"return_ref"}
Truth table66%2/3
A and B
A= $i >= $var->$#*B= $ARGS->{"return_ref"}
ABresult
0X0
100
111
557 535 ▶ my $type = $self->{'CALL_CONTEXT'} || '';
Condition100%2/2
$self->{'CALL_CONTEXT'} || ''
l!l
48487
MC/DC100%1/1
$self->{'CALL_CONTEXT'} || ''
$self->{'CALL_CONTEXT'}
Truth table100%2/2
A
A= $self->{'CALL_CONTEXT'}
Aresult
11
00
558 535 ▶ my @args = $args ? map { $self->play_expr($_) } @$args : ();
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 9 526 535
559 535 ▶ if ($type eq 'item') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'item') { } 21 514 535
elsif ($type eq 'list') { } 21 493 514
560 21 $ref = $ref->$name(@args);
561 21 next;
562 } elsif ($type eq 'list') {
563 21 $ref = [$ref->$name(@args)];
564 21 next;
565 }
566 493 my @results = eval { $ref->$name(@args) };
567 493 ▶ if ($@) {
Branch: 3 branches
BranchTrueFalseTotal
if ($@) { } 9 484 493
elsif (defined $results[0]) { } 484 0 484
elsif (defined $results[1]) { } 0 0 0
568 9 my $class = ref $ref;
569 9 ▶ die $@ if ref $@ || $@ !~ /Can\'t locate object method "\Q$name\E" via package "\Q$class\E"/ || $type eq 'list';
Branch: 1 branch
BranchTrueFalseTotal
if ref $@ or not $@ =~ /Can\'t locate object method "\Q$name\E" via package "\Q$class\E"/ or $type eq "list" 0 9 9
Condition33%2/6
ref $@ or not $@ =~ /Can\'t locate object method "\Q$name\E" via package "\Q$class\E"/ or $type eq "list"
l!l&&r!l&&!r
009
ref $@ or not $@ =~ /Can\'t locate object method "\Q$name\E" via package "\Q$class\E"/
l!l&&r!l&&!r
009
MC/DC0%0/3
ref $@ or not $@ =~ /Can\'t locate object method "\Q$name\E" via package "\Q$class\E"/ or $type eq "list"
ref $@ not $@ =~ /Can\'t locate object method "\Q$name\E" via package "\Q$class\E"/ $type eq "list"
Truth table25%1/4
A or not(B) or C
A= ref $@B= not $@ =~ /Can\'t locate object method "\Q$name\E" via package "\Q$class\E"/C= $type eq "list"
ABCresult
1XX1
01X1
0011
0000
570 } elsif (defined $results[0]) {
571 484 ▶ $ref = ($#results > 0) ? \@results : $results[0];
Branch: 1 branch
BranchTrueFalseTotal
$#results > 0 ? : 15 469 484
572 484 next;
573 } elsif (defined $results[1]) {
574 0 die $results[1]; # TT behavior - why not just throw ?
575 } else {
576 0 $ref = undef;
577 0 last;
578 }
579 # didn't find a method by that name - so fail down to hash and array access
580 }
581  
582 1567 ▶ if (UNIVERSAL::isa($ref, 'HASH')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($ref, 'HASH')) { } 980 587 1567
elsif (UNIVERSAL::isa($ref, 'ARRAY')) { } 587 0 587
583 980 ▶ if ($was_dot_call && exists($ref->{$name}) ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($was_dot_call and exists $ref->{$name}) { } 692 288 980
elsif ($Template::Alloy::HASH_OPS->{$name}) { } 159 129 288
elsif ($ARGS->{'is_namespace_during_compile'}) { } 6 123 129
Condition100%3/3
$was_dot_call and exists $ref->{$name}
!ll&&!rl&&r
6282692
MC/DC100%2/2
$was_dot_call and exists $ref->{$name}
$was_dot_call exists $ref->{$name}
Truth table100%3/3
A and B
A= $was_dot_callB= exists $ref->{$name}
ABresult
0X0
100
111
584 692 ▶ return \ $ref->{$name} if $i >= $#$var && $ARGS->{'return_ref'} && ! ref $ref->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $var->$#* and $ARGS->{"return_ref"} and not ref $ref->{$name} 12 680 692
Condition83%5/6
$i >= $var->$#* and $ARGS->{"return_ref"} and not ref $ref->{$name}
!ll&&!rl&&r
680012
$i >= $var->$#* and $ARGS->{"return_ref"}
!ll&&!rl&&r
11856212
MC/DC66%2/3
$i >= $var->$#* and $ARGS->{"return_ref"} and not ref $ref->{$name}
$i >= $var->$#* $ARGS->{"return_ref"} not ref $ref->{$name}
Truth table75%3/4
A and B and not(C)
A= $i >= $var->$#*B= $ARGS->{"return_ref"}C= not ref $ref->{$name}
ABCresult
0XX0
10X0
1100
1111
585 680 $ref = $ref->{$name};
586 } elsif ($HASH_OPS->{$name}) {
587 159 ▶ $ref = $HASH_OPS->{$name}->($ref, $args ? map { $self->play_expr($_) } @$args : ());
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 72 87 159
588 } elsif ($ARGS->{'is_namespace_during_compile'}) {
589 6 return $var; # abort - can't fold namespace variable
590 } else {
591 123 ▶ return \ $ref->{$name} if $i >= $#$var && $ARGS->{'return_ref'};
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $var->$#* and $ARGS->{"return_ref"} 3 120 123
Condition100%3/3
$i >= $var->$#* and $ARGS->{"return_ref"}
!ll&&!rl&&r
31173
MC/DC100%2/2
$i >= $var->$#* and $ARGS->{"return_ref"}
$i >= $var->$#* $ARGS->{"return_ref"}
Truth table100%3/3
A and B
A= $i >= $var->$#*B= $ARGS->{"return_ref"}
ABresult
0X0
100
111
592 120 $ref = undef;
593 }
594  
595 } elsif (UNIVERSAL::isa($ref, 'ARRAY')) {
596 587 ▶ if ($name =~ m{ ^ -? $QR_INDEX $ }ox) {
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ / ^ -? $Template::Alloy::QR_INDEX $ /ox) { } 155 432 587
elsif ($Template::Alloy::LIST_OPS->{$name}) { } 432 0 432
597 155 ▶ return \ $ref->[$name] if $i >= $#$var && $ARGS->{'return_ref'} && ! ref $ref->[$name];
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $var->$#* and $ARGS->{"return_ref"} and not ref $ref->[$name] 6 149 155
Condition83%5/6
$i >= $var->$#* and $ARGS->{"return_ref"} and not ref $ref->[$name]
!ll&&!rl&&r
14906
$i >= $var->$#* and $ARGS->{"return_ref"}
!ll&&!rl&&r
121376
MC/DC66%2/3
$i >= $var->$#* and $ARGS->{"return_ref"} and not ref $ref->[$name]
$i >= $var->$#* $ARGS->{"return_ref"} not ref $ref->[$name]
Truth table75%3/4
A and B and not(C)
A= $i >= $var->$#*B= $ARGS->{"return_ref"}C= not ref $ref->[$name]
ABCresult
0XX0
10X0
1100
1111
598 149 $ref = $ref->[$name];
599 } elsif ($LIST_OPS->{$name}) {
600 432 ▶ $ref = $LIST_OPS->{$name}->($ref, $args ? map { $self->play_expr($_) } @$args : ());
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 126 306 432
601 } else {
602 0 $ref = undef;
603 }
604 } else {
605 0 $ref = undef;
606 }
607 }
608  
609 } # end of while
610  
611 17941 ▶ if (! defined $ref) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ref) 769 17172 17941
612 769 ▶ $self->strict_throw($var) if $self->{'STRICT'}; # will die
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"STRICT"} 27 742 769
613 745 ▶ die $self->tt_var_string($var)." is undefined\n" if $self->{'_debug_undef'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_debug_undef"} 6 739 745
614 739 $ref = $self->undefined_any($var);
615 }
616  
617 17911 return $ref;
618 }
619  
620 5533 ▶sub set_variable {
Subroutine set_variable: called CC=58 SCAR=49.8
Pod documented
621 5533 my ($self, $var, $val, $ARGS) = @_;
622 5533 ▶ $ARGS ||= {};
Condition100%2/2
$ARGS ||= {}
l!l
35530
MC/DC100%1/1
$ARGS ||= {}
$ARGS
Truth table100%2/2
A
A= $ARGS
Aresult
11
00
623 5533 my $i = 0;
624  
625 ### allow for the parse tree to store literals - the literal is used as a name (like [% 'a' = 'A' %])
626 5533 ▶ $var = [$var, 0] if ! ref $var;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $var 89 5444 5533
627  
628 ### determine the top level of this particular variable access
629 5533 my $ref = $var->[$i++];
630 5533 my $args = $var->[$i++];
631 5533 ▶ if (ref $ref) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $ref) { } 18 5515 5533
elsif (defined $ref) { } 5515 0 5515
632 ### non-named types can't be set
633 18 ▶ return if ref($ref) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $ref ne "ARRAY" 0 18 18
634 18 ▶ if (! defined $ref->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ref->[0]) { } 6 12 18
635 6 ▶ return if ! $ref->[1] || $ref->[1] !~ /^[\$\@]\(\)$/; # do allow @( )
Branch: 1 branch
BranchTrueFalseTotal
unless $ref->[1] and $ref->[1] =~ /^[\$\@]\(\)$/ 0 6 6
Condition33%1/3
$ref->[1] and $ref->[1] =~ /^[\$\@]\(\)$/
!ll&&!rl&&r
006
MC/DC0%0/2
$ref->[1] and $ref->[1] =~ /^[\$\@]\(\)$/
$ref->[1] $ref->[1] =~ /^[\$\@]\(\)$/
Truth table33%1/3
A and B
A= $ref->[1]B= $ref->[1] =~ /^[\$\@]\(\)$/
ABresult
0X0
100
111
636 6 $ref = $self->play_operator($ref);
637 } else {
638 # named access (ie via $name.foo)
639 12 $ref = $self->play_expr($ref);
640 12 ▶ if (defined $ref && (! $QR_PRIVATE || $ref !~ $QR_PRIVATE)) { # don't allow vars that begin with _
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref and not $Template::Alloy::QR_PRIVATE && $ref =~ /$Template::Alloy::QR_PRIVATE/) { } 12 0 12
Condition33%2/6
defined $ref and not $Template::Alloy::QR_PRIVATE && $ref =~ /$Template::Alloy::QR_PRIVATE/
!ll&&!rl&&r
0012
$Template::Alloy::QR_PRIVATE && $ref =~ /$Template::Alloy::QR_PRIVATE/
!ll&&!rl&&r
0120
MC/DC0%0/3
defined $ref and not $Template::Alloy::QR_PRIVATE && $ref =~ /$Template::Alloy::QR_PRIVATE/
defined $ref $Template::Alloy::QR_PRIVATE $ref =~ /$Template::Alloy::QR_PRIVATE/
Truth table25%1/4
A and not(B && C)
A= defined $refB= $Template::Alloy::QR_PRIVATEC= $ref =~ /$Template::Alloy::QR_PRIVATE/
ABCresult
0XX0
1110
10X1
1101
641 12 ▶ if ($#$var <= $i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var->$#* <= $i) { } 6 6 12
642 6 return $self->{'_vars'}->{$ref} = $val;
643 } else {
644 6 ▶ $ref = $self->{'_vars'}->{$ref} ||= {};
Condition50%1/2
$self->{"_vars"}{$ref} ||= {}
l!l
06
MC/DC0%0/1
$self->{"_vars"}{$ref} ||= {}
$self->{"_vars"}{$ref}
Truth table50%1/2
A
A= $self->{"_vars"}{$ref}
Aresult
11
00
645 }
646 } else {
647 0 return;
648 }
649 }
650 } elsif (defined $ref) {
651 5515 ▶ return if $QR_PRIVATE && $ref =~ $QR_PRIVATE; # don't allow vars that begin with _
Branch: 1 branch
BranchTrueFalseTotal
if $Template::Alloy::QR_PRIVATE and $ref =~ /$Template::Alloy::QR_PRIVATE/ 3 5512 5515
Condition100%3/3
$Template::Alloy::QR_PRIVATE and $ref =~ /$Template::Alloy::QR_PRIVATE/
!ll&&!rl&&r
4354693
MC/DC100%2/2
$Template::Alloy::QR_PRIVATE and $ref =~ /$Template::Alloy::QR_PRIVATE/
$Template::Alloy::QR_PRIVATE $ref =~ /$Template::Alloy::QR_PRIVATE/
Truth table100%3/3
A and B
A= $Template::Alloy::QR_PRIVATEB= $ref =~ /$Template::Alloy::QR_PRIVATE/
ABresult
0X0
100
111
652 5512 ▶ if ($#$var <= $i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var->$#* <= $i) { } 5374 138 5512
653 5374 return $self->{'_vars'}->{$ref} = $val;
654 } else {
655 138 ▶ $ref = $self->{'_vars'}->{$ref} ||= {};
Condition100%2/2
$self->{"_vars"}{$ref} ||= {}
l!l
7563
MC/DC100%1/1
$self->{"_vars"}{$ref} ||= {}
$self->{"_vars"}{$ref}
Truth table100%2/2
A
A= $self->{"_vars"}{$ref}
Aresult
11
00
656 }
657 }
658  
659 150 ▶ while (defined $ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref) 198 0 198
660  
661 ### check at each point if the returned thing was a code
662 198 ▶ if (UNIVERSAL::isa($ref, 'CODE')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($ref, "CODE")) 6 192 198
663 6 ▶ my $type = $self->{'CALL_CONTEXT'} || '';
Condition100%2/2
$self->{'CALL_CONTEXT'} || ''
l!l
33
MC/DC100%1/1
$self->{'CALL_CONTEXT'} || ''
$self->{'CALL_CONTEXT'}
Truth table100%2/2
A
A= $self->{'CALL_CONTEXT'}
Aresult
11
00
664 0 ▶ my @args = $args ? map { $self->play_expr($_) } @$args : ();
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 0 6 6
665 6 ▶ if ($type eq 'item') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'item') { } 0 6 6
666 0 $ref = $ref->(@args);
667 } else {
668 6 my @results = $ref->(@args);
669 6 ▶ if ($type eq 'list') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'list') { } 3 3 6
elsif (defined $results[0]) { } 3 0 3
elsif (defined $results[1]) { } 0 0 0
670 3 $ref = \@results;
671 } elsif (defined $results[0]) {
672 3 ▶ $ref = ($#results > 0) ? \@results : $results[0];
Branch: 1 branch
BranchTrueFalseTotal
$#results > 0 ? : 0 3 3
673 } elsif (defined $results[1]) {
674 0 die $results[1]; # TT behavior - why not just throw ?
675 } else {
676 0 return;
677 }
678 }
679 }
680  
681 ### descend one chained level
682 198 ▶ last if $i >= $#$var;
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $var->$#* 0 198 198
683 198 ▶ my $was_dot_call = $ARGS->{'no_dots'} ? 1 : $var->[$i++] eq '.';
Branch: 1 branch
BranchTrueFalseTotal
$ARGS->{'no_dots'} ? : 6 192 198
684 198 my $name = $var->[$i++];
685 198 my $args = $var->[$i++];
686  
687 ### allow for named portions of a variable name (foo.$name.bar)
688 198 ▶ if (ref $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $name) 18 180 198
689 18 ▶ if (ref($name) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $name eq 'ARRAY') { } 18 0 18
690 18 $name = $self->play_expr($name);
691 18 ▶ if (! defined($name) || $name =~ /^[_.]/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $name or $name =~ /^[_.]/) 0 18 18
Condition33%1/3
not defined $name or $name =~ /^[_.]/
l!l&&r!l&&!r
0018
MC/DC0%0/2
not defined $name or $name =~ /^[_.]/
not defined $name $name =~ /^[_.]/
Truth table33%1/3
not(A) or B
A= not defined $nameB= $name =~ /^[_.]/
ABresult
1X1
011
000
692 0 return;
693 }
694 } else {
695 0 die "Shouldn't get a ".ref($name)." during a vivify on chain";
696 }
697 }
698 198 ▶ if ($QR_PRIVATE && $name =~ $QR_PRIVATE) { # don't allow vars that begin with _
Branch: 1 branch
BranchTrueFalseTotal
if ($Template::Alloy::QR_PRIVATE and $name =~ /$Template::Alloy::QR_PRIVATE/) 0 198 198
Condition33%1/3
$Template::Alloy::QR_PRIVATE and $name =~ /$Template::Alloy::QR_PRIVATE/
!ll&&!rl&&r
01980
MC/DC0%0/2
$Template::Alloy::QR_PRIVATE and $name =~ /$Template::Alloy::QR_PRIVATE/
$Template::Alloy::QR_PRIVATE $name =~ /$Template::Alloy::QR_PRIVATE/
Truth table33%1/3
A and B
A= $Template::Alloy::QR_PRIVATEB= $name =~ /$Template::Alloy::QR_PRIVATE/
ABresult
0X0
100
111
699 0 return;
700 }
701  
702 ### scalar access
703 198 ▶ if (! ref $ref) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $ref) { } 0 198 198
elsif (UNIVERSAL::can($ref, 'can')) { } 15 183 198
704 0 return;
705  
706 ### method calls on objects
707 } elsif (UNIVERSAL::can($ref, 'can')) {
708 15 my $lvalueish;
709 15 ▶ my $type = $self->{'CALL_CONTEXT'} || '';
Condition100%2/2
$self->{'CALL_CONTEXT'} || ''
l!l
69
MC/DC100%1/1
$self->{'CALL_CONTEXT'} || ''
$self->{'CALL_CONTEXT'}
Truth table100%2/2
A
A= $self->{'CALL_CONTEXT'}
Aresult
11
00
710 0 ▶ my @args = $args ? map { $self->play_expr($_) } @$args : ();
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 0 15 15
711 15 ▶ if ($i >= $#$var) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= $var->$#*) 12 3 15
712 12 $lvalueish = 1;
713 12 push @args, $val;
714 }
715 15 ▶ if ($type eq 'item') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'item') { } 3 12 15
elsif ($type eq 'list') { } 3 9 12
716 3 $ref = $ref->$name(@args);
717 3 ▶ return if $lvalueish;
Branch: 1 branch
BranchTrueFalseTotal
if $lvalueish 3 0 3
718 0 next;
719 } elsif ($type eq 'list') {
720 3 $ref = [$ref->$name(@args)];
721 3 ▶ return if $lvalueish;
Branch: 1 branch
BranchTrueFalseTotal
if $lvalueish 3 0 3
722 0 next;
723 }
724 9 my @results = eval { $ref->$name(@args) };
725 9 ▶ if (! $@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 9 0 9
726 9 ▶ if (defined $results[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $results[0]) { } 9 0 9
elsif (defined $results[1]) { } 0 0 0
727 9 ▶ $ref = ($#results > 0) ? \@results : $results[0];
Branch: 1 branch
BranchTrueFalseTotal
$#results > 0 ? : 0 9 9
728 } elsif (defined $results[1]) {
729 0 die $results[1]; # TT behavior - why not just throw ?
730 } else {
731 0 return;
732 }
733 9 ▶ return if $lvalueish;
Branch: 1 branch
BranchTrueFalseTotal
if $lvalueish 6 3 9
734 3 next;
735 }
736 0 my $class = ref $ref;
737 0 ▶ die $@ if ref $@ || $@ !~ /Can\'t locate object method "\Q$name\E" via package "\Q$class\E"/;
Branch: 1 branch
BranchTrueFalseTotal
if ref $@ or not $@ =~ /Can\'t locate object method "\Q$name\E" via package "\Q$class\E"/ 0 0 0
Condition0%0/3
ref $@ or not $@ =~ /Can\'t locate object method "\Q$name\E" via package "\Q$class\E"/
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $@ or not $@ =~ /Can\'t locate object method "\Q$name\E" via package "\Q$class\E"/
ref $@ not $@ =~ /Can\'t locate object method "\Q$name\E" via package "\Q$class\E"/
Truth table0%0/3
A or not(B)
A= ref $@B= not $@ =~ /Can\'t locate object method "\Q$name\E" via package "\Q$class\E"/
ABresult
1X1
011
000
738 # fall on down to "normal" accessors
739 }
740  
741 183 ▶ if (UNIVERSAL::isa($ref, 'HASH')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($ref, 'HASH')) { } 165 18 183
elsif (UNIVERSAL::isa($ref, 'ARRAY')) { } 18 0 18
742 165 ▶ if ($#$var <= $i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var->$#* <= $i) { } 126 39 165
743 126 return $ref->{$name} = $val;
744 } else {
745 39 ▶ $ref = $ref->{$name} ||= {};
Condition100%2/2
$ref->{$name} ||= {}
l!l
1227
MC/DC100%1/1
$ref->{$name} ||= {}
$ref->{$name}
Truth table100%2/2
A
A= $ref->{$name}
Aresult
11
00
746 39 next;
747 }
748  
749 } elsif (UNIVERSAL::isa($ref, 'ARRAY')) {
750 18 ▶ if ($name =~ m{ ^ -? $QR_INDEX $ }ox) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ / ^ -? $Template::Alloy::QR_INDEX $ /ox) { } 18 0 18
751 18 ▶ if ($#$var <= $i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var->$#* <= $i) { } 12 6 18
752 12 return $ref->[$name] = $val;
753 } else {
754 6 ▶ $ref = $ref->[$name] ||= {};
Condition50%1/2
$ref->[$name] ||= {}
l!l
60
MC/DC0%0/1
$ref->[$name] ||= {}
$ref->[$name]
Truth table50%1/2
A
A= $ref->[$name]
Aresult
11
00
755 6 next;
756 }
757 } else {
758 0 return;
759 }
760  
761 }
762  
763 }
764  
765 0 return;
766 }
767  
768 ###----------------------------------------------------------------###
769  
770 190 ▶sub _vars {
Subroutine _vars: called CC=3 SCAR=11.7
771 190 my $self = shift;
772 190 ▶ $self->{'_vars'} = shift if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 190 190
773 190 ▶ return $self->{'_vars'} ||= {};
Condition50%1/2
$self->{"_vars"} ||= {}
l!l
1900
MC/DC0%0/1
$self->{"_vars"} ||= {}
$self->{"_vars"}
Truth table50%1/2
A
A= $self->{"_vars"}
Aresult
11
00
774 }
775  
776 539 ▶sub include_filename {
Subroutine include_filename: called CC=14 SCAR=33.7
Pod documented
777 539 my ($self, $file) = @_;
778 539 ▶ if ($file =~ m|^/|) {
Branch: 2 branches
BranchTrueFalseTotal
if ($file =~ m[^/]) { } 0 539 539
elsif ($file =~ m[(^|/)\.\./]) { } 0 539 539
779 0 ▶ $self->throw('file', "$file absolute paths are not allowed (set ABSOLUTE option)") if ! $self->{'ABSOLUTE'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"ABSOLUTE"} 0 0 0
780 0 ▶ return $file if -e $file;
Branch: 1 branch
BranchTrueFalseTotal
if -e $file 0 0 0
781 } elsif ($file =~ m{(^|/)\.\./}) {
782 0 ▶ $self->throw('file', "$file relative paths are not allowed (set RELATIVE option)") if ! $self->{'RELATIVE'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"RELATIVE"} 0 0 0
783 0 ▶ return $file if -e $file;
Branch: 1 branch
BranchTrueFalseTotal
if -e $file 0 0 0
784 }
785  
786 539 my @paths = @{ $self->include_paths };
787 539 ▶ if ($self->{'ADD_LOCAL_PATH'}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ADD_LOCAL_PATH"} and $self->{"_component"} and $self->{"_component"}{"_filename"} and $self->{"_component"}{"_filename"} =~ m[^(.+)/[^/]+$]) 60 479 539
Condition66%6/9
$self->{"ADD_LOCAL_PATH"} and $self->{"_component"} and $self->{"_component"}{"_filename"} and $self->{"_component"}{"_filename"} =~ m[^(.+)/[^/]+$]
!ll&&!rl&&r
479060
$self->{"ADD_LOCAL_PATH"} and $self->{"_component"} and $self->{"_component"}{"_filename"}
!ll&&!rl&&r
479060
$self->{"ADD_LOCAL_PATH"} and $self->{"_component"}
!ll&&!rl&&r
479060
MC/DC25%1/4
$self->{"ADD_LOCAL_PATH"} and $self->{"_component"} and $self->{"_component"}{"_filename"} and $self->{"_component"}{"_filename"} =~ m[^(.+)/[^/]+$]
$self->{"ADD_LOCAL_PATH"} $self->{"_component"} $self->{"_component"}{"_filename"} $self->{"_component"}{"_filename"} =~ m[^(.+)/[^/]+$]
Truth table40%2/5
A and B and C and D
A= $self->{"ADD_LOCAL_PATH"}B= $self->{"_component"}C= $self->{"_component"}{"_filename"}D= $self->{"_component"}{"_filename"} =~ m[^(.+)/[^/]+$]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
788 && $self->{'_component'}
789 && $self->{'_component'}->{'_filename'}
790 && $self->{'_component'}->{'_filename'} =~ m|^(.+)/[^/]+$|) {
791 60 ▶ ($self->{'ADD_LOCAL_PATH'} < 0) ? push(@paths, $1) : unshift(@paths, $1);
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ADD_LOCAL_PATH'} < 0 ? : 12 48 60
792 }
793  
794 539 foreach my $path (@paths) {
795 580 ▶ return "$path/$file" if -e "$path/$file";
Branch: 1 branch
BranchTrueFalseTotal
if -e "$path/$file" 488 92 580
796 }
797  
798 51 $self->throw('file', "$file: not found");
799 }
800  
801 542 ▶sub include_paths {
Subroutine include_paths: called CC=5 SCAR=16.2
Pod undocumented
802 542 my $self = shift;
803 542 ▶ return $self->{'INCLUDE_PATHS'} ||= do {
Condition66%2/3
$self->{"INCLUDE_PATHS"} ||= do { my $paths = $self->{"INCLUDE_PATH"} || ["."]; $paths = &$paths() if UNIVERSAL::isa($paths, "CODE"); $paths = $self->split_paths($paths) unless UNIVERSAL::isa($paths, "ARRAY"); $paths }
l!l&&r!l&&!r
1324100
MC/DC0%0/2
$self->{"INCLUDE_PATHS"} ||= do { my $paths = $self->{"INCLUDE_PATH"} || ["."]; $paths = &$paths() if UNIVERSAL::isa($paths, "CODE"); $paths = $self->split_paths($paths) unless UNIVERSAL::isa($paths, "ARRAY"); $paths }
$self->{"INCLUDE_PATHS"} do { my $paths = $self->{"INCLUDE_PATH"} || ["."]; $paths = &$paths() if UNIVERSAL::isa($paths, "CODE"); $paths = $self->split_paths($paths) unless UNIVERSAL::isa($paths, "ARRAY"); $paths }
Truth table66%2/3
A ||= B
A= $self->{"INCLUDE_PATHS"}B= do { my $paths = $self->{"INCLUDE_PATH"} || ["."]; $paths = &$paths() if UNIVERSAL::isa($paths, "CODE"); $paths = $self->split_paths($paths) unless UNIVERSAL::isa($paths, "ARRAY"); $paths }
ABresult
1X1
011
000
804 # TT does this everytime a file is looked up - we are going to do it just in time - the first time
805 410 ▶ my $paths = $self->{'INCLUDE_PATH'} || ['.'];
Condition100%2/2
$self->{'INCLUDE_PATH'} || ['.']
l!l
4046
MC/DC100%1/1
$self->{'INCLUDE_PATH'} || ['.']
$self->{'INCLUDE_PATH'}
Truth table100%2/2
A
A= $self->{'INCLUDE_PATH'}
Aresult
11
00
806 410 ▶ $paths = $paths->() if UNIVERSAL::isa($paths, 'CODE');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($paths, "CODE") 0 410 410
807 410 ▶ $paths = $self->split_paths($paths) if ! UNIVERSAL::isa($paths, 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($paths, "ARRAY") 404 6 410
808 410 $paths; # return of the do
809 };
810 }
811  
812 548 ▶sub split_paths {
Subroutine split_paths: called CC=5 SCAR=17.2
Pod documented
813 548 my ($self, $path) = @_;
814 548 ▶ return $path if UNIVERSAL::isa($path, 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($path, "ARRAY") 27 521 548
815 521 ▶ my $delim = $self->{'DELIMITER'} || ':';
Condition50%1/2
$self->{'DELIMITER'} || ':'
l!l
0521
MC/DC0%0/1
$self->{'DELIMITER'} || ':'
$self->{'DELIMITER'}
Truth table50%1/2
A
A= $self->{'DELIMITER'}
Aresult
11
00
816 521 ▶ $delim = ($delim eq ':' && $^O eq 'MSWin32') ? qr|:(?!/)| : qr|\Q$delim\E|;
Branch: 1 branch
BranchTrueFalseTotal
$delim eq ':' && $^O eq 'MSWin32' ? : 0 521 521
Condition33%1/3
$delim eq ":" and $^O eq "MSWin32"
!ll&&!rl&&r
05210
MC/DC0%0/2
$delim eq ":" and $^O eq "MSWin32"
$delim eq ":" $^O eq "MSWin32"
Truth table33%1/3
A and B
A= $delim eq ":"B= $^O eq "MSWin32"
ABresult
0X0
100
111
817 521 return [split $delim, "$path"]; # allow objects to stringify as necessary
818 }
819  
820 490 ▶sub slurp {
Subroutine slurp: called CC=5 SCAR=17.0
Pod documented
821 490 my ($self, $file) = @_;
822 490 ▶ open(my $fh, '<', $file) || $self->throw('file', "$file couldn't be opened: $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or $self->throw("file", "$file couldn't be opened: $!") 490 0 490
823 490 read $fh, my $txt, -s $file;
824  
825 490 ▶ if ($self->{'ENCODING'}) { # thanks to Carl Franks for this addition
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ENCODING"}) 3 487 490
826 3 eval { require Encode };
827 3 ▶ if ($@ || ! defined &Encode::decode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not defined &Encode::decode) { } 0 3 3
Condition33%1/3
$@ or not defined &Encode::decode
l!l&&r!l&&!r
003
MC/DC0%0/2
$@ or not defined &Encode::decode
$@ not defined &Encode::decode
Truth table33%1/3
A or not(B)
A= $@B= not defined &Encode::decode
ABresult
1X1
011
000
828 0 warn "Encode module not found, 'ENCODING' config only available on perl >= 5.7.3\n$@";
829 } else {
830 3 $txt = Encode::decode($self->{'ENCODING'}, $txt);
831 }
832 }
833  
834 490 return \$txt;
835 }
836  
837 38 ▶sub error { shift->{'error'} }
Subroutine error: called CC=1 SCAR=0.0
Pod documented
838  
839 487 ▶sub exception {
Subroutine exception: called CC=8 SCAR=22.1
Pod documented
840 487 my $self_or_class = shift;
841 487 my $type = shift;
842 487 my $info = shift;
843 487 ▶ return $type if UNIVERSAL::can($type, 'type');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($type, "type") 13 474 487
844 474 ▶ if (ref($info) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $info eq "ARRAY") 100 374 474
845 100 ▶ my $hash = ref($info->[-1]) eq 'HASH' ? pop(@$info) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $info->[-1] eq 'HASH' ? : 0 100 100
846 100 ▶ if (@$info >= 2 || scalar keys %$hash) {
Branch: 2 branches
BranchTrueFalseTotal
if (@$info >= 2 or scalar keys %$hash) { } 0 100 100
elsif (@$info == 1) { } 87 13 100
Condition50%1/2
@$info >= 2 or scalar keys %$hash
l!l
0100
MC/DC0%0/1
@$info >= 2 or scalar keys %$hash
@$info >= 2
Truth table50%1/2
A
A= @$info >= 2
Aresult
11
00
847 0 my $i = 0;
848 0 $hash->{$_} = $info->[$_] for 0 .. $#$info;
849 0 $hash->{'args'} = $info;
850 0 $info = $hash;
851 } elsif (@$info == 1) {
852 87 $info = $info->[0];
853 } else {
854 13 $info = $type;
855 13 $type = 'undef';
856 }
857 }
858 474 return Template::Alloy::Exception->new($type, $info, @_);
859 }
860  
861 440 ▶sub throw { die shift->exception(@_) }
Subroutine throw: called CC=1 SCAR=0.0
Pod documented
862  
863 45 ▶sub context {
Subroutine context: called CC=1 SCAR=0.0
Pod documented
864 45 my $self = shift;
865 45 require Template::Alloy::Context;
866 45 return Template::Alloy::Context->new({_template => $self});
867 }
868  
869 257 ▶sub iterator {
Subroutine iterator: called CC=1 SCAR=0.0
Pod undocumented
870 257 my $self = shift;
871 257 require Template::Alloy::Iterator;
872 257 Template::Alloy::Iterator->new(@_);
873 }
874  
875 614 ▶sub undefined_get {
Subroutine undefined_get: called CC=2 SCAR=7.1
Pod documented
876 614 my ($self, $ident, $node) = @_;
877 614 ▶ return $self->{'UNDEFINED_GET'}->($self, $ident, $node) if $self->{'UNDEFINED_GET'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"UNDEFINED_GET"} 0 614 614
878 614 return '';
879 }
880  
881 739 ▶sub undefined_any {
Subroutine undefined_any: called CC=2 SCAR=7.1
Pod documented
882 739 my ($self, $ident) = @_;
883 739 ▶ return $self->{'UNDEFINED_ANY'}->($self, $ident) if $self->{'UNDEFINED_ANY'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"UNDEFINED_ANY"} 0 739 739
884 739 return;
885 }
886  
887 27 ▶sub strict_throw {
Subroutine strict_throw: called CC=3 SCAR=11.0
Pod documented
888 27 my ($self, $ident) = @_;
889 27 my $v = $self->tt_var_string($ident);
890 27 my $temp = $self->{'_template'}->{'name'};
891 27 my $comp = $self->{'_component'}->{'name'};
892 27 ▶ my $msg = "undefined variable: $v in $comp".($comp ne $temp ? " while processing $temp" : '');
Branch: 1 branch
BranchTrueFalseTotal
$comp ne $temp ? : 3 24 27
893 27 ▶ return $self->{'STRICT_THROW'}->($self, 'var.undef', $msg, {name => $v, component => $comp, template => $temp, ident => $ident}) if $self->{'STRICT_THROW'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"STRICT_THROW"} 6 21 27
894 21 $self->throw('var.undef', $msg);
895 }
896  
897 9 ▶sub list_filters { shift->{'_filters'} ||= eval { require Template::Filters; $Template::Filters::FILTERS } || {} }
Subroutine list_filters: called CC=3 SCAR=12.5
Pod documented
Condition40%2/5
+(shift())->{"_filters"} ||= eval { do { require Template::Filters; $Template::Filters::FILTERS } } || {}
l!l&&r!l&&!r
090
eval { do { require Template::Filters; $Template::Filters::FILTERS } } || {}
l!l
90
MC/DC0%0/2
+(shift())->{"_filters"} ||= eval { do { require Template::Filters; $Template::Filters::FILTERS } } || {}
+(shift())->{"_filters"} eval { do { require Template::Filters; $Template::Filters::FILTERS } }
Truth table33%1/3
A ||= B
A= +(shift())->{"_filters"}B= eval { do { require Template::Filters; $Template::Filters::FILTERS } }
ABresult
1X1
011
000
898  
899 16 ▶sub debug_node {
Subroutine debug_node: called CC=3 SCAR=11.0
Pod documented
900 16 my ($self, $node) = @_;
901 16 my $info = $self->node_info($node);
902 16 ▶ my $format = $self->{'_debug_format'} || $self->{'DEBUG_FORMAT'} || "\n## \$file line \$line : [% \$text %] ##\n";
Condition100%5/5
$self->{'_debug_format'} || $self->{'DEBUG_FORMAT'} || "\n## \$file line \$line : [% \$text %] ##\n"
l!l
106
$self->{"_debug_format"} or $self->{"DEBUG_FORMAT"}
l!l&&r!l&&!r
286
MC/DC100%2/2
$self->{'_debug_format'} || $self->{'DEBUG_FORMAT'} || "\n## \$file line \$line : [% \$text %] ##\n"
$self->{"_debug_format"} $self->{"DEBUG_FORMAT"}
Truth table100%3/3
A or B
A= $self->{"_debug_format"}B= $self->{"DEBUG_FORMAT"}
ABresult
1X1
011
000
903 16 $format =~ s{\$(file|line|text)}{$info->{$1}}g;
904 16 return $format;
905 }
906  
907 102 ▶sub node_info {
Subroutine node_info: called CC=5 SCAR=16.7
Pod undocumented
908 102 my ($self, $node) = @_;
909 102 my $doc = $self->{'_component'};
910 102 my $i = $node->[1];
911 102 ▶ my $j = $node->[2] || return ''; # META can be 0
Condition50%1/2
$node->[2] || (return '')
l!l
1020
MC/DC0%0/1
$node->[2] || (return '')
$node->[2]
Truth table50%1/2
A
A= $node->[2]
Aresult
11
00
912 return {
913 file => $doc->{'name'},
914 line => 'unknown',
915 text => 'unknown',
916 102 ▶ } if !$doc->{'_filename'} && !$doc->{'_content'};
Branch: 1 branch
BranchTrueFalseTotal
unless $doc->{"_filename"} or $doc->{"_content"} 0 102 102
Condition33%1/3
$doc->{"_filename"} or $doc->{"_content"}
l!l&&r!l&&!r
10200
MC/DC0%0/2
$doc->{"_filename"} or $doc->{"_content"}
$doc->{"_filename"} $doc->{"_content"}
Truth table33%1/3
A or B
A= $doc->{"_filename"}B= $doc->{"_content"}
ABresult
1X1
011
000
917 102 ▶ $doc->{'_content'} ||= $self->slurp($doc->{'_filename'});
Condition66%2/3
$doc->{"_content"} ||= $self->slurp($doc->{"_filename"})
l!l&&r!l&&!r
9930
MC/DC0%0/2
$doc->{"_content"} ||= $self->slurp($doc->{"_filename"})
$doc->{"_content"} $self->slurp($doc->{"_filename"})
Truth table66%2/3
A ||= B
A= $doc->{"_content"}B= $self->slurp($doc->{"_filename"})
ABresult
1X1
011
000
918 102 my $s = substr(${ $doc->{'_content'} }, $i, $j - $i);
919 102 $s =~ s/^\s+//;
920 102 $s =~ s/\s+$//;
921 return {
922 102 file => $doc->{'name'},
923 line => $self->get_line_number_by_index($doc, $i),
924 text => $s,
925 };
926 }
927  
928 3500 ▶sub get_line_number_by_index {
Subroutine get_line_number_by_index: called CC=12 SCAR=25.7
Pod documented
929 3500 my ($self, $doc, $index, $include_char) = @_;
930 3500 ▶ if (! $index || $index <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $index or $index <= 0) 0 3500 3500
Condition33%1/3
not $index or $index <= 0
l!l&&r!l&&!r
003500
MC/DC0%0/2
not $index or $index <= 0
not $index $index <= 0
Truth table33%1/3
not(A) or B
A= not $indexB= $index <= 0
ABresult
1X1
011
000
931 0 ▶ return $include_char ? (1, 1) : 1;
Branch: 1 branch
BranchTrueFalseTotal
$include_char ? : 0 0 0
932 }
933  
934 3500 ▶ my $lines = $doc->{'_line_offsets'} ||= do {
Condition66%2/3
$doc->{"_line_offsets"} ||= do { $doc->{"_content"} ||= $self->slurp($doc->{"_filename"}); my $i = 0; my(@lines) = 0; while (1) { $i = index(${$doc->{"_content"};}, "\n", $i) + 1; last if $i == 0; push @lines, $i; } ; \@lines }
l!l&&r!l&&!r
187216280
MC/DC0%0/2
$doc->{"_line_offsets"} ||= do { $doc->{"_content"} ||= $self->slurp($doc->{"_filename"}); my $i = 0; my(@lines) = 0; while (1) { $i = index(${$doc->{"_content"};}, "\n", $i) + 1; last if $i == 0; push @lines, $i; } ; \@lines }
$doc->{"_line_offsets"} do { $doc->{"_content"} ||= $self->slurp($doc->{"_filename"}); my $i = 0; my(@lines) = 0; while (1) { $i = index(${$doc->{"_content"};}, "\n", $i) + 1; last if $i == 0; push @lines, $i; } ; \@lines }
Truth table66%2/3
A ||= B
A= $doc->{"_line_offsets"}B= do { $doc->{"_content"} ||= $self->slurp($doc->{"_filename"}); my $i = 0; my(@lines) = 0; while (1) { $i = index(${$doc->{"_content"};}, "\n", $i) + 1; last if $i == 0; push @lines, $i; } ; \@lines }
ABresult
1X1
011
000
935 1628 ▶ $doc->{'_content'} ||= $self->slurp($doc->{'_filename'});
Condition33%1/3
$doc->{"_content"} ||= $self->slurp($doc->{"_filename"})
l!l&&r!l&&!r
162800
MC/DC0%0/2
$doc->{"_content"} ||= $self->slurp($doc->{"_filename"})
$doc->{"_content"} $self->slurp($doc->{"_filename"})
Truth table33%1/3
A ||= B
A= $doc->{"_content"}B= $self->slurp($doc->{"_filename"})
ABresult
1X1
011
000
936 1628 my $i = 0;
937 1628 my @lines = (0);
938 1628 while (1) {
939 1780 $i = index(${ $doc->{'_content'} }, "\n", $i) + 1;
940 1780 ▶ last if $i == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $i == 0 1628 152 1780
941 152 push @lines, $i;
942 }
943 1628 \@lines;
944 };
945  
946 ### binary search them (this is fast even on big docs)
947 3500 my ($i, $j) = (0, $#$lines);
948 3500 ▶ if ($index > $lines->[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index > $lines->[-1]) { } 3282 218 3500
949 3282 $i = $j;
950 } else {
951 218 while (1) {
952 620 ▶ last if abs($i - $j) <= 1;
Branch: 1 branch
BranchTrueFalseTotal
if abs $i - $j <= 1 218 402 620
953 402 my $k = int(($i + $j) / 2);
954 402 ▶ $j = $k if $lines->[$k] >= $index;
Branch: 1 branch
BranchTrueFalseTotal
if $lines->[$k] >= $index 170 232 402
955 402 ▶ $i = $k if $lines->[$k] <= $index;
Branch: 1 branch
BranchTrueFalseTotal
if $lines->[$k] <= $index 242 160 402
956 }
957 }
958 3500 ▶ return $include_char ? ($i + 1, $index - $lines->[$i]) : $i + 1;
Branch: 1 branch
BranchTrueFalseTotal
$include_char ? : 3398 102 3500
959 }
960  
961 31014 ▶sub ast_string {
Subroutine ast_string: called CC=4 SCAR=13.9
Pod documented
962 31014 my ($self, $var) = @_;
963  
964 31014 ▶ return 'undef' if ! defined $var;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $var 1857 29157 31014
965 29157 ▶ return '['.join(', ', map { $self->ast_string($_) } @$var).']' if ref $var;
Branch: 1 branch
BranchTrueFalseTotal
if ref $var 8892 20265 29157
966 20265 ▶ return $var if $var =~ /^(-?[1-9]\d{0,13}|0)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $var =~ /^(-?[1-9]\d{0,13}|0)$/ 9167 11098 20265
967  
968 11098 $var =~ s/([\'\\])/\\$1/g;
969 11098 return "'$var'";
970 }
971  
972 36 ▶sub tt_var_string {
Subroutine tt_var_string: called CC=7 SCAR=19.9
Pod documented
973 36 my ($self, $ident) = @_;
974 36 ▶ if (! ref $ident) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $ident) 3 33 36
975 3 ▶ return $ident if $ident eq '0' || $ident =~ /^[1-9]\d{0,12}$/;
Branch: 1 branch
BranchTrueFalseTotal
if $ident eq 0 or $ident =~ /^[1-9]\d{0,12}$/ 3 0 3
Condition33%1/3
$ident eq 0 or $ident =~ /^[1-9]\d{0,12}$/
l!l&&r!l&&!r
030
MC/DC0%0/2
$ident eq 0 or $ident =~ /^[1-9]\d{0,12}$/
$ident eq 0 $ident =~ /^[1-9]\d{0,12}$/
Truth table33%1/3
A or B
A= $ident eq 0B= $ident =~ /^[1-9]\d{0,12}$/
ABresult
1X1
011
000
976 0 $ident =~ s/\'/\\\'/g;
977 0 return "'$ident'";
978 }
979 33 my $v = '';
980 33 ▶ for (my $i = 0; $i < @$ident; ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$ident) 51 33 84
981 51 $v .= $ident->[$i++];
982 51 ▶ $v .= '('.join(',',map{$self->tt_var_string($_)} @{$ident->[$i-1]}).')' if $ident->[$i++];
Branch: 1 branch
BranchTrueFalseTotal
if $$ident[$i++] 9 42 51
983 51 ▶ $v .= $ident->[$i++] if $i < @$ident;
Branch: 1 branch
BranchTrueFalseTotal
if $i < @$ident 18 33 51
984 }
985 33 return $v;
986 }
987  
988 223 ▶sub item_method_eval {
Subroutine item_method_eval: called CC=9 SCAR=22.0
Pod undocumented
989 223 my $self = shift;
990 223 ▶ my $text = shift; return '' if ! defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 223 223
991 223 ▶ my $args = shift || {};
Condition100%2/2
shift() || {}
l!l
60163
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
992  
993 223 ▶ local $self->{'_eval_recurse'} = $self->{'_eval_recurse'} || 0;
Condition100%2/2
$self->{'_eval_recurse'} || 0
l!l
102121
MC/DC100%1/1
$self->{'_eval_recurse'} || 0
$self->{'_eval_recurse'}
Truth table100%2/2
A
A= $self->{'_eval_recurse'}
Aresult
11
00
994 $self->throw('eval_recurse', "MAX_EVAL_RECURSE $Template::Alloy::MAX_EVAL_RECURSE reached")
995 223 ▶ if ++$self->{'_eval_recurse'} > ($self->{'MAX_EVAL_RECURSE'} || $MAX_EVAL_RECURSE);
Branch: 1 branch
BranchTrueFalseTotal
if ++$self->{"_eval_recurse"} > ($self->{"MAX_EVAL_RECURSE"} || $Template::Alloy::MAX_EVAL_RECURSE) 30 193 223
Condition66%2/3
$self->{'MAX_EVAL_RECURSE'} || $Template::Alloy::MAX_EVAL_RECURSE
l!l&&r!l&&!r
132910
MC/DC0%0/2
$self->{'MAX_EVAL_RECURSE'} || $Template::Alloy::MAX_EVAL_RECURSE
$self->{'MAX_EVAL_RECURSE'} $Template::Alloy::MAX_EVAL_RECURSE
Truth table66%2/3
A || B
A= $self->{'MAX_EVAL_RECURSE'}B= $Template::Alloy::MAX_EVAL_RECURSE
ABresult
1X1
011
000
996  
997 193 my %ARGS;
998 193 @ARGS{ map {uc} keys %$args } = values %$args;
999 193 delete @ARGS{ grep {! $Template::Alloy::EVAL_CONFIG->{$_}} keys %ARGS };
1000 193 ▶ $self->throw("eval_strict", "Cannot disable STRICT once it is enabled") if exists $ARGS{'STRICT'} && ! $ARGS{'STRICT'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $ARGS{"STRICT"} and not $ARGS{"STRICT"} 3 190 193
Condition100%3/3
exists $ARGS{"STRICT"} and not $ARGS{"STRICT"}
!ll&&!rl&&r
18463
MC/DC100%2/2
exists $ARGS{"STRICT"} and not $ARGS{"STRICT"}
exists $ARGS{"STRICT"} not $ARGS{"STRICT"}
Truth table100%3/3
A and not(B)
A= exists $ARGS{"STRICT"}B= not $ARGS{"STRICT"}
ABresult
0X0
100
111
1001  
1002 190 local @$self{ keys %ARGS } = values %ARGS;
1003 190 my $out = '';
1004 190 ▶ $self->process_simple(\$text, $self->_vars, \$out) || $self->throw($self->error);
Branch: 1 branch
BranchTrueFalseTotal
$self->process_simple(\$text, $self->_vars, \$out) or $self->throw($self->error) 179 11 190
1005 179 return $out;
1006 }
1007  
1008 10 1;
1009  
1010 ### See the perldoc in Template/Alloy.pod
« Alloy/TT.pm ↑ Summary Alloy/Parse.pm »