blib/lib/Text/Template/Compact.pm

filter: Statementstmt 93.1% 1096 / 1177 Branchbran 71.7% 337 / 470 Conditioncond 65.3% 113 / 173 MC/DCmcdc 46.0% 47 / 102 Subroutinesub 92.8% 220 / 237 Podpod 0.0% 0 / 33 totaltotal 82.7% 1813 / 2192 CC 298 SCAR 24.7
CC
298
Cov
85%
parseTemplateTag
58.9
toString
56.0
parse
44.1
CRAP 11.8
↑ Summary
1 #!perl --
2 package Text::Template::Compact;
3 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 our $VERSION = "0.1.13";
9
10 1446 ▶sub getDataType($){
Subroutine getDataType: called CC=2 SCAR=6.9
Pod undocumented
11 # return empty string if not reference type.
12 1446 ▶ return '' if not ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] 2 1443 1445
13 # use scalar to avoid bless.
14 1444 $_[0]=~/(\w+)\(/;
15 1444 return $1;
16 }
17
18 # decode "quoted" string to plain.
19 686 ▶sub decodeQuote{
Subroutine decodeQuote: called CC=4 SCAR=14.5
Pod undocumented
20 686 ▶ return if not @_ or not defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless @_ and defined $_[0] 0 685 685
Condition33%1/3
@_ and defined $_[0]
!ll&&!rl&&r
00685
MC/DC0%0/2
@_ and defined $_[0]
@_ defined $_[0]
Truth table33%1/3
A and B
A= @_B= defined $_[0]
ABresult
0X0
100
111
21 686 ▶ return $_[0] if not $_[0] =~ /^"/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^"/ 460 225 685
22 226 my $r = substr($_[0],1,length($_[0])-2);
23 226 $r =~ s/""/"/g;
24 226 return $r;
25 }
26
27 # defined or ...
28 866 ▶sub dor{
Subroutine dor: called CC=3 SCAR=11.0
Pod undocumented
29 866 ▶ for(@_){ defined($_) and return $_;}
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and return $_ 865 394 1259
30 1 return;
31 }
32
33 # filter for variable expansion
34 our %filter_map =(
35 3 ▶ raw => sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
36 3 return $_[0];
37 },
38 463 ▶ html => sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
39 463 my $a = $_[0];
40 463 $a =~ s/&/&/g;
41 463 $a =~ s/</&lt;/g;
42 463 $a =~ s/>/&gt;/g;
43 463 $a =~ s/"/&quot;/g;
44 463 $a =~ s/'/&#39;/g;
45 463 $a =~ s/\n/<br>\n/g;
46 463 return $a;
47 },
48 3 ▶ nobr => sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
49 3 my $a = $_[0];
50 3 $a =~ s/&/&amp;/g;
51 3 $a =~ s/</&lt;/g;
52 3 $a =~ s/>/&gt;/g;
53 3 $a =~ s/"/&quot;/g;
54 3 $a =~ s/'/&#39;/g;
55 3 return $a;
56 },
57 3 ▶ uri => sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
58 3 my $a = Encode::encode('utf8',$_[0]);
59 3 $a =~ s/([^a-zA-Z0-9_.!~*'()-])/'%' . unpack('H2', $1)/eg;
60 3 return $a;
61 },
62 3 );
63
64 {
65 package Text::Template::Compact::ExprParser;
66 4 ▶ use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 3 our @ExprOperator;
68 3 our %ExprOperator;
69 3 our $token_re;
70 3 our $dataset;
71 3 our $list_op_prio;
72 {
73 3 my $prio=0;
74 3 for(
75 # 優先順序が同じ場合の結合順序: L=左結合((a+b)+c) R=右結合(a=(b=c)) _=非結合
76 # 演算子の見た目:
77 # b (braket) (a) のような外見,
78 # l (left) 左側の単項演算子。 +num
79 # a (array) a[b] のような外見,
80 # r (right) 右側の単項演算子。 num++
81 # m (middle) 二項演算子 a ** b
82 # t (tri) 三項演算子 a?b:c
83 # k (keyword) 二項演算子 a.keyword 演算子の右側に式ではなくキーワードが入る
84 # c (const) 定数
85 # K (const) キーワード
86 # 優先順序の区切り: []
87 8 ▶ ['Lb','(',1,sub{ return $_[0];},')'],
Subroutine __ANON__: called CC=1 SCAR=0.0
88 1 ▶ ['La','(',1,sub{
Subroutine __ANON__: called CC=2 SCAR=7.6
89 # find list operator
90 1 my $key = $dataset->getV($_[0]);
91 1 my $op = findOp($key,qr/l/);
92 1 ▶ $op or return $dataset->encode("[Error: $op() is not found]");
Branch: 1 branch
BranchTrueFalseTotal
$op or return $Text::Template::Compact::ExprParser::dataset->encode("[Error: $op() is not found]") 0 0 0
93 1 return $op->{_eval}->($_[1]);
94 },')'],
95 [],
96 43 ▶ ['Lk','.',2,sub{ return $dataset->child($_[0],$_[1] ) } ],
Subroutine __ANON__: called CC=1 SCAR=0.0
97 14 ▶ ['La','[',2,sub{ return $dataset->child($_[0],$dataset->encode($dataset->getV($_[1]))) },']' ],
Subroutine __ANON__: called CC=1 SCAR=0.0
98 [],
99 4 ▶ ['_l','++',1,sub{ no warnings; my $v= $dataset->getV($_[0]); $dataset->setV($_[0],++$v); return $dataset->encode( $v);} ],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
100 4 ▶ ['_l','--',1,sub{ no warnings; my $v= $dataset->getV($_[0]); $dataset->setV($_[0],--$v); return $dataset->encode( $v);} ],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
101 4 ▶ ['_r','++',1,sub{ no warnings; my $v= $dataset->getV($_[0]); $dataset->setV($_[0],++$v); return $dataset->encode(--$v);} ],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
102 4 ▶ ['_r','--',1,sub{ no warnings; my $v= $dataset->getV($_[0]); $dataset->setV($_[0],--$v); return $dataset->encode(++$v);} ],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
103 [],
104 4 ▶ ['Rm','**',2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0])**$dataset->getV($_[1])); } ],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
105 [],
106 4 ▶ ['Rl','!',1,sub{ no warnings; return $dataset->encode(!$dataset->getV($_[0]))} ],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
107 4 ▶ ['Rl','~',1,sub{ no warnings; return $dataset->encode(~(0+$dataset->getV($_[0])))} ],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
108 4 ▶ ['Rl','+',1,sub{ no warnings; return $dataset->encode(+$dataset->getV($_[0]))} ],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
109 4 ▶ ['Rl','-',1,sub{ no warnings; return $dataset->encode(-$dataset->getV($_[0]))} ],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
110 [],
111 4 ▶ ['Lm','*',2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) * $dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
112 4 ▶ ['Lm','/',2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) / $dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
113 4 ▶ ['Lm','%',2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) % $dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
114 4 ▶ ['Lm','repeat',2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) x $dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
115 [],
116 4 ▶ ['Lm','+',2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) + $dataset->getV($_[1])) } ],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
117 4 ▶ ['Lm','-',2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) - $dataset->getV($_[1])) } ],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
118 4 ▶ ['Lm','cat',2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) . $dataset->getV($_[1])) } ],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
119 [],
120 4 ▶ ['Lm','<<',2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) << $dataset->getV($_[1])) } ],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
121 4 ▶ ['Lm','>>',2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) >> $dataset->getV($_[1])) } ],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
122 [],
123 50 ▶ ['_l','defined' ,1,sub{ return $dataset->encode( defined($dataset->getV($_[0])) ?1:0); }],
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $Text::Template::Compact::ExprParser::dataset->getV($_[0]) ? : 44 5 49
124 25 ▶ ['_l','bool' ,1,sub{ return $dataset->encode($dataset->getV($_[0]) ?1:0); }],
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$Text::Template::Compact::ExprParser::dataset->getV($_[0]) ? : 18 6 24
125 4 ▶ ['_l','nz' ,1,sub{ no warnings; return $dataset->encode($dataset->getV($_[0])!=0 ?1:0); }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$Text::Template::Compact::ExprParser::dataset->getV($_[0]) != 0 ? : 14 10 24
126 4 ▶ ['_l','int' ,1,sub{ no warnings; return $dataset->encode(int $dataset->getV($_[0]) ); }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
127 49 ▶ ['_l','length' ,1,sub{
Subroutine __ANON__: called CC=5 SCAR=16.1
128 49 my $v =$dataset->getV($_[0]);
129 49 ▶ defined($v) or return $dataset->encode(undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $v or return $Text::Template::Compact::ExprParser::dataset->encode(undef) 44 4 48
130 45 ▶ ref($v) or return $dataset->encode(length $v);
Branch: 1 branch
BranchTrueFalseTotal
ref $v or return $Text::Template::Compact::ExprParser::dataset->encode(length $v) 12 32 44
131 13 my $type = Text::Template::Compact::getDataType($v);
132 13 ▶ $type =~ /ARRAY/ and return $dataset->encode(scalar @$v);
Branch: 1 branch
BranchTrueFalseTotal
$type =~ /ARRAY/ and return $Text::Template::Compact::ExprParser::dataset->encode(scalar @$v) 4 8 12
133 9 ▶ $type =~ /HASH/ and return $dataset->encode(scalar keys %$v);
Branch: 1 branch
BranchTrueFalseTotal
$type =~ /HASH/ and return $Text::Template::Compact::ExprParser::dataset->encode(scalar keys %$v) 6 2 8
134 3 return $dataset->encode(length $v);
135 }],
136 2 ▶ ['l','pop',1,sub{
Subroutine __ANON__: called CC=2 SCAR=7.0
137 2 my $ra = $dataset->getV($_[0]);
138 2 ▶ if(Text::Template::Compact::getDataType($ra) =~ /ARRAY/ ){
Branch: 1 branch
BranchTrueFalseTotal
if (&Text::Template::Compact::getDataType($ra) =~ /ARRAY/) 0 1 1
139 1 return $dataset->encode( pop @$ra );
140 }
141 2 return $dataset->encode( undef );
142 }],
143 1 ▶ ['l','shift',1,sub{
Subroutine __ANON__: called CC=2 SCAR=7.6
144 1 my $ra = $dataset->getV($_[0]);
145 1 ▶ if(Text::Template::Compact::getDataType($ra) =~ /ARRAY/ ){
Branch: 1 branch
BranchTrueFalseTotal
if (&Text::Template::Compact::getDataType($ra) =~ /ARRAY/) 0 0 0
146 1 return $dataset->encode( shift @$ra );
147 }
148 1 return $dataset->encode( undef );
149 }],
150 [],
151 4 ▶ ['_m','<' ,2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) < $dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
152 4 ▶ ['_m','>' ,2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) > $dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
153 4 ▶ ['_m','<=' ,2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) <= $dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
154 4 ▶ ['_m','>=' ,2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) >= $dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
155 4 ▶ ['_m','lt' ,2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) lt $dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
156 4 ▶ ['_m','gt' ,2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) gt $dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
157 4 ▶ ['_m','le' ,2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) le $dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
158 4 ▶ ['_m','ge' ,2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) ge $dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
159 [],
160 4 ▶ ['_m','==' ,2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) == $dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
161 4 ▶ ['_m','!=' ,2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) != $dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
162 4 ▶ ['_m','<=>' ,2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) <=> $dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
163 4 ▶ ['_m','eq' ,2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) eq $dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
164 4 ▶ ['_m','ne' ,2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) ne $dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
165 4 ▶ ['_m','cmp' ,2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0]) cmp $dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
166 [],
167 4 ▶ ['Lm','&' ,2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0])+0 & 0+$dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
168 [],
169 4 ▶ ['Lm','|' ,2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0])+0 | 0+$dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
170 4 ▶ ['Lm','^' ,2,sub{ no warnings; return $dataset->encode($dataset->getV($_[0])+0 ^ 0+$dataset->getV($_[1])) }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
171 [],
172 15 ▶ ['Lm','&&',2,sub{ return $dataset->getV($_[0]) ?$_[1]:$_[0]; }],
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$Text::Template::Compact::ExprParser::dataset->getV($_[0]) ? : 10 4 14
173 [],
174 27 ▶ ['Lm','||',2,sub{ return $dataset->getV($_[0]) ?$_[0]:$_[1]; }],
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$Text::Template::Compact::ExprParser::dataset->getV($_[0]) ? : 19 7 26
175 15 ▶ ['Lm','//',2,sub{ return defined($dataset->getV($_[0])) ?$_[0]:$_[1]; }],
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $Text::Template::Compact::ExprParser::dataset->getV($_[0]) ? : 12 2 14
176 [],
177 27 ▶ ['Rt','?' ,3,sub{ return $dataset->getV($_[0])? $_[1]:$_[2]; },':'],
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$Text::Template::Compact::ExprParser::dataset->getV($_[0]) ? : 19 7 26
178 [],
179 15 ▶ [ 'Rm', '=',2,sub{ $dataset->setV($_[0],$dataset->getV($_[1]) ); return $_[0]; }],
Subroutine __ANON__: called CC=1 SCAR=0.0
180 4 ▶ [ 'Rm','**=',2,sub{ no warnings; $dataset->setV($_[0],$dataset->getV($_[0]) ** $dataset->getV($_[1]) ); return $_[0]; }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
181 4 ▶ [ 'Rm', '*=',2,sub{ no warnings; $dataset->setV($_[0],$dataset->getV($_[0]) * $dataset->getV($_[1]) ); return $_[0]; }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
182 4 ▶ [ 'Rm', '/=',2,sub{ no warnings; $dataset->setV($_[0],$dataset->getV($_[0]) / $dataset->getV($_[1]) ); return $_[0]; }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
183 4 ▶ [ 'Rm', '%=',2,sub{ no warnings; $dataset->setV($_[0],$dataset->getV($_[0]) % $dataset->getV($_[1]) ); return $_[0]; }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
184 4 ▶ [ 'Rm', '+=',2,sub{ no warnings; $dataset->setV($_[0],$dataset->getV($_[0]) + $dataset->getV($_[1]) ); return $_[0]; }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=0.0
185 4 ▶ [ 'Rm', '-=',2,sub{ no warnings; $dataset->setV($_[0],$dataset->getV($_[0]) - $dataset->getV($_[1]) ); return $_[0]; }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=0.0
186 4 ▶ [ 'Rm','<<=',2,sub{ no warnings; $dataset->setV($_[0],$dataset->getV($_[0]) << $dataset->getV($_[1]) ); return $_[0]; }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=0.0
187 4 ▶ [ 'Rm','>>=',2,sub{ no warnings; $dataset->setV($_[0],$dataset->getV($_[0]) >> $dataset->getV($_[1]) ); return $_[0]; }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=0.0
188 4 ▶ [ 'Rm','&=' ,2,sub{ no warnings; $dataset->setV($_[0],$dataset->getV($_[0])+0&0+$dataset->getV($_[1]) ); return $_[0]; }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=0.0
189 4 ▶ [ 'Rm','|=' ,2,sub{ no warnings; $dataset->setV($_[0],$dataset->getV($_[0])+0|0+$dataset->getV($_[1]) ); return $_[0]; }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=0.0
190 4 ▶ [ 'Rm','^=' ,2,sub{ no warnings; $dataset->setV($_[0],$dataset->getV($_[0])+0^0+$dataset->getV($_[1]) ); return $_[0]; }],
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=0.0
191 1 ▶ [ 'Rm','&&=',2,sub{ $dataset->getV($_[0]) and $dataset->setV($_[0],$dataset->getV($_[1])); return $_[0]; }],
Subroutine __ANON__: not called CC=2 SCAR=9.2
Branch: 1 branch
BranchTrueFalseTotal
$Text::Template::Compact::ExprParser::dataset->getV($_[0]) and $Text::Template::Compact::ExprParser::dataset->setV($_[0], $Text::Template::Compact::ExprParser::dataset->getV($_[1])) 0 0 0
192 1 ▶ [ 'Rm','||=',2,sub{ $dataset->getV($_[0]) or $dataset->setV($_[0],$dataset->getV($_[1])); return $_[0]; }],
Subroutine __ANON__: not called CC=2 SCAR=9.2
Branch: 1 branch
BranchTrueFalseTotal
$Text::Template::Compact::ExprParser::dataset->getV($_[0]) or $Text::Template::Compact::ExprParser::dataset->setV($_[0], $Text::Template::Compact::ExprParser::dataset->getV($_[1])) 0 0 0
193 1 ▶ [ 'Rm','//=',2,sub{ defined($dataset->getV($_[0])) or $dataset->setV($_[0],$dataset->getV($_[1])); return $_[0]; }],
Subroutine __ANON__: not called CC=2 SCAR=9.2
Branch: 1 branch
BranchTrueFalseTotal
defined $Text::Template::Compact::ExprParser::dataset->getV($_[0]) or $Text::Template::Compact::ExprParser::dataset->setV($_[0], $Text::Template::Compact::ExprParser::dataset->getV($_[1])) 0 0 0
194
195 [],
196 93 ▶ ['Lm',',',2,sub{ return $dataset->makepathlist($_[0],$_[1]);}],
Subroutine __ANON__: called CC=1 SCAR=0.0
197 [],
198 10 ▶ ['l','print',1,sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
199 11 my @list;
200 11 $dataset->getVlist(\@list,$_[0]);
201 11 $dataset->print( @list);
202 11 return $dataset->encode('');
203 }],
204 2 ▶ ['l','join',1,sub{
Subroutine __ANON__: called CC=2 SCAR=7.0
205 3 my @list;
206 3 $dataset->getVlist(\@list,$_[0]);
207 3 ▶ @list or return $dataset->encode('');
Branch: 1 branch
BranchTrueFalseTotal
@list or return $Text::Template::Compact::ExprParser::dataset->encode("") 2 0 2
208 3 my $delm = shift @list;
209 3 my $a = join $delm,@list;
210 3 return $dataset->encode( $a );
211 }],
212 1 ▶ ['l','scalar',1,sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
213 2 my @list;
214 2 $dataset->getVlist(\@list,$_[0]);
215 2 return $dataset->encode( scalar @list );
216 }],
217 1 ▶ ['l','push',1,sub{
Subroutine __ANON__: called CC=3 SCAR=11.6
218 2 my @list;
219 2 $dataset->getVlist(\@list,$_[0]);
220 2 ▶ if( @list and Text::Template::Compact::getDataType($list[0]) =~ /ARRAY/ ){
Branch: 1 branch
BranchTrueFalseTotal
if (@list and &Text::Template::Compact::getDataType($list[0]) =~ /ARRAY/) 0 1 1
Condition33%1/3
@list and &Text::Template::Compact::getDataType($list[0]) =~ /ARRAY/
!ll&&!rl&&r
010
MC/DC0%0/2
@list and &Text::Template::Compact::getDataType($list[0]) =~ /ARRAY/
@list &Text::Template::Compact::getDataType($list[0]) =~ /ARRAY/
Truth table33%1/3
A and B
A= @listB= &Text::Template::Compact::getDataType($list[0]) =~ /ARRAY/
ABresult
0X0
100
111
221 1 my $ra = shift @list;
222 1 push @$ra,@list;
223 }
224 2 return $dataset->encode( undef );
225 }],
226 0 ▶ ['l','unshift',1,sub{
Subroutine __ANON__: not called CC=3 SCAR=13.5
227 1 my @list;
228 1 $dataset->getVlist(\@list,$_[0]);
229 1 ▶ if(@list and Text::Template::Compact::getDataType($list[0]) =~ /ARRAY/ ){
Branch: 1 branch
BranchTrueFalseTotal
if (@list and &Text::Template::Compact::getDataType($list[0]) =~ /ARRAY/) 0 0 0
Condition0%0/3
@list and &Text::Template::Compact::getDataType($list[0]) =~ /ARRAY/
!ll&&!rl&&r
000
MC/DC0%0/2
@list and &Text::Template::Compact::getDataType($list[0]) =~ /ARRAY/
@list &Text::Template::Compact::getDataType($list[0]) =~ /ARRAY/
Truth table0%0/3
A and B
A= @listB= &Text::Template::Compact::getDataType($list[0]) =~ /ARRAY/
ABresult
0X0
100
111
230 1 my $ra = shift @list;
231 1 unshift @$ra,@list;
232 }
233 1 return $dataset->encode( undef );
234 }],
235 1 ▶ ['l','call',1,sub{
Subroutine __ANON__: called CC=6 SCAR=18.9
236 2 my @list;
237 2 $dataset->getVlist(\@list,$_[0]);
238 2 local $_ = $dataset->{tmpl}{param};
239 2 ▶ if(@list and Text::Template::Compact::getDataType($list[0]) =~ /CODE/ ){
Branch: 2 branches
BranchTrueFalseTotal
if (@list and &Text::Template::Compact::getDataType($list[0]) =~ /CODE/) { } 0 1 1
elsif (@list >= 2) { } 1 0 1
Condition33%1/3
@list and &Text::Template::Compact::getDataType($list[0]) =~ /CODE/
!ll&&!rl&&r
010
MC/DC0%0/2
@list and &Text::Template::Compact::getDataType($list[0]) =~ /CODE/
@list &Text::Template::Compact::getDataType($list[0]) =~ /CODE/
Truth table33%1/3
A and B
A= @listB= &Text::Template::Compact::getDataType($list[0]) =~ /CODE/
ABresult
0X0
100
111
240 1 my $coderef = shift @list;
241 1 my $rv = eval{ $coderef->(@list); };
242 1 ▶ $@ and $rv = "[Error: $@]";
Branch: 1 branch
BranchTrueFalseTotal
$@ and $rv = "[Error: $@]" 0 0 0
243 1 return $dataset->encode( $rv );
244 }elsif( @list >= 2 ){
245 2 my $obj = shift @list;
246 2 my $method = shift @list;
247 2 my $rv = eval{ $obj->$method(@list); };
248 2 ▶ $@ and $rv = "[Error: $@]";
Branch: 1 branch
BranchTrueFalseTotal
$@ and $rv = "[Error: $@]" 0 1 1
249 2 return $dataset->encode( $rv );
250 }
251 1 return $dataset->encode( undef );
252 }],
253 1 ▶ ['l','makearray',1,sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
254 2 my @list;
255 2 $dataset->getVlist(\@list,$_[0]);
256 2 return $dataset->encode( \@list );
257 }],
258 1 ▶ ['l','makehash',1,sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
259 2 my @list;
260 2 $dataset->getVlist(\@list,$_[0]);
261 2 return $dataset->encode( {@list} );
262 }],
263 [],
264 # not and or xor
265 73 ▶ ['Rl','not',1,sub{ return $dataset->encode(not $dataset->getV($_[0]));} ],
Subroutine __ANON__: called CC=1 SCAR=0.0
266 [],
267 21 ▶ ['Lm','and',2,sub{ return $dataset->encode( $dataset->getV($_[0]) and $dataset->getV($_[1])); }],
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%3/3
$Text::Template::Compact::ExprParser::dataset->getV($_[0]) && $Text::Template::Compact::ExprParser::dataset->getV($_[1])
!ll&&!rl&&r
1541
MC/DC100%2/2
$Text::Template::Compact::ExprParser::dataset->getV($_[0]) && $Text::Template::Compact::ExprParser::dataset->getV($_[1])
$Text::Template::Compact::ExprParser::dataset->getV($_[0]) $Text::Template::Compact::ExprParser::dataset->getV($_[1])
Truth table100%3/3
A && B
A= $Text::Template::Compact::ExprParser::dataset->getV($_[0])B= $Text::Template::Compact::ExprParser::dataset->getV($_[1])
ABresult
0X0
100
111
268 [],
269 1 ▶ ['Lm','or' ,2,sub{ return $dataset->encode( $dataset->getV($_[0]) or $dataset->getV($_[1])); }],
Subroutine __ANON__: not called CC=2 SCAR=13.0
Condition0%0/3
$Text::Template::Compact::ExprParser::dataset->getV($_[0]) || $Text::Template::Compact::ExprParser::dataset->getV($_[1])
l!l&&r!l&&!r
000
MC/DC0%0/2
$Text::Template::Compact::ExprParser::dataset->getV($_[0]) || $Text::Template::Compact::ExprParser::dataset->getV($_[1])
$Text::Template::Compact::ExprParser::dataset->getV($_[0]) $Text::Template::Compact::ExprParser::dataset->getV($_[1])
Truth table0%0/3
A || B
A= $Text::Template::Compact::ExprParser::dataset->getV($_[0])B= $Text::Template::Compact::ExprParser::dataset->getV($_[1])
ABresult
1X1
011
000
270 1 ▶ ['Lm','xor',2,sub{ return $dataset->encode( $dataset->getV($_[0]) xor $dataset->getV($_[1])); }],
Subroutine __ANON__: not called CC=2 SCAR=14.0
Condition0%0/4
$Text::Template::Compact::ExprParser::dataset->getV($_[0]) ^^ $Text::Template::Compact::ExprParser::dataset->getV($_[1])
l&&rl&&!r!l&&r!l&&!r
0000
MC/DC0%0/2
$Text::Template::Compact::ExprParser::dataset->getV($_[0]) ^^ $Text::Template::Compact::ExprParser::dataset->getV($_[1])
$Text::Template::Compact::ExprParser::dataset->getV($_[0]) $Text::Template::Compact::ExprParser::dataset->getV($_[1])
Truth table0%0/4
A ^^ B
A= $Text::Template::Compact::ExprParser::dataset->getV($_[0])B= $Text::Template::Compact::ExprParser::dataset->getV($_[1])
ABresult
110
101
011
000
271 ){
272 297 ▶ if(not @$_){ ++$prio; next; }
Branch: 1 branch
BranchTrueFalseTotal
unless (@$_) 63 234 297
273 234 my $item = {
274 prio => $prio,
275 assoc => $_->[0],
276 key1 => $_->[1],
277 count => $_->[2],
278 _eval => $_->[3],
279 key2 => $_->[4],
280 };
281 234 ▶ ( $item->{key1} eq 'print') and $list_op_prio=$prio;
Branch: 1 branch
BranchTrueFalseTotal
$item->{"key1"} eq "print" and $Text::Template::Compact::ExprParser::list_op_prio = $prio 3 231 234
282
283 234 push @ExprOperator,$item;
284 # defined($ExprOperator{ $item->{key1} }) or $ExprOperator{ $item->{key1} }=[];
285 234 push @{$ExprOperator{ $item->{key1} }},$item;
286 }
287 # make re
288 3 my %c;
289 3 for( '#',',',';','-|','$','$$',map {$_->{key1},$_->{key2}} @ExprOperator){
290 486 ▶ next if not defined or not length;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ and length $_ 222 264 486
Condition66%2/3
defined $_ and length $_
!ll&&!rl&&r
2220264
MC/DC50%1/2
defined $_ and length $_
defined $_ length $_
Truth table66%2/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
291 264 ▶ next if /^\w+$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\w+$/ 84 180 264
292 180 my $text = $_;
293 180 my $map = \%c;
294 180 ▶ for(my $i=0;$i<length($text);++$i){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $text) 294 180 474
295 294 my $c = substr($text,$i,1);
296 294 ▶ $map->{$c} or $map->{$c}={};
Branch: 1 branch
BranchTrueFalseTotal
$map->{$c} or $map->{$c} = {} 135 159 294
297 294 $map = $map->{$c};
298 }
299 }
300 162 ▶ sub toRe{
Subroutine toRe: called CC=5 SCAR=16.1
301 162 my($map)=@_;
302 162 my @list;
303 162 ▶ while(my($k,$v)=each %$map){
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$map) 159 162 321
304 159 my $sub = toRe($v);
305 159 ▶ if($sub){
Branch: 1 branch
BranchTrueFalseTotal
if ($sub) { } 60 99 159
306 60 push @list,quotemeta($k).$sub."?";
307 }else{
308 99 push @list,quotemeta($k);
309 }
310 }
311 162 ▶ @list > 1 and return "(?:".join('|',@list).")";
Branch: 1 branch
BranchTrueFalseTotal
@list > 1 and return '(?:' . join("|", @list) . ')' 27 135 162
312 135 ▶ @list and return $list[0];
Branch: 1 branch
BranchTrueFalseTotal
@list and return $list[0] 36 99 135
313 99 return;
314 }
315 3 my $a = toRe(\%c);
316 3 $token_re = qr/$a/;
317 }
318
319 1521 ▶ sub findOp{
Subroutine findOp: called CC=4 SCAR=13.9
320 1521 my($token,$re)=@_;
321 1521 ▶ my $list = $ExprOperator{ $token } or return;
Branch: 1 branch
BranchTrueFalseTotal
my $list = $Text::Template::Compact::ExprParser::ExprOperator{$token} or return 466 1055 1521
322 466 ▶ for(@$list){ return $_ if $_->{assoc} =~ $re; }
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"assoc"} =~ /$re/ 424 95 519
323 42 return;
324 }
325
326 {
327 package Text::Template::Compact::ExprNode;
328 522 ▶ sub new{
Subroutine new: called CC=3 SCAR=11.0
329 522 my($class,$op,$text)=@_;
330 522 ▶ if(not ref $op){
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $op) 285 237 522
331 # keyword?
332 285 ▶ return $text if $op eq 'k';
Branch: 1 branch
BranchTrueFalseTotal
if $op eq "k" 0 285 285
333 # root operator?
334 $op = {
335 assoc => '_',
336 key1 => 'root',
337 1282 ▶ _eval => sub{ return $_[0]; },
Subroutine __ANON__: called CC=1 SCAR=0.0
338 285 count => 1,
339 prio => 999,
340 };
341 }
342 522 return bless{ op=>$op, args=>[],},$class;
343 };
344 843 ▶ sub addArg{
Subroutine addArg: called CC=1 SCAR=0.0
345 843 my $self=shift;
346 843 push @{$self->{args}},@_;
347 }
348 0 ▶ sub toString{
Subroutine toString: not called CC=7 SCAR=40.3
349 0 my($self,$mark)=@_;
350 0 ▶ defined($mark) or $mark = '';
Branch: 1 branch
BranchTrueFalseTotal
defined $mark or $mark = "" 0 0 0
351 0 ▶ if($self->{op}{key1} eq 'root'){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"op"}{"key1"} eq "root") 0 0 0
352 0 ▶ return join(',',map{ ref($_)?$_->toString($mark):$_} @{$self->{args}});
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
353 }
354 return
355 $self->{op}{key1}
356 .($self->{closed}?$self->{op}{key2}:'')
357 .($mark eq $self ?"<=HERE=>":'')
358 .'{'
359 0 ▶ .join(',',map{ ref($_)?$_->toString($mark):$_ } @{$self->{args}} )
Branch: 3 branches
BranchTrueFalseTotal
$self->{'closed'} ? : 0 0 0
$mark eq $self ? : 0 0 0
ref $_ ? : 0 0 0
360 .'}';
361 }
362 2035 ▶ sub _eval{
Subroutine _eval: called CC=3 SCAR=11.0
363 2035 my($self)=@_;
364 2035 ▶ my @args = map{ ref($_) ? $_->_eval() : $Text::Template::Compact::ExprParser::dataset->token2path($_) } @{$self->{args}};
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 753 1770 2523
365 2035 ▶ my $r = ($self->{realop} || $self->{op})->{_eval}(@args);
Condition66%2/3
$self->{'realop'} || $self->{'op'}
l!l&&r!l&&!r
520300
MC/DC0%0/2
$self->{'realop'} || $self->{'op'}
$self->{'realop'} $self->{'op'}
Truth table66%2/3
A || B
A= $self->{'realop'}B= $self->{'op'}
ABresult
1X1
011
000
366 2035 return $r;
367 }
368 1282 ▶ sub eval{
Subroutine eval: called CC=2 SCAR=7.0
369 1282 my($self,$dataset)=@_;
370 1282 local $Text::Template::Compact::ExprParser::dataset = $dataset;
371 1282 my $r = CORE::eval{ $self->_eval();};
372 1282 ▶ $@ and return ['i',"[Error: $@ in ".$self->toString." in Text::Template::Compact::ExprNode::eval]"];
Branch: 1 branch
BranchTrueFalseTotal
$@ and return ["i", "[Error: $@ in " . $self->toString . ' in Text::Template::Compact::ExprNode::eval]'] 0 1282 1282
373 1282 return $r;
374 }
375 }
376
377 3 our $verbose = 0;
378
379 2393 ▶ sub peekToken{
Subroutine peekToken: called CC=2 SCAR=6.9
380 2393 my $self = shift;
381 2393 ▶ @{$self->{token}} and return $self->{token}[0];
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{"token"};} and return $self->{"token"}[0] 1222 1171 2393
382 1171 return;
383 }
384 999 ▶ sub reduce{
Subroutine reduce: called CC=14 SCAR=28.0
385 999 my($self,$where)=@_;
386
387 999 ▶ return if $self->{allow_child};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"allow_child"} 486 513 999
388
389 513 my $a = $self->peekToken;
390
391 # スタックが空ならreduceできない
392 513 ▶ return if @{$self->{stack}}==1;
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"stack"};} == 1 285 228 513
393
394 228 my $target = $self->{stack}[0];
395
396 # 注目ノードの種別が () []だった
397 228 ▶ if( $target->{op}{assoc} =~ /[ba]/ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($target->{'op'}{'assoc'} =~ /[ba]/) { } 25 203 228
398 25 ▶ if( defined($a) and $a eq $target->{op}{key2}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $a and $a eq $target->{"op"}{"key2"} and @{$target->{"args"};} == $target->{"op"}{"count"}) 25 0 25
Condition33%2/6
defined $a and $a eq $target->{"op"}{"key2"} and @{$target->{"args"};} == $target->{"op"}{"count"}
!ll&&!rl&&r
0025
defined $a and $a eq $target->{"op"}{"key2"}
!ll&&!rl&&r
0025
MC/DC0%0/3
defined $a and $a eq $target->{"op"}{"key2"} and @{$target->{"args"};} == $target->{"op"}{"count"}
defined $a $a eq $target->{"op"}{"key2"} @{$target->{"args"};} == $target->{"op"}{"count"}
Truth table25%1/4
A and B and C
A= defined $aB= $a eq $target->{"op"}{"key2"}C= @{$target->{"args"};} == $target->{"op"}{"count"}
ABCresult
0XX0
10X0
1100
1111
399 25 and @{$target->{args}} == $target->{op}->{count}
400 ){
401 25 ▶ $verbose>0 and warn "remove end of braket $target->{op}{key2}. reduce in $where\n";
Branch: 1 branch
BranchTrueFalseTotal
$Text::Template::Compact::ExprParser::verbose > 0 and warn qq[remove end of braket $target->{"op"}{"key2"}. reduce in $where\n] 0 25 25
402 25 $target->{closed} = 1;
403 25 shift @{$self->{token}};
404 25 shift @{$self->{stack}};
405 25 $self->{allow_child} = 0;
406 25 return 1;
407 }
408 }else{
409 203 ▶ if( @{$target->{args}} == $target->{op}->{count} ){
Branch: 1 branch
BranchTrueFalseTotal
if (@{$target->{"args"};} == $target->{"op"}{"count"}) 199 4 203
410 199 ▶ $verbose>0 and warn "end of operator $target->{op}{key1} . reduce in $where\n";
Branch: 1 branch
BranchTrueFalseTotal
$Text::Template::Compact::ExprParser::verbose > 0 and warn qq[end of operator $target->{"op"}{"key1"} . reduce in $where\n] 0 199 199
411 199 shift @{$self->{stack}};
412 199 $self->{allow_child} = 0;
413 199 return 1;
414 }
415 # ?:
416 4 ▶ if( $target->{op}{assoc} =~ /t/ and $a and $a eq $target->{op}->{key2} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($target->{"op"}{"assoc"} =~ /t/ and $a and $a eq $target->{"op"}{"key2"}) 4 0 4
Condition33%2/6
$target->{"op"}{"assoc"} =~ /t/ and $a and $a eq $target->{"op"}{"key2"}
!ll&&!rl&&r
004
$target->{"op"}{"assoc"} =~ /t/ and $a
!ll&&!rl&&r
004
MC/DC0%0/3
$target->{"op"}{"assoc"} =~ /t/ and $a and $a eq $target->{"op"}{"key2"}
$target->{"op"}{"assoc"} =~ /t/ $a $a eq $target->{"op"}{"key2"}
Truth table25%1/4
A and B and C
A= $target->{"op"}{"assoc"} =~ /t/B= $aC= $a eq $target->{"op"}{"key2"}
ABCresult
0XX0
10X0
1100
1111
417 4 ▶ $verbose>0 and warn "eating ':' operator . reduce in $where\n";
Branch: 1 branch
BranchTrueFalseTotal
$Text::Template::Compact::ExprParser::verbose > 0 and warn "eating ':' operator . reduce in $where\n" 0 4 4
418 4 shift @{$self->{token}};
419 4 $self->{allow_child} = 1;
420 4 return 1;
421 }
422 }
423 0 return;
424 }
425
426 285 ▶ sub parse{
Subroutine parse: called CC=37 SCAR=37.9
427 285 my($list)=@_;
428
429 285 my $self = bless{
430 allow_child => 1,
431 stack=>[new Text::Template::Compact::ExprNode('')],
432 token=>$list,
433 };
434
435 285 my($op,$node);
436
437 285 Loop: for(;;){
438 1151 my $target = $self->{stack}[0];
439 1151 my $token = $self->peekToken;
440 0 ▶ $verbose>0 and warn "mode=$self->{allow_child} token:",($token||'')," stack:",join(',',map{$_->{op}{key1}} @{$self->{stack}}),"\n";
Branch: 1 branch
BranchTrueFalseTotal
$Text::Template::Compact::ExprParser::verbose > 0 and warn qq[mode=$self->{"allow_child"} token:], $token || "", " stack:", join(",", map({$_->{"op"}{"key1"};} @{$$self{"stack"};})), "\n" 0 1151 1151
Condition0%0/2
$token || ''
l!l
00
MC/DC0%0/1
$token || ''
$token
Truth table0%0/2
A
A= $token
Aresult
11
00
441
442
443 # reduce if possible
444 1151 ▶ if( not defined($token)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $token and findOp($token, qr/[armtk]/)) 969 182 1151
Condition100%3/3
defined $token and findOp($token, qr/[armtk]/)
!ll&&!rl&&r
366603182
MC/DC100%2/2
defined $token and findOp($token, qr/[armtk]/)
defined $token findOp($token, qr/[armtk]/)
Truth table100%3/3
A and B
A= defined $tokenB= findOp($token, qr/[armtk]/)
ABresult
0X0
100
111
445 or not findOp( $token,qr/[armtk]/ )
446 ){
447 969 ▶ next if $self->reduce('loop');
Branch: 1 branch
BranchTrueFalseTotal
if $self->reduce("loop") 198 771 969
448 }
449
450 953 ▶ last if not defined($token);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $token 235 718 953
451
452 718 ▶ if( $self->{allow_child} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'allow_child'}) { } 506 212 718
453 506 my $op = findOp($token,qr/[bl]/);
454 506 ▶ if($op){
Branch: 1 branch
BranchTrueFalseTotal
if ($op) 62 444 506
455 # listop(b) ??
456 62 ▶ if( @{$self->{token}} >= 2
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"token"};} >= 2 and $op->{"key1"} =~ /^\w/ and $self->{"token"}[1] eq "(") 5 57 62
Condition83%5/6
@{$self->{"token"};} >= 2 and $op->{"key1"} =~ /^\w/ and $self->{"token"}[1] eq "("
!ll&&!rl&&r
24335
@{$self->{"token"};} >= 2 and $op->{"key1"} =~ /^\w/
!ll&&!rl&&r
02438
MC/DC66%2/3
@{$self->{"token"};} >= 2 and $op->{"key1"} =~ /^\w/ and $self->{"token"}[1] eq "("
@{$self->{"token"};} >= 2 $op->{"key1"} =~ /^\w/ $self->{"token"}[1] eq "("
Truth table75%3/4
A and B and C
A= @{$self->{"token"};} >= 2B= $op->{"key1"} =~ /^\w/C= $self->{"token"}[1] eq "("
ABCresult
0XX0
10X0
1100
1111
457 and $op->{key1} =~/^\w/
458 and $self->{token}[1] eq '('
459 ){
460 5 ▶ $verbose>0 and warn "start of term $token(?) \n";
Branch: 1 branch
BranchTrueFalseTotal
$Text::Template::Compact::ExprParser::verbose > 0 and warn "start of term $token(?) \n" 0 5 5
461 5 shift @{$self->{token}};
462 5 shift @{$self->{token}};
463 5 $node = new Text::Template::Compact::ExprNode(findOp('(',qr/a/));
464 5 $target->addArg($node);
465 5 unshift @{$self->{stack}},$node;
466 5 $self->{allow_child} = 1;
467 5 $node->{realop} = $op;
468 5 next;
469 }
470
471 # unary left or '('
472 57 ▶ $verbose>0 and warn "operator $token start\n";
Branch: 1 branch
BranchTrueFalseTotal
$Text::Template::Compact::ExprParser::verbose > 0 and warn "operator $token start\n" 0 57 57
473 57 shift @{$self->{token}};
474 57 $node = new Text::Template::Compact::ExprNode($op);
475 57 $target->addArg($node);
476 57 unshift @{$self->{stack}},$node;
477 57 $self->{allow_child} = 1;
478 57 next;
479 }
480
481 # keyword or constant or $,$$
482 444 ▶ if( $token =~/^["\w\d_\$]/ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($token =~ /^["\w\d_\$]/) 444 0 444
483 444 ▶ $verbose>0 and warn "constant or keyword $token\n";
Branch: 1 branch
BranchTrueFalseTotal
$Text::Template::Compact::ExprParser::verbose > 0 and warn "constant or keyword $token\n" 0 444 444
484 444 $target->addArg(shift @{$self->{token}});
485 444 $self->{allow_child} = 0;
486
487 # $keyword
488 444 my $old_arg = $target->{args}[-1];
489 444 $token = $self->peekToken;
490 444 ▶ if( defined($token) and $token =~/^["\w\d_]/ and $old_arg =~/^\$/ ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $token and $token =~ /^["\w\d_]/ and $old_arg =~ /^\$/) 13 431 444
Condition100%6/6
defined $token and $token =~ /^["\w\d_]/ and $old_arg =~ /^\$/
!ll&&!rl&&r
3983313
defined $token and $token =~ /^["\w\d_]/
!ll&&!rl&&r
20419446
MC/DC100%3/3
defined $token and $token =~ /^["\w\d_]/ and $old_arg =~ /^\$/
defined $token $token =~ /^["\w\d_]/ $old_arg =~ /^\$/
Truth table100%4/4
A and B and C
A= defined $tokenB= $token =~ /^["\w\d_]/C= $old_arg =~ /^\$/
ABCresult
0XX0
10X0
1100
1111
491 13 ▶ $verbose>0 and warn "merge '$old_arg' and '$token'\n";
Branch: 1 branch
BranchTrueFalseTotal
$Text::Template::Compact::ExprParser::verbose > 0 and warn "merge '${old_arg}' and '${token}'\n" 0 13 13
492 13 $node = new Text::Template::Compact::ExprNode(findOp('.',qr/[armtk]/));
493 13 $target->{args}[-1] = $node;
494 13 $node->addArg($old_arg,$token);
495 13 shift @{$self->{token}};
496 }
497 444 next;
498 }
499 }else{
500
501 212 $op = findOp($token,qr/[armtk]/);
502 212 ▶ if($op){
Branch: 1 branch
BranchTrueFalseTotal
if ($op) 162 50 212
503 162 $node = new Text::Template::Compact::ExprNode($op);
504 162 my $a;
505 162 ▶ while(@{$self->{stack}}){
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"stack"};}) 192 0 192
506 192 my($left,$right) =($target->{op},$op);
507 192 my($left_prio,$right_prio) =($left->{prio},$right->{prio});
508 192 my($left_assoc,$right_assoc) =($left->{assoc},$right->{assoc});
509
510 192 ▶ if( $left_assoc =~ /[ba]/ and not $target->{closed} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($left_assoc =~ /[ba]/ and not $target->{'closed'}) { } 21 171 192
Condition66%2/3
$left_assoc =~ /[ba]/ and not $target->{"closed"}
!ll&&!rl&&r
171021
MC/DC50%1/2
$left_assoc =~ /[ba]/ and not $target->{"closed"}
$left_assoc =~ /[ba]/ not $target->{"closed"}
Truth table66%2/3
A and not(B)
A= $left_assoc =~ /[ba]/B= not $target->{"closed"}
ABresult
0X0
100
111
511 # if inside of non closed braket, always right combination
512 21 $a=1;
513 }else{
514 # List Operators (Leftward) has very high priority
515 171 ▶ if( $right_prio == $list_op_prio ){
Branch: 1 branch
BranchTrueFalseTotal
if ($right_prio == $Text::Template::Compact::ExprParser::list_op_prio) 0 171 171
516 0 $right_prio = 0;
517 }
518 # compare operator precedence
519 171 $a = $left_prio - $right_prio;
520 171 ▶ if(!$a){
Branch: 1 branch
BranchTrueFalseTotal
unless ($a) 24 147 171
521 # if same, check left or right associativity
522 24 ▶ if( $left_assoc =~/L/ ){ $a=-1;}
Branch: 2 branches
BranchTrueFalseTotal
if ($left_assoc =~ /L/) { } 24 0 24
elsif ($left_assoc =~ /R/) { } 0 0 0
523 0 elsif( $left_assoc =~/R/ ){ $a= 1;}
524 else{
525 0 die "repeating non-assoc operator. $left->{key1} $right->{key1}\n";
526 }
527 }
528 }
529 192 ▶ $verbose>0 and warn "lr=$a $left->{key1} $right->{key1}\n";
Branch: 1 branch
BranchTrueFalseTotal
$Text::Template::Compact::ExprParser::verbose > 0 and warn qq[lr=$a $left->{"key1"} $right->{"key1"}\n] 0 192 192
530
531 192 ▶ if($a>0){ #right a+(b*c)
Branch: 1 branch
BranchTrueFalseTotal
if ($a > 0) 162 30 192
532 162 ▶ $verbose>0 and warn "appending right combination\n";
Branch: 1 branch
BranchTrueFalseTotal
$Text::Template::Compact::ExprParser::verbose > 0 and warn "appending right combination\n" 0 162 162
533 162 shift @{$self->{token}};
534 162 my $b = pop @{$target->{args}};
535 162 $target->addArg($node);
536 162 unshift @{$self->{stack}},$node;
537 162 $node->addArg($b);
538 162 $target=$self->{stack}[0];
539 162 ▶ if( @{$target->{args}} < $target->{op}{count} ){
Branch: 1 branch
BranchTrueFalseTotal
if (@{$target->{"args"};} < $target->{"op"}{"count"}) 155 7 162
540 155 $self->{allow_child} =1;
541 }
542 162 next Loop;
543 }
544
545 30 ▶ if( not $self->reduce("left combination $target->{op}->{key1} $op->{key1}") ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->reduce(qq[left combination $target->{"op"}{"key1"} $op->{"key1"}])) 0 30 30
546 # warn "reduce failed: ",Data::Dumper::Dumper($target),"\n";
547 0 die "cannot resolve operator precedence between '$target->{op}->{key1}' and '$op->{key1}'\n";
548 }
549 30 $target=$self->{stack}[0];
550 }
551 }
552 }
553 50 last;
554 }
555 0 ▶ $verbose>0 and warn "end. stack=",join(',',map{$_->{op}->{key1}} @{$self->{stack}}),"\n";
Branch: 1 branch
BranchTrueFalseTotal
$Text::Template::Compact::ExprParser::verbose > 0 and warn "end. stack=", join(",", map({$_->{"op"}{"key1"};} @{$$self{"stack"};})), "\n" 0 285 285
556 285 my $token = $self->peekToken;
557 285 ▶ @{$self->{stack}}==1 or die "expression is not completed at '",(defined($token)?"'$token'":"end of statement"),"'\n";
Branch: 2 branches
BranchTrueFalseTotal
@{$self->{"stack"};} == 1 or die "expression is not completed at '", defined $token ? "'${token}'" : "end of statement", "'\n" 285 0 285
defined $token ? : 0 0 0
558 285 ▶ @{$self->{stack}[0]{args}} or die "expression not found\n";
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{"stack"}[0]{"args"};} or die "expression not found\n" 285 0 285
559 285 return $self->{stack}[0];
560 }
561 }
562
563 {
564 3 package Text::Template::Compact::Dataset;
565
566 3 *getDataType = \&Text::Template::Compact::getDataType;
567 3 *decodeQuote = \&Text::Template::Compact::decodeQuote;
568
569 1282 ▶ sub new{
Subroutine new: called CC=1 SCAR=0.0
570 1282 my($class,$tmpl,$tag)=@_;
571 return bless {
572 tmpl=>$tmpl,
573 tag=>$tag,
574 enc => $tmpl->{paramEncoding},
575 1282 },$class;
576 }
577
578 10 ▶ sub print{
Subroutine print: called CC=3 SCAR=11.4
579 10 my($self)=shift;
580 10 my $printer = $self->{tmpl}{printer};
581 10 ▶ my $filter = ( $self->{tag}{filter} || $self->{tmpl}{filter_default} );
Condition33%1/3
$self->{'tag'}{'filter'} || $self->{'tmpl'}{'filter_default'}
l!l&&r!l&&!r
0100
MC/DC0%0/2
$self->{'tag'}{'filter'} || $self->{'tmpl'}{'filter_default'}
$self->{'tag'}{'filter'} $self->{'tmpl'}{'filter_default'}
Truth table33%1/3
A || B
A= $self->{'tag'}{'filter'}B= $self->{'tmpl'}{'filter_default'}
ABresult
1X1
011
000
582 10 for(@_){ $printer->( $filter->( Text::Template::Compact::dor($_,$self->{tmpl}{undef_supply}))); }
583 }
584
585 # make path from token
586 1770 ▶ sub token2path{
Subroutine token2path: called CC=3 SCAR=11.0
587 1770 my($self,$token)=@_;
588 1770 ▶ if( $token =~ /^"/
Branch: 1 branch
BranchTrueFalseTotal
if ($token =~ /^"/ or $token =~ /^\d/) 439 1331 1770
Condition100%3/3
$token =~ /^"/ or $token =~ /^\d/
l!l&&r!l&&!r
1672721331
MC/DC100%2/2
$token =~ /^"/ or $token =~ /^\d/
$token =~ /^"/ $token =~ /^\d/
Truth table100%3/3
A or B
A= $token =~ /^"/B= $token =~ /^\d/
ABresult
1X1
011
000
589 or $token =~ /^\d/
590 ){
591 439 return ['i',decodeQuote($token)];
592 }
593 1331 return ['k',$token];
594 }
595
596 92 ▶ sub makepathlist{
Subroutine makepathlist: called CC=1 SCAR=0.0
597 92 my($self) = shift;
598 92 return [ 'l',@_];
599 }
600
601 1945 ▶ sub endoflist{
Subroutine endoflist: called CC=2 SCAR=6.9
602 1945 my($self,$path)=@_;
603 1945 ▶ ( $path->[0] eq 'l' ) and return $self->endoflist($path->[-1]);
Branch: 1 branch
BranchTrueFalseTotal
$path->[0] eq "l" and return $self->endoflist($path->[-1]) 3 1942 1945
604 1942 return $path;
605 }
606
607 582 ▶ sub getVlist{
Subroutine getVlist: called CC=3 SCAR=11.0
608 582 my($self,$result,$path)=@_;
609 582 ▶ if( $path->[0] eq 'l' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($path->[0] eq 'l') { } 88 494 582
610 88 ▶ for(my $i=1;$i<@$path;++$i){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$path) 176 88 264
611 176 $self->getVlist($result,$path->[$i]);
612 }
613 }else{
614 494 my $val = $self->getV($path);
615 494 push @$result,$val;
616 }
617 }
618
619 # make data path from immediate value
620 518 ▶ sub encode{
Subroutine encode: called CC=1 SCAR=0.0
621 518 my($self,$value)=@_;
622 518 return ['i',$value];
623 }
624
625 # make relative data path
626 55 ▶ sub child{
Subroutine child: called CC=3 SCAR=11.0
627 55 my($self,$path,$rel)=@_;
628 55 my $r = ['p',[]];
629
630 # get right item if arg is list
631 55 $path = $self->endoflist($path);
632 55 $rel = $self->endoflist($rel);
633
634 # copy parent
635 55 ▶ if($path->[0] eq 'p'){
Branch: 1 branch
BranchTrueFalseTotal
if ($path->[0] eq 'p') { } 6 49 55
636 6 push @{$r->[1]} , @{$path->[1]};
637 }else{
638 49 push @{$r->[1]} , $path->[1];
639 }
640
641 # copy child
642 55 ▶ if($rel->[0] eq 'p'){
Branch: 1 branch
BranchTrueFalseTotal
if ($rel->[0] eq 'p') { } 2 53 55
643 2 push @{$r->[1]} , @{$rel->[1]};
644 }else{
645 53 push @{$r->[1]} , $rel->[1];
646 }
647
648 # make
649 55 return $r;
650 }
651
652 # get value in data path
653 1830 ▶ sub getV{
Subroutine getV: called CC=16 SCAR=27.9
654 1830 my($self,$path)=@_;
655 1830 ▶ ref($path) or die "incorrect path\n";
Branch: 1 branch
BranchTrueFalseTotal
ref $path or die "incorrect path\n" 1830 0 1830
656
657 # get right item if arg is list
658 1830 $path = $self->endoflist($path);
659
660 # immidiate value
661 1830 ▶ return $path->[1] if $path->[0] eq 'i';
Branch: 1 branch
BranchTrueFalseTotal
if $path->[0] eq "i" 843 987 1830
662
663 987 my @path;
664 987 ▶ if( $path->[0] eq 'p' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($path->[0] eq 'p') { } 42 945 987
665 42 push @path,@{$path->[1]};
666 }else{
667 945 push @path,$path->[1];
668 }
669
670 987 my $param = $self->{tmpl}{param};
671 987 my $path_str = '$';
672 987 ▶ if( $path[0] eq '$' ){
Branch: 2 branches
BranchTrueFalseTotal
if ($path[0] eq '$') { } 10 977 987
elsif ($path[0] eq '$$') { } 2 975 977
673 10 shift @path;
674 }elsif( $path[0] eq '$$' ){
675 2 shift @path;
676 2 $param = $self->{tmpl};
677 }
678
679 987 ▶ while(@path){
Branch: 1 branch
BranchTrueFalseTotal
if (@path) 1025 987 2012
680 1025 my $key = shift @path;
681 1025 my $type = getDataType($param);
682 1025 ▶ if( $type eq 'ARRAY' ){
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'ARRAY') { } 27 998 1025
elsif ($type eq 'HASH') { } 998 0 998
683 4 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
684 27 $param = $param->[$key];
685 }elsif($type eq 'HASH' ){
686 4 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
687 998 $param = $param->{$key};
688 }else{
689 0 die "incorrect data path $path_str\n";
690 }
691 1025 ▶ $path_str .= (length($path_str)?'.':'').$key;
Branch: 1 branch
BranchTrueFalseTotal
length $path_str ? : 1025 0 1025
692 1025 ▶ (@path and not ref $param) and die "incorrect data path $path_str\n";
Branch: 1 branch
BranchTrueFalseTotal
@path and not ref $param and die "incorrect data path $path_str\n" 0 1025 1025
Condition66%2/3
@path and not ref $param
!ll&&!rl&&r
987380
MC/DC0%0/2
@path and not ref $param
@path not ref $param
Truth table66%2/3
A and not(B)
A= @pathB= not ref $param
ABresult
0X0
100
111
693 }
694 987 ▶ if( defined $param
Branch: 1 branch
BranchTrueFalseTotal
if (defined $param and not ref $param and not utf8::is_utf8($param) and defined $self->{"enc"}) 701 286 987
Condition88%8/9
defined $param and not ref $param and not utf8::is_utf8($param) and defined $self->{"enc"}
!ll&&!rl&&r
2860701
defined $param and not ref $param and not utf8::is_utf8($param)
!ll&&!rl&&r
183103701
defined $param and not ref $param
!ll&&!rl&&r
40143804
MC/DC75%3/4
defined $param and not ref $param and not utf8::is_utf8($param) and defined $self->{"enc"}
defined $param not ref $param not utf8::is_utf8($param) defined $self->{"enc"}
Truth table80%4/5
A and not(B) and not(C) and D
A= defined $paramB= not ref $paramC= not utf8::is_utf8($param)D= defined $self->{"enc"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
695 and not ref($param)
696 and not utf8::is_utf8($param)
697 and defined $self->{enc}
698 ){
699 701 return Encode::decode($self->{enc},$param);
700 }
701 286 return $param;
702 }
703 # set value to data path
704 405 ▶ sub setV{
Subroutine setV: called CC=13 SCAR=33.7
705 405 my($self,$path,$newval)=@_;
706
707 # get right item if arg is list
708 405 ▶ ($path->[0] eq 'l') and $path = $self->endoflist($path);
Branch: 1 branch
BranchTrueFalseTotal
$path->[0] eq "l" and $path = $self->endoflist($path) 0 405 405
709
710 405 ▶ if( $path->[0] eq 'i' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($path->[0] eq "i") 0 405 405
711 0 die "L-Value required\n";
712 }
713
714 405 my @path;
715 405 ▶ if( $path->[0] eq 'p' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($path->[0] eq 'p') { } 5 400 405
716 5 push @path,@{$path->[1]};
717 }else{
718 400 push @path,$path->[1];
719 }
720
721 405 my $param = $self->{tmpl}{param};
722 405 my $path_str = '$';
723 405 ▶ if( $path[0] eq '$' ){
Branch: 2 branches
BranchTrueFalseTotal
if ($path[0] eq '$') { } 5 400 405
elsif ($path[0] eq '$$') { } 0 400 400
724 5 shift @path;
725 }elsif( $path[0] eq '$$' ){
726 0 shift @path;
727 0 $param = $self->{tmpl};
728 }
729
730 405 ▶ while(@path){
Branch: 1 branch
BranchTrueFalseTotal
if (@path) 405 0 405
731 405 my $key = shift @path;
732 405 my $type = getDataType($param);
733 405 ▶ if( $type eq 'ARRAY' ){
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'ARRAY') { } 0 405 405
elsif ($type eq 'HASH') { } 405 0 405
734 0 ▶ if(not @path){
Branch: 1 branch
BranchTrueFalseTotal
if (not @path) { } 0 0 0
735 0 my $old = $param->[$key];
736 0 $param->[$key] = $newval;
737 0 return \$old;
738 }else{
739 0 $param = $param->[$key];
740 }
741 }elsif($type eq 'HASH' ){
742 405 ▶ if(not @path){
Branch: 1 branch
BranchTrueFalseTotal
if (not @path) { } 405 0 405
743 405 my $old = $param->{$key};
744 405 $param->{$key} = $newval;
745 405 return \$old;
746 }else{
747 0 $param = $param->{$key};
748 }
749 }else{
750 0 die "incorrect data path $path_str\n";
751 }
752 0 $path_str .= '.'.$key;
753 0 ▶ (@path and not ref $param) and die "incorrect data path $path_str\n";
Branch: 1 branch
BranchTrueFalseTotal
@path and not ref $param and die "incorrect data path $path_str\n" 0 0 0
Condition0%0/3
@path and not ref $param
!ll&&!rl&&r
000
MC/DC0%0/2
@path and not ref $param
@path not ref $param
Truth table0%0/3
A and not(B)
A= @pathB= not ref $param
ABresult
0X0
100
111
754 }
755 }
756 }
757
758 # record parse error and die (should be catch in parser)
759 3 ▶sub parseError{
Subroutine parseError: not called CC=1 SCAR=4.9
Pod undocumented
760 0 my($self)=shift;
761 0 my $msg = join('',"$self->{source_name} $self->{lno}: ",@_);
762 0 $msg =~ s/[\x0d\x0a]+//g;
763 0 push @{$self->{error}},$msg;
764 0 croak $msg,"\n";
765 }
766
767 285 ▶sub parseExpr{
Subroutine parseExpr: called CC=2 SCAR=7.0
Pod undocumented
768 285 my($self,$list)=@_;
769 285 my $r = eval{ Text::Template::Compact::ExprParser::parse($list);};
770 285 ▶ $@ and $self->parseError($@);
Branch: 1 branch
BranchTrueFalseTotal
$@ and $self->parseError($@) 0 285 285
771 285 return $r;
772 }
773
774 535 ▶sub evalExpr{
Subroutine evalExpr: called CC=2 SCAR=7.5
Pod undocumented
775 535 my($tmpl,$tag,$expr)=@_;
776 535 my $dataset = new Text::Template::Compact::Dataset($tmpl,$tag);
777 535 my $r = eval{ $dataset->getV( $expr->eval($dataset) );};
778 535 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 535 535
779 0 $r = "[Error: $@ in evalExpr]";
780 0 $r =~s/[\x0d\x0a]+//g;
781 }
782 535 return $r;
783 }
784 389 ▶sub evalExprList{
Subroutine evalExprList: called CC=2 SCAR=7.6
Pod undocumented
785 389 my($tmpl,$tag,$expr)=@_;
786 389 my $dataset = new Text::Template::Compact::Dataset($tmpl,$tag);
787 389 my @list;
788 389 eval{ $dataset->getVlist( \@list,$expr->eval($dataset) ); };
789 389 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 389 389
790 0 my $r = "[Error: $@ in evalExprList]";
791 0 $r =~s/[\x0d\x0a]+//g;
792 0 return $r;
793 }
794 389 return @list;
795 }
796 2 ▶sub evalExprKw{
Subroutine evalExprKw: called CC=4 SCAR=20.3
Pod undocumented
797 2 my($tmpl,$tag,$expr)=@_;
798 2 my $dataset = new Text::Template::Compact::Dataset($tmpl,$tag);
799 2 my $path = eval{ $expr->eval($dataset); };
800 2 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
801 0 my $r = "[Error: $@ in evalExprKw]";
802 0 $r =~s/[\x0d\x0a]+//g;
803 0 return $r;
804 }
805 2 $path = $dataset->endoflist($path);
806 2 ▶ return $path->[1] if $path->[0] =~/[ki]/;
Branch: 1 branch
BranchTrueFalseTotal
if $path->[0] =~ /[ki]/ 2 0 2
807
808 0 my $v = eval{ $dataset->getV( $path );};
809 0 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
810 0 my $r = "[Error: $@ in evalExprKw]";
811 0 $r =~s/[\x0d\x0a]+//g;
812 0 return $r;
813 }
814 0 return $v;
815 }
816
817
818
819 356 ▶sub setExprValue{
Subroutine setExprValue: called CC=2 SCAR=7.3
Pod undocumented
820 356 my($tmpl,$tag,$expr,$newval)=@_;
821 356 my $dataset = new Text::Template::Compact::Dataset($tmpl,$tag);
822 356 my $path = $expr->eval($dataset);
823 356 my $r = eval{ $dataset->setV($path,$newval);};
824 356 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 356 356
825 0 $r = "[Error: $@ in setExprValue]";
826 0 $r =~s/[\x0d\x0a]+//g;
827 }
828 356 return $r;
829 }
830
831 # eat specified token at head of the list. otherwise return undef.
832 20 ▶sub eatType{
Subroutine eatType: called CC=4 SCAR=17.9
Pod undocumented
833 20 my($list,$type)=@_;
834 20 ▶ if( @$list and ref($list->[0]) and $list->[0]->{$type} ){
Branch: 1 branch
BranchTrueFalseTotal
if (@$list and ref $list->[0] and $list->[0]{$type}) 20 0 20
Condition33%2/6
@$list and ref $list->[0] and $list->[0]{$type}
!ll&&!rl&&r
0020
@$list and ref $list->[0]
!ll&&!rl&&r
0020
MC/DC0%0/3
@$list and ref $list->[0] and $list->[0]{$type}
@$list ref $list->[0] $list->[0]{$type}
Truth table25%1/4
A and B and C
A= @$listB= ref $list->[0]C= $list->[0]{$type}
ABCresult
0XX0
10X0
1100
1111
835 20 return shift @$list;
836 }
837 0 return;
838 }
839
840 ######################################
841
842
843 # print %eval tag
844 6 ▶sub print_eval{
Subroutine print_eval: called CC=1 SCAR=0.0
Pod undocumented
845 6 my($tmpl,$tag)=@_;
846 6 $tmpl->evalExpr($tag,$tag->{expr});
847 6 return;
848 }
849
850 # print %var tag
851 389 ▶sub print_var{
Subroutine print_var: called CC=2 SCAR=6.9
Pod undocumented
852 389 my($tmpl,$tag)=@_;
853 389 my $printer = $tmpl->{printer};
854 389 my $filter = dor( $tag->{filter} ,$tmpl->{filter_default} );
855 389 for my $value ( $tmpl->evalExprList($tag,$tag->{expr}) ){
856 449 $value = dor($value,$tmpl->{undef_supply});
857 449 $printer->( $filter->($value));
858 }
859 389 return;
860 }
861
862 8 ▶sub evalLabel($$$){
Subroutine evalLabel: called CC=2 SCAR=6.9
Pod undocumented
863 8 my($tmpl,$tag,$label)=@_;
864 8 ▶ return '' if not defined $label;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $label 6 2 8
865 2 return $tmpl->evalExprKw($tag,$label);
866 }
867
868 # print %for tag
869 20 ▶sub print_for{
Subroutine print_for: called CC=13 SCAR=26.0
Pod undocumented
870 20 my($tmpl,$tag)=@_;
871 20 my $list = $tmpl->evalExpr($tag,$tag->{listname});
872 20 my $index = 0;
873 20 ▶ $tag->{indexstart} and $index = $tmpl->evalExpr($tag,$tag->{indexstart});
Branch: 1 branch
BranchTrueFalseTotal
$tag->{"indexstart"} and $index = $tmpl->evalExpr($tag, $tag->{"indexstart"}) 2 18 20
874 20 for my $v (@$list){
875 139 my $oldr;
876 my $oldi;
877 139 ▶ if($tag->{itemname}){
Branch: 1 branch
BranchTrueFalseTotal
if ($tag->{"itemname"}) 139 0 139
878 139 $oldr = $tmpl->setExprValue($tag,$tag->{itemname},$v);
879 139 ▶ ref($oldr) or $tmpl->{printer}->($oldr);
Branch: 1 branch
BranchTrueFalseTotal
ref $oldr or $tmpl->{"printer"}->($oldr) 139 0 139
880 }
881 139 ▶ if($tag->{indexname}){
Branch: 1 branch
BranchTrueFalseTotal
if ($tag->{"indexname"}) 4 135 139
882 4 $oldi = $tmpl->setExprValue($tag,$tag->{indexname},$index++);
883 4 ▶ ref($oldi) or $tmpl->{printer}->($oldi);
Branch: 1 branch
BranchTrueFalseTotal
ref $oldi or $tmpl->{"printer"}->($oldi) 4 0 4
884 }
885 139 my $exit_tag = $tmpl->printBlock( $tag->{block} );
886 139 ▶ ref($oldr) and $tmpl->setExprValue($tag,$tag->{itemname} ,$$oldr);
Branch: 1 branch
BranchTrueFalseTotal
ref $oldr and $tmpl->setExprValue($tag, $tag->{"itemname"}, $$oldr) 139 0 139
887 139 ▶ ref($oldi) and $tmpl->setExprValue($tag,$tag->{indexname} ,$$oldi);
Branch: 1 branch
BranchTrueFalseTotal
ref $oldi and $tmpl->setExprValue($tag, $tag->{"indexname"}, $$oldi) 4 135 139
888
889 139 ▶ if($exit_tag){
Branch: 1 branch
BranchTrueFalseTotal
if ($exit_tag) 7 132 139
890 # not for this block?
891 7 ▶ return $exit_tag if dor($tag->{label},'') ne evalLabel($tmpl,$tag,$exit_tag->{label});
Branch: 1 branch
BranchTrueFalseTotal
if dor($tag->{"label"}, "") ne &evalLabel($tmpl, $tag, $exit_tag->{"label"}) 1 6 7
892 # for this block.
893 6 ▶ next if $exit_tag->{continue};
Branch: 1 branch
BranchTrueFalseTotal
if $exit_tag->{"continue"} 0 6 6
894 6 ▶ last if $exit_tag->{break};
Branch: 1 branch
BranchTrueFalseTotal
if $exit_tag->{"break"} 6 0 6
895 }
896 }
897 19 return;
898 }
899
900 3 ▶sub print_while{
Subroutine print_while: called CC=11 SCAR=24.1
Pod undocumented
901 3 my($tmpl,$tag)=@_;
902 3 ▶ $tag->{ex_init} and $tmpl->evalExpr($tag,$tag->{ex_init});
Branch: 1 branch
BranchTrueFalseTotal
$tag->{"ex_init"} and $tmpl->evalExpr($tag, $tag->{"ex_init"}) 3 0 3
903 3 my $exit_tag;
904 3 for(;;){
905 30 ▶ last if $tag->{ex_precheck} and not $tmpl->evalExpr($tag,$tag->{ex_precheck});
Branch: 1 branch
BranchTrueFalseTotal
if $tag->{"ex_precheck"} and not $tmpl->evalExpr($tag, $tag->{"ex_precheck"}) 1 29 30
Condition100%3/3
$tag->{"ex_precheck"} and not $tmpl->evalExpr($tag, $tag->{"ex_precheck"})
!ll&&!rl&&r
19101
MC/DC100%2/2
$tag->{"ex_precheck"} and not $tmpl->evalExpr($tag, $tag->{"ex_precheck"})
$tag->{"ex_precheck"} not $tmpl->evalExpr($tag, $tag->{"ex_precheck"})
Truth table100%3/3
A and not(B)
A= $tag->{"ex_precheck"}B= not $tmpl->evalExpr($tag, $tag->{"ex_precheck"})
ABresult
0X0
100
111
906 29 $exit_tag = $tmpl->printBlock( $tag->{block} );
907 29 ▶ if($exit_tag){
Branch: 1 branch
BranchTrueFalseTotal
if ($exit_tag) 1 28 29
908 # not for this block?
909 1 ▶ last if dor($tag->{label},'') ne evalLabel($tmpl,$tag,$exit_tag->{label});
Branch: 1 branch
BranchTrueFalseTotal
if dor($tag->{"label"}, "") ne &evalLabel($tmpl, $tag, $exit_tag->{"label"}) 0 1 1
910 # for this block.
911 1 ▶ if($exit_tag->{break}){
Branch: 1 branch
BranchTrueFalseTotal
if ($exit_tag->{"break"}) 1 0 1
912 1 undef $exit_tag;
913 1 last;
914 }
915 }
916 28 ▶ last if $tag->{ex_postcheck} and not $tmpl->evalExpr($tag,$tag->{ex_postcheck});
Branch: 1 branch
BranchTrueFalseTotal
if $tag->{"ex_postcheck"} and not $tmpl->evalExpr($tag, $tag->{"ex_postcheck"}) 1 27 28
Condition100%3/3
$tag->{"ex_postcheck"} and not $tmpl->evalExpr($tag, $tag->{"ex_postcheck"})
!ll&&!rl&&r
10171
MC/DC100%2/2
$tag->{"ex_postcheck"} and not $tmpl->evalExpr($tag, $tag->{"ex_postcheck"})
$tag->{"ex_postcheck"} not $tmpl->evalExpr($tag, $tag->{"ex_postcheck"})
Truth table100%3/3
A and not(B)
A= $tag->{"ex_postcheck"}B= not $tmpl->evalExpr($tag, $tag->{"ex_postcheck"})
ABresult
0X0
100
111
917 27 ▶ $tag->{ex_step} and $tmpl->evalExpr($tag,$tag->{ex_step});
Branch: 1 branch
BranchTrueFalseTotal
$tag->{"ex_step"} and $tmpl->evalExpr($tag, $tag->{"ex_step"}) 27 0 27
918 }
919 3 ▶ $tag->{ex_final} and $tmpl->evalExpr($tag,$tag->{ex_final});
Branch: 1 branch
BranchTrueFalseTotal
$tag->{"ex_final"} and $tmpl->evalExpr($tag, $tag->{"ex_final"}) 1 2 3
920 3 return $exit_tag;
921 }
922
923 # print %blockpaste tag
924 6 ▶sub print_block{
Subroutine print_block: called CC=4 SCAR=18.6
Pod undocumented
925 6 my($tmpl,$tag)=@_;
926 6 my $block = $tmpl->{block}{$tag->{name}};
927 6 ▶ if(not defined($block) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $block) 0 6 6
928 0 $tmpl->{printer}->( "[Error: block '$tag->{name}' is not defined]" );
929 0 return;
930 }
931 6 my $exit_tag = $tmpl->printBlock( $block );
932 6 ▶ return if not $exit_tag;
Branch: 1 branch
BranchTrueFalseTotal
unless $exit_tag 6 0 6
933 # not for this block?
934 0 ▶ return $exit_tag if dor($tag->{label},'') ne evalLabel($tmpl,$tag,$exit_tag->{label});
Branch: 1 branch
BranchTrueFalseTotal
if dor($tag->{"label"}, "") ne &evalLabel($tmpl, $tag, $exit_tag->{"label"}) 0 0 0
935 # for this block.
936 # no difference between break or continue, just exit this block.
937 0 return;
938 }
939
940 2 ▶sub _clean_error {
Subroutine _clean_error: called CC=1 SCAR=0.0
941 2 my ($error) = @_;
942 2 $error=~s/^Execution of .* aborted due to compilation errors.\n//m;
943 2 return $error;
944 }
945
946 # print %eval tag
947 74 ▶sub print_evalperl{
Subroutine print_evalperl: called CC=4 SCAR=13.9
Pod undocumented
948 74 my($tmpl,$tag)=@_;
949 74 local $_ = $tmpl->{param};
950 74 my $code = $tag->{code};
951 74 my @data = map{ $tmpl->evalExpr($tag,$_) } @{$tag->{args}};
952 74 my $a_code =ord('a');
953 74 ▶ @data and $code = "my(".join(',',map{my $c=chr($_+$a_code);"\$$c"}(0..$#data)).")=\@data;$code";
Branch: 1 branch
BranchTrueFalseTotal
@data and $code = 'my(' . join(",", map({my $c = chr $_ + $a_code; "\$$c";} 0 .. $#data)) . ")=\@data;$code" 34 40 74
954 74 ▶ my $r = eval "{no warnings; $code;}";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
955 74 ▶ $@ and $tmpl->{printer}->( sprintf "[eval failed: %s]", _clean_error($@) );
Branch: 1 branch
BranchTrueFalseTotal
$@ and $tmpl->{"printer"}->(sprintf("[eval failed: %s]", _clean_error($@))) 2 72 74
956 74 ▶ $tag->{result} and $tmpl->setExprValue($tag,$tag->{result},$r);
Branch: 1 branch
BranchTrueFalseTotal
$tag->{"result"} and $tmpl->setExprValue($tag, $tag->{"result"}, $r) 70 4 74
957 74 return;
958 }
959
960
961 # print %else tag
962 175 ▶sub print_else{
Subroutine print_else: called CC=5 SCAR=17.5
Pod undocumented
963 175 my($tmpl,$tag)=@_;
964
965 175 my $exit_tag = $tmpl->printBlock( $tag->{block} );
966
967 # normally 'if' is not match for break,continue
968 # match only label is explicitly specified in both of block and break.
969 175 ▶ if( $exit_tag
Branch: 1 branch
BranchTrueFalseTotal
if ($exit_tag and defined $exit_tag->{"label"} and defined $tag->{"label"} and $exit_tag->{"label"} eq $tag->{"label"}) 0 175 175
Condition66%6/9
$exit_tag and defined $exit_tag->{"label"} and defined $tag->{"label"} and $exit_tag->{"label"} eq $tag->{"label"}
!ll&&!rl&&r
17500
$exit_tag and defined $exit_tag->{"label"} and defined $tag->{"label"}
!ll&&!rl&&r
17410
$exit_tag and defined $exit_tag->{"label"}
!ll&&!rl&&r
16861
MC/DC0%0/4
$exit_tag and defined $exit_tag->{"label"} and defined $tag->{"label"} and $exit_tag->{"label"} eq $tag->{"label"}
$exit_tag defined $exit_tag->{"label"} defined $tag->{"label"} $exit_tag->{"label"} eq $tag->{"label"}
Truth table60%3/5
A and B and C and D
A= $exit_tagB= defined $exit_tag->{"label"}C= defined $tag->{"label"}D= $exit_tag->{"label"} eq $tag->{"label"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
970 and defined($exit_tag->{label})
971 and defined($tag->{label})
972 and $exit_tag->{label} eq $tag->{label}
973 ){
974 # exit_tag is solved in this scope.
975 0 return;
976 }
977 175 return $exit_tag;
978 }
979
980 # print %if tag
981 275 ▶sub print_if_simple{
Subroutine print_if_simple: called CC=3 SCAR=11.0
Pod undocumented
982 275 my($tmpl,$tag)=@_;
983 275 my $value = $tmpl->evalExpr($tag,$tag->{expr});
984 275 ▶ $value and return print_else($tmpl,$tag);
Branch: 1 branch
BranchTrueFalseTotal
$value and return print_else($tmpl, $tag) 109 166 275
985 166 $tag=$tag->{next};
986 166 ▶ $tag->{printer} and return $tag->{printer}($tmpl,$tag);
Branch: 1 branch
BranchTrueFalseTotal
$tag->{"printer"} and return $tag->{"printer"}->($tmpl, $tag) 24 142 166
987 142 return;
988 }
989
990 # print %if tag
991 126 ▶sub print_if_code{
Subroutine print_if_code: called CC=5 SCAR=16.1
Pod undocumented
992 126 my($tmpl,$tag)=@_;
993 126 my @data = map{ $tmpl->evalExpr($tag,$_) } @{$tag->{args}};
994 126 my $code = $tag->{code};
995 126 my $a_code =ord('a');
996 126 ▶ @data and $code = "my(".join(',',map{my $c=chr($_+$a_code);"\$$c"}(0..$#data)).")=\@data;$code";
Branch: 1 branch
BranchTrueFalseTotal
@data and $code = 'my(' . join(",", map({my $c = chr $_ + $a_code; "\$$c";} 0 .. $#data)) . ")=\@data;$code" 126 0 126
997 126 local $_ = $tmpl->{param};
998 126 ▶ my $value = eval "no warnings; $code";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
999 126 ▶ $@ and $tmpl->{printer}->( sprintf "[eval failed: %s]", _clean_error($@) );
Branch: 1 branch
BranchTrueFalseTotal
$@ and $tmpl->{"printer"}->(sprintf("[eval failed: %s]", _clean_error($@))) 0 126 126
1000
1001 126 ▶ $value and return print_else($tmpl,$tag);
Branch: 1 branch
BranchTrueFalseTotal
$value and return print_else($tmpl, $tag) 54 72 126
1002 72 $tag=$tag->{next};
1003 72 ▶ $tag->{printer} and return $tag->{printer}($tmpl,$tag);
Branch: 1 branch
BranchTrueFalseTotal
$tag->{"printer"} and return $tag->{"printer"}->($tmpl, $tag) 24 48 72
1004 48 return;
1005 }
1006
1007 #####################################################
1008
1009 # parse template tag
1010 300 ▶sub parseTemplateTag{
Subroutine parseTemplateTag: called CC=54 SCAR=40.8
Pod undocumented
1011 300 my($self,$text)=@_;
1012
1013 # split to token list
1014 300 my @list = $text =~ /$Text::Template::Compact::ExprParser::token_re|"(?:[^"]|"")*"|[\w_]+|\p{IsWord}+/g;
1015 300 ▶ @list or die $self->parseError("empty template tag");
Branch: 1 branch
BranchTrueFalseTotal
@list or die $self->parseError("empty template tag") 300 0 300
1016
1017 # parse filter
1018 300 my $filter;
1019 300 ▶ if( @list >= 2 and $filter_map{ $list[-1] } and $list[-2] eq '#' ){
Branch: 1 branch
BranchTrueFalseTotal
if (@list >= 2 and $Text::Template::Compact::filter_map{$list[-1]} and $list[-2] eq "#") 8 292 300
Condition83%5/6
@list >= 2 and $Text::Template::Compact::filter_map{$list[-1]} and $list[-2] eq "#"
!ll&&!rl&&r
29208
@list >= 2 and $Text::Template::Compact::filter_map{$list[-1]}
!ll&&!rl&&r
342588
MC/DC66%2/3
@list >= 2 and $Text::Template::Compact::filter_map{$list[-1]} and $list[-2] eq "#"
@list >= 2 $Text::Template::Compact::filter_map{$list[-1]} $list[-2] eq "#"
Truth table75%3/4
A and B and C
A= @list >= 2B= $Text::Template::Compact::filter_map{$list[-1]}C= $list[-2] eq "#"
ABCresult
0XX0
10X0
1100
1111
1020 8 $filter = $filter_map{ $list[@list-1] };
1021 8 splice @list,@list-2;
1022 }
1023
1024 300 my @taglist;
1025 my $type;
1026 300 ▶ while(@list){
Branch: 1 branch
BranchTrueFalseTotal
if (@list) 352 300 652
1027 352 ▶ if($list[0] eq ';'){
Branch: 1 branch
BranchTrueFalseTotal
if ($list[0] eq ";") 29 323 352
1028 29 shift @list;
1029 29 next;
1030 }
1031
1032 323 my $item = {lno=>$self->{lno}};
1033 323 ▶ $filter and $item->{filter} = $filter;
Branch: 1 branch
BranchTrueFalseTotal
$filter and $item->{"filter"} = $filter 8 315 323
1034
1035 # read label:
1036 323 ▶ if( @list >= 2
Branch: 1 branch
BranchTrueFalseTotal
if (@list >= 2 and $list[1] eq ":" and $list[0] =~ /^\w/) 1 322 323
Condition83%5/6
@list >= 2 and $list[1] eq ":" and $list[0] =~ /^\w/
!ll&&!rl&&r
32201
@list >= 2 and $list[1] eq ":"
!ll&&!rl&&r
422801
MC/DC66%2/3
@list >= 2 and $list[1] eq ":" and $list[0] =~ /^\w/
@list >= 2 $list[1] eq ":" $list[0] =~ /^\w/
Truth table75%3/4
A and B and C
A= @list >= 2B= $list[1] eq ":"C= $list[0] =~ /^\w/
ABCresult
0XX0
10X0
1100
1111
1037 and $list[1] eq ':'
1038 and $list[0] =~/^\w/
1039 ){
1040 1 $item->{label} = $list[0];
1041 1 splice @list,0,2;
1042 1 ▶ last if not @list;
Branch: 1 branch
BranchTrueFalseTotal
unless @list 0 1 1
1043 }
1044
1045 # % type
1046 323 ▶ if( $list[0] eq '%' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($list[0] eq '%') { } 180 143 323
1047 # skip '%'
1048 180 shift @list;
1049 # read type of tag
1050 180 ▶ @list or $self->parseError("no tag type after '%'");
Branch: 1 branch
BranchTrueFalseTotal
@list or $self->parseError("no tag type after '%'") 180 0 180
1051 180 $type = lc decodeQuote(shift @list);
1052 }else{
1053 143 $type = 'print';
1054 }
1055
1056 323 $item->{$item->{type}=$type}=1;
1057
1058 323 ▶ if( $type eq 'print' ){
Branch: 12 branches
BranchTrueFalseTotal
if ($type eq 'print') { } 150 173 323
elsif ($type eq 'eval') { } 6 167 173
elsif ($type eq 'if' or $type eq 'elsif') { } 25 142 167
elsif ($type eq 'ifc' or $type eq 'elsifc') { } 14 128 142
elsif ($type eq 'else') { } 4 124 128
elsif ($type eq 'end') { } 51 73 124
elsif ($type eq 'break' or $type eq 'continue') { } 3 70 73
elsif ($type eq 'end') { } 0 70 70
elsif ($type eq 'for') { } 15 55 70
elsif ($type eq 'while') { } 3 52 55
elsif ($type eq 'blockdefine' or $type eq 'blockpaste') { } 8 44 52
elsif ($type eq 'evalperl') { } 44 0 44
1059 # %print expr,expr...
1060 150 $item->{printer}=\&print_var;
1061 150 $item->{expr} = $self->parseExpr(\@list);
1062
1063 }elsif( $type eq 'eval' ){
1064 # %print expr,expr...
1065 6 $item->{printer}=\&print_eval;
1066 6 $item->{expr} = $self->parseExpr(\@list);
1067
1068 ▶ }elsif( $type eq 'if' or $type eq 'elsif' ){
Condition100%3/3
$type eq "if" or $type eq "elsif"
l!l&&r!l&&!r
214142
MC/DC100%2/2
$type eq "if" or $type eq "elsif"
$type eq "if" $type eq "elsif"
Truth table100%3/3
A or B
A= $type eq "if"B= $type eq "elsif"
ABresult
1X1
011
000
1069 # %if expr
1070 # %elsif expr
1071 25 $item->{printer}=\&print_if_simple;
1072 25 $item->{expr} = $self->parseExpr(\@list);
1073
1074 ▶ }elsif( $type eq 'ifc' or $type eq 'elsifc' ){
Condition100%3/3
$type eq "ifc" or $type eq "elsifc"
l!l&&r!l&&!r
104128
MC/DC100%2/2
$type eq "ifc" or $type eq "elsifc"
$type eq "ifc" $type eq "elsifc"
Truth table100%3/3
A or B
A= $type eq "ifc"B= $type eq "elsifc"
ABresult
1X1
011
000
1075 # %ifc "code" dataspec dataspec ...
1076 # %elsifc "code" dataspec dataspec ...
1077 14 $item->{printer}=\&print_if_code;
1078 14 $item->{code} =decodeQuote(shift @list);
1079 14 $item->{args}=[];
1080 14 ▶ while(@list and $list[0] ne ';' ){
Branch: 1 branch
BranchTrueFalseTotal
if (@list and $list[0] ne ";") 15 14 29
Condition66%2/3
@list and $list[0] ne ";"
!ll&&!rl&&r
14015
MC/DC50%1/2
@list and $list[0] ne ";"
@list $list[0] ne ";"
Truth table66%2/3
A and B
A= @listB= $list[0] ne ";"
ABresult
0X0
100
111
1081 15 push @{$item->{args}},$self->parseExpr(\@list);
1082 }
1083
1084 }elsif( $type eq 'else'){
1085 # %else
1086 4 $item->{printer}=\&print_else;
1087
1088 }elsif( $type eq 'end'){
1089 # %end
1090
1091 ▶ }elsif( $type eq 'break' or $type eq 'continue' ){
Condition66%2/3
$type eq "break" or $type eq "continue"
l!l&&r!l&&!r
3070
MC/DC50%1/2
$type eq "break" or $type eq "continue"
$type eq "break" $type eq "continue"
Truth table66%2/3
A or B
A= $type eq "break"B= $type eq "continue"
ABresult
1X1
011
000
1092 # %break [label]
1093 # %continue [label]
1094 3 ▶ if( @list and $list[0] ne ';'){
Branch: 1 branch
BranchTrueFalseTotal
if (@list and $list[0] ne ";") 1 2 3
Condition66%2/3
@list and $list[0] ne ";"
!ll&&!rl&&r
021
MC/DC50%1/2
@list and $list[0] ne ";"
@list $list[0] ne ";"
Truth table66%2/3
A and B
A= @listB= $list[0] ne ";"
ABresult
0X0
100
111
1095 1 $item->{label} = $self->parseExpr(\@list);
1096 }
1097
1098 }elsif( $type eq 'end'){
1099 # %end
1100
1101 }elsif( $type eq 'for' ){
1102 # %for item in list indexname indexstart
1103 15 $item->{printer}=\&print_for;
1104 15 $item->{itemname} = $self->parseExpr(\@list);
1105
1106 15 ▶ (not @list or not $list[0] eq 'in' ) and $self->parseError("expected 'in' keyword is not found.");
Branch: 1 branch
BranchTrueFalseTotal
@list and $list[0] eq "in" or $self->parseError("expected 'in' keyword is not found.") 15 0 15
Condition33%1/3
@list and $list[0] eq "in"
!ll&&!rl&&r
0015
MC/DC0%0/2
@list and $list[0] eq "in"
@list $list[0] eq "in"
Truth table33%1/3
A and B
A= @listB= $list[0] eq "in"
ABresult
0X0
100
111
1107 15 shift @list;
1108
1109 15 $item->{listname} = $self->parseExpr(\@list);
1110
1111 15 ▶ (@list and $list[0] ne ';') and $item->{indexname} = $self->parseExpr(\@list);
Branch: 1 branch
BranchTrueFalseTotal
@list and $list[0] ne ";" and $item->{"indexname"} = $self->parseExpr(\@list) 2 13 15
Condition100%3/3
@list and $list[0] ne ";"
!ll&&!rl&&r
1122
MC/DC100%2/2
@list and $list[0] ne ";"
@list $list[0] ne ";"
Truth table100%3/3
A and B
A= @listB= $list[0] ne ";"
ABresult
0X0
100
111
1112 15 ▶ (@list and $list[0] ne ';') and $item->{indexstart} = $self->parseExpr(\@list);
Branch: 1 branch
BranchTrueFalseTotal
@list and $list[0] ne ";" and $item->{"indexstart"} = $self->parseExpr(\@list) 2 13 15
Condition100%3/3
@list and $list[0] ne ";"
!ll&&!rl&&r
1122
MC/DC100%2/2
@list and $list[0] ne ";"
@list $list[0] ne ";"
Truth table100%3/3
A and B
A= @listB= $list[0] ne ";"
ABresult
0X0
100
111
1113
1114 }elsif( $type eq 'while' ){
1115 # %for item in list indexname indexstart
1116 3 $item->{printer}=\&print_while;
1117 3 ▶ Loop: while( @list and $list[0] ne ';' ){
Branch: 1 branch
BranchTrueFalseTotal
if (@list and $list[0] ne ";") 10 3 13
Condition66%2/3
@list and $list[0] ne ";"
!ll&&!rl&&r
0310
MC/DC50%1/2
@list and $list[0] ne ";"
@list $list[0] ne ";"
Truth table66%2/3
A and B
A= @listB= $list[0] ne ";"
ABresult
0X0
100
111
1118 10 for (qw( init precheck postcheck step final )){
1119 28 ▶ if( $list[0] eq $_ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($list[0] eq $_) 10 18 28
1120 10 shift @list;
1121 10 $item->{"ex_$_"} = $self->parseExpr(\@list);
1122 10 next Loop;
1123 }
1124 }
1125 0 $self->parseError("expected 'init/precheck/postcheck/step/final' not found.");
1126 }
1127
1128 ▶ }elsif( $type eq 'blockdefine' or $type eq 'blockpaste' ){
Condition100%3/3
$type eq "blockdefine" or $type eq "blockpaste"
l!l&&r!l&&!r
2644
MC/DC100%2/2
$type eq "blockdefine" or $type eq "blockpaste"
$type eq "blockdefine" $type eq "blockpaste"
Truth table100%3/3
A or B
A= $type eq "blockdefine"B= $type eq "blockpaste"
ABresult
1X1
011
000
1129 # %blockdefine blockname
1130 # %blockpaste blockname
1131 8 $item->{printer}=\&print_block;
1132 8 ▶ @list or $self->parseError("no block name after $type");
Branch: 1 branch
BranchTrueFalseTotal
@list or $self->parseError("no block name after $type") 8 0 8
1133 8 $item->{name} = decodeQuote(shift @list);
1134 8 ▶ if( $type eq 'blockdefine' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "blockdefine") 2 6 8
1135 2 ▶ defined( $self->{block}{$item->{name}} ) and $self->parseError("redefined block '$item->{name}'");
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"block"}{$item->{"name"}} and $self->parseError(qq[redefined block '$item->{"name"}']) 0 2 2
1136 2 $self->{block}{$item->{name}} = [];
1137 }
1138 }elsif( $type eq 'evalperl' ){
1139 # %evalperl "code" [result] [arg]...
1140 44 $item->{printer}=\&print_evalperl;
1141 44 ▶ @list or $self->parseError("no text after 'evalperl'");
Branch: 1 branch
BranchTrueFalseTotal
@list or $self->parseError("no text after 'evalperl'") 44 0 44
1142 44 ▶ $list[0] =~ /^"/ or $self->parseError("you must quote code with \"...\"");
Branch: 1 branch
BranchTrueFalseTotal
$list[0] =~ /^"/ or $self->parseError("you must quote code with \"...\"") 44 0 44
1143 44 $item->{code} = decodeQuote(shift @list);
1144 44 ▶ @list and $item->{result} = $self->parseExpr(\@list);
Branch: 1 branch
BranchTrueFalseTotal
@list and $item->{"result"} = $self->parseExpr(\@list) 40 4 44
1145 44 $item->{args} = [];
1146 44 ▶ while(@list and $list[0] ne ';' ){
Branch: 1 branch
BranchTrueFalseTotal
if (@list and $list[0] ne ";") 4 44 48
Condition66%2/3
@list and $list[0] ne ";"
!ll&&!rl&&r
4404
MC/DC50%1/2
@list and $list[0] ne ";"
@list $list[0] ne ";"
Truth table66%2/3
A and B
A= @listB= $list[0] ne ";"
ABresult
0X0
100
111
1147 4 push @{$item->{args}},$self->parseExpr(\@list);
1148 }
1149 }else{
1150 # unsupported tag type
1151 0 $self->parseError("unsupported tag type '$type'");
1152 }
1153 323 ▶ @list and $list[0] ne ';' and $self->parseError("unexpected token '$list[0]' in template tag");
Branch: 1 branch
BranchTrueFalseTotal
@list and $list[0] ne ";" and $self->parseError("unexpected token '$list[0]' in template tag") 0 323 323
Condition66%2/3
@list and $list[0] ne ";"
!ll&&!rl&&r
294290
MC/DC0%0/2
@list and $list[0] ne ";"
@list $list[0] ne ";"
Truth table66%2/3
A and B
A= @listB= $list[0] ne ";"
ABresult
0X0
100
111
1154 323 push @taglist,$item;
1155 }
1156 300 return @taglist;
1157 }
1158
1159 # compose tree of tag and text.
1160 125 ▶sub parseBlock{
Subroutine parseBlock: called CC=15 SCAR=27.2
Pod undocumented
1161 125 my($self,$rList,$block)=@_;
1162
1163 125 ▶ while(@$rList){
Branch: 1 branch
BranchTrueFalseTotal
if (@$rList) 569 62 631
1164 569 my $item = $rList->[0];
1165 # normal text
1166 569 ▶ if( not ref($item) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $item) 246 323 569
1167 246 push @$block, shift @$rList;
1168 246 next;
1169 }
1170 # exit before end of block
1171 323 ▶ last if grep {$item->{type} eq $_} qw( end else elsif elsifc );
Branch: 1 branch
BranchTrueFalseTotal
if grep {$item->{"type"} eq $_;} "end", "else", "elsif", "elsifc" 63 260 323
1172
1173 # %blockdefine
1174 260 ▶ if( $item->{blockdefine} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($item->{"blockdefine"}) 2 258 260
1175 2 shift @$rList;
1176 2 $self->parseBlock( $rList,$self->{block}{$item->{name}});
1177 2 ▶ eatType($rList,'end') or $self->parseError("missing end of blockdefine (start at $item->{lno})");
Branch: 1 branch
BranchTrueFalseTotal
eatType($rList, "end") or $self->parseError(qq[missing end of blockdefine (start at $item->{"lno"})]) 2 0 2
1178 2 next;
1179 }
1180
1181 # append to current block
1182 258 push @$block, shift @$rList;
1183
1184 # %for
1185 258 ▶ if( $item->{for} or $item->{while} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($item->{"for"} or $item->{"while"}) 18 240 258
Condition100%3/3
$item->{"for"} or $item->{"while"}
l!l&&r!l&&!r
153240
MC/DC100%2/2
$item->{"for"} or $item->{"while"}
$item->{"for"} $item->{"while"}
Truth table100%3/3
A or B
A= $item->{"for"}B= $item->{"while"}
ABresult
1X1
011
000
1186 18 $item->{block} = [];
1187 18 $self->parseBlock( $rList ,$item->{block});
1188 18 ▶ eatType($rList,'end') or $self->parseError("missing end of $item->{type} loop (start at $item->{lno})");
Branch: 1 branch
BranchTrueFalseTotal
eatType($rList, "end") or $self->parseError(qq[missing end of $item->{"type"} loop (start at $item->{"lno"})]) 18 0 18
1189 18 next;
1190 }
1191
1192 # %if ,%elsif,%else
1193 240 ▶ if( $item->{if} or $item->{ifc}){
Branch: 1 branch
BranchTrueFalseTotal
if ($item->{"if"} or $item->{"ifc"}) 31 209 240
Condition100%3/3
$item->{"if"} or $item->{"ifc"}
l!l&&r!l&&!r
2110209
MC/DC100%2/2
$item->{"if"} or $item->{"ifc"}
$item->{"if"} $item->{"ifc"}
Truth table100%3/3
A or B
A= $item->{"if"}B= $item->{"ifc"}
ABresult
1X1
011
000
1194 31 for(;;$item = $item->{next}){
1195 43 $item->{block} = [];
1196 43 $self->parseBlock( $rList ,$item->{block});
1197 43 ▶ @$rList or $self->parseError("missing end of if/elsif/else/elsifc block (start at $item->{lno})");
Branch: 1 branch
BranchTrueFalseTotal
@$rList or $self->parseError(qq[missing end of if/elsif/else/elsifc block (start at $item->{"lno"})]) 43 0 43
1198 43 $item->{next} = shift @$rList;
1199 43 ▶ last if $item->{next}{end};
Branch: 1 branch
BranchTrueFalseTotal
if $item->{"next"}{"end"} 31 12 43
1200 12 ▶ $item->{label} and not defined($item->{next}->{label}) and $item->{next}->{label}=$item->{label};
Branch: 1 branch
BranchTrueFalseTotal
$item->{"label"} and not defined $item->{"next"}{"label"} and $item->{"next"}{"label"} = $item->{"label"} 0 12 12
Condition33%1/3
$item->{"label"} and not defined $item->{"next"}{"label"}
!ll&&!rl&&r
1200
MC/DC0%0/2
$item->{"label"} and not defined $item->{"next"}{"label"}
$item->{"label"} not defined $item->{"next"}{"label"}
Truth table33%1/3
A and not(B)
A= $item->{"label"}B= not defined $item->{"next"}{"label"}
ABresult
0X0
100
111
1201 }
1202 31 next;
1203 }
1204 }
1205 }
1206
1207 399 ▶sub closeLine{
Subroutine closeLine: called CC=10 SCAR=23.0
Pod undocumented
1208 399 my($rAll,$rLine)=@_;
1209 my $a = grep{
1210 399 ▶ if( ref($_) ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_) { } 323 370 693
1211 323 $_->{print};
1212 }else{
1213 370 ▶ $_ =~ /[^\s ]/ ?1:0;
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /[^\s\x{3000}]/ ? : 318 52 370
1214 }
1215 } @$rLine;
1216 399 ▶ if($a){
Branch: 1 branch
BranchTrueFalseTotal
if ($a) { } 275 124 399
1217 275 for (@$rLine,"\x0a"){
1218 875 ▶ if(not ref($_)
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_ and @$rAll and not ref $rAll->[-1]) { } 386 489 875
Condition100%6/6
not ref $_ and @$rAll and not ref $rAll->[-1]
!ll&&!rl&&r
249240386
not ref $_ and @$rAll
!ll&&!rl&&r
2436626
MC/DC100%3/3
not ref $_ and @$rAll and not ref $rAll->[-1]
not ref $_ @$rAll not ref $rAll->[-1]
Truth table100%4/4
not(A) and B and not(C)
A= not ref $_B= @$rAllC= not ref $rAll->[-1]
ABCresult
0XX0
10X0
1100
1111
1219 and @$rAll
1220 and not ref($rAll->[-1])
1221 ){
1222 386 $rAll->[-1].= $_;
1223 }else{
1224 489 push @$rAll,$_;
1225 }
1226 }
1227 }else{
1228 124 for (@$rLine){
1229 93 ▶ ref($_) and push @$rAll,$_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ and push @$rAll, $_ 80 13 93
1230 }
1231 }
1232 399 @$rLine = ();
1233 }
1234
1235 # convert from source text to template structure.
1236 # $ok = $tmpl->loadText($filename,\$text [,$blockname]);
1237 62 ▶sub loadText{
Subroutine loadText: called CC=8 SCAR=21.2
Pod undocumented
1238 62 my $self = shift;
1239 62 $self->{error}=[];
1240 62 $self->{lno}=1;
1241 62 $self->{source_name} = $_[0];
1242 62 ▶ my $rText = ref($_[1])?$_[1]:\$_[1];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] ? : 62 0 62
1243 62 ▶ my $blockname = ($_[2] || "");
Condition50%1/2
$_[2] || ''
l!l
062
MC/DC0%0/1
$_[2] || ''
$_[2]
Truth table50%1/2
A
A= $_[2]
Aresult
11
00
1244
1245 # split source to tag and text
1246 62 my @list;
1247 my @line;
1248 62 my $lastend = 0;
1249 62 ▶ while( $$rText =~ /(\x0D\x0A|\x0D|\x0A)|(?<!\$)(\$\{(?:[^}"]*|"(?:[^"]|"")*")+)\}/gs ){
Branch: 1 branch
BranchTrueFalseTotal
if ($$rText =~ /(\x0D\x0A|\x0D|\x0A)|(?<!\$)(\$\{(?:[^}"]*|"(?:[^"]|"")*")+)\}/gs) 699 62 761
1250 699 my $pre = substr($$rText,$lastend,$-[0] - $lastend); $lastend = $+[0];
1251 699 ▶ if( defined($1) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $1) { } 399 300 699
1252 399 $pre =~ s/\$\$\{/\$\{/g;
1253 399 ▶ length($pre) and push @line,$pre;
Branch: 1 branch
BranchTrueFalseTotal
length $pre and push @line, $pre 191 208 399
1254 399 closeLine(\@list,\@line);
1255 399 ++$self->{lno};
1256 }else{
1257 300 my $inside = substr($2,2);
1258 300 $pre =~ s/\$\$\{/\$\{/g;
1259 300 ▶ length($pre) and push @line,$pre;
Branch: 1 branch
BranchTrueFalseTotal
length $pre and push @line, $pre 179 121 300
1260 300 push @line,eval{ $self->parseTemplateTag($inside);};
1261 300 $self->{lno} += $inside =~ tr/\x0a/\x0a/;
1262 }
1263 }
1264 62 ▶ if( $lastend < length($$rText) ){
Branch: 1 branch
BranchTrueFalseTotal
if ($lastend < length $$rText) 0 62 62
1265 0 my $text =substr($$rText,$lastend);
1266 0 $text =~ s/\$\$\{/\$\{/g;
1267 0 warn "left=[$text]\n";
1268 0 push @line,$text;
1269 0 closeLine(\@list,\@line);
1270 }
1271
1272 # parse control block
1273 62 $self->{block}{$blockname} = [];
1274 62 eval{ $self->parseBlock( \@list,$self->{block}{$blockname} ); };
1275
1276 62 return !@{$self->{error}};
1277 }
1278
1279
1280 # $ok = $tml->loadFile("filename","utf8" [,$blockname]);
1281 1 ▶sub loadFile{
Subroutine loadFile: called CC=7 SCAR=23.6
Pod undocumented
1282 1 my $self = shift;
1283
1284 1 $self->{lno} = 0;
1285 1 $self->{source_name} = $_[0];
1286 1 my $enc = $_[1];
1287 1 my $blockname = $_[2];
1288
1289 # find encoding object for source
1290 1 ▶ if(defined $enc){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $enc) 1 0 1
1291 1 ▶ ref($enc) or $enc = Encode::find_encoding($enc);
Branch: 1 branch
BranchTrueFalseTotal
ref $enc or $enc = &Encode::find_encoding($enc) 0 1 1
1292 1 ▶ if(not ref($enc) =~/Encode/){
Branch: 1 branch
BranchTrueFalseTotal
unless (ref($enc) =~ /Encode/) 0 1 1
1293 0 push @{$self->{error}},"$self->{source_name} $self->{lno}: incorrect encode spec.";
1294 0 return;
1295 }
1296 }
1297
1298 # read source text
1299 1 my $source;
1300 my $fh;
1301 1 ▶ if(not open $fh,"<",$self->{source_name} ){
Branch: 1 branch
BranchTrueFalseTotal
if (not open($fh, '<', $self->{'source_name'})) { } 0 1 1
1302 0 push @{$self->{error}},"$self->{source_name} $self->{lno}: $!";
1303 0 return;
1304 }else{
1305 1 local $/=undef;
1306 1 $source = <$fh>;
1307 1 ▶ defined($enc) and $source = Encode::decode($enc,$source);
Branch: 1 branch
BranchTrueFalseTotal
defined $enc and $source = &Encode::decode($enc, $source) 1 0 1
1308 1 ▶ if(not close $fh ){
Branch: 1 branch
BranchTrueFalseTotal
unless (close $fh) 0 1 1
1309 0 push @{$self->{error}},"$self->{source_name} $self->{lno}: $!";
1310 0 return;
1311 }
1312 }
1313 1 return $self->loadText($self->{source_name},\$source,$blockname);
1314 }
1315
1316 # $teml = Text::Template::Compact->new();
1317 2 ▶sub new{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
1318 return bless{
1319 error => [],
1320 paramEncoding => Encode::find_encoding('utf8'),
1321 2 filter_default => $filter_map{'html'},
1322 undef_supply => '',
1323 } , shift;
1324 }
1325
1326 # get error as string.
1327 0 ▶sub error{
Subroutine error: not called CC=1 SCAR=6.9
Pod undocumented
1328 0 return join("\n",@{$_[0]->{error}},'');
1329 }
1330 # get error as string.
1331 1 ▶sub undef_supply{
Subroutine undef_supply: called CC=2 SCAR=7.0
Pod undocumented
1332 1 my $self = shift;
1333 1 ▶ if(@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 0 1
1334 1 $self->{undef_supply} = $_[0];
1335 }
1336 1 return $self->{undef_supply};
1337 }
1338
1339 # set encoding for decode parameter
1340 2 ▶sub param_encoding{
Subroutine param_encoding: called CC=5 SCAR=16.8
Pod undocumented
1341 2 my $self = shift;
1342 2 ▶ if(@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 0 2
1343 2 my $enc = $_[0];
1344 # find encoding object for source
1345 2 ▶ if(defined $enc){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $enc) 2 0 2
1346 2 ▶ ref($enc) or $enc = Encode::find_encoding($enc);
Branch: 1 branch
BranchTrueFalseTotal
ref $enc or $enc = &Encode::find_encoding($enc) 0 2 2
1347 2 ▶ ref($enc) =~/Encode/ or croak "incorrect encode spec.";
Branch: 1 branch
BranchTrueFalseTotal
ref($enc) =~ /Encode/ or croak("incorrect encode spec.") 2 0 2
1348 }
1349 2 $self->{paramEncoding} = $enc;
1350 }
1351 2 return;
1352 }
1353
1354 # set default of filter for variable expand.
1355 2 ▶sub filter_default{
Subroutine filter_default: called CC=4 SCAR=15.5
Pod undocumented
1356 2 my $self = shift;
1357 2 ▶ if(@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 0 2
1358 2 my $filtername = $_[0];
1359 2 ▶ if( not $filtername or not $filter_map{$filtername} ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($filtername and $Text::Template::Compact::filter_map{$filtername}) 0 2 2
Condition33%1/3
$filtername and $Text::Template::Compact::filter_map{$filtername}
!ll&&!rl&&r
002
MC/DC0%0/2
$filtername and $Text::Template::Compact::filter_map{$filtername}
$filtername $Text::Template::Compact::filter_map{$filtername}
Truth table33%1/3
A and B
A= $filternameB= $Text::Template::Compact::filter_map{$filtername}
ABresult
0X0
100
111
1360 0 croak "unknown filter '$filtername'";
1361 }
1362 2 $self->{filter_default} = $filter_map{$filtername};
1363 }
1364 2 return;
1365 }
1366
1367 # print template block(low-level method)
1368 411 ▶sub printBlock{
Subroutine printBlock: called CC=6 SCAR=17.9
Pod undocumented
1369 411 my($self,$block)=@_;
1370 411 for my $item ( @$block ){
1371 1753 ▶ if( not ref $item ){
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $item) { } 883 870 1753
elsif ($item->{'break'} or $item->{'continue'}) { } 7 863 870
1372 883 $self->{printer}->($item);
1373 ▶ }elsif( $item->{break} or $item->{continue} ){
Condition66%2/3
$item->{"break"} or $item->{"continue"}
l!l&&r!l&&!r
70863
MC/DC50%1/2
$item->{"break"} or $item->{"continue"}
$item->{"break"} $item->{"continue"}
Truth table66%2/3
A or B
A= $item->{"break"}B= $item->{"continue"}
ABresult
1X1
011
000
1374 7 return $item;
1375 }else{
1376 863 my $exit_tag = $item->{printer}($self,$item);
1377 863 ▶ $exit_tag and return $exit_tag;
Branch: 1 branch
BranchTrueFalseTotal
$exit_tag and return $exit_tag 8 855 863
1378 }
1379 }
1380 396 return;
1381 }
1382
1383 # print to filehandle
1384 1 ▶sub print{
Subroutine print: called CC=4 SCAR=14.8
Pod undocumented
1385 1 my($self,$param,$fh,$enc)=@_;
1386
1387 # generate closure to print
1388 1 ▶ if(defined $enc){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $enc) { } 1 0 1
1389 # find encoding object for source
1390 1 ▶ ref($enc) or $enc = Encode::find_encoding($enc);
Branch: 1 branch
BranchTrueFalseTotal
ref $enc or $enc = &Encode::find_encoding($enc) 0 1 1
1391 1 ▶ ref($enc) =~/Encode/ or croak "incorrect encode spec.";
Branch: 1 branch
BranchTrueFalseTotal
ref($enc) =~ /Encode/ or croak("incorrect encode spec.") 1 0 1
1392 1 ▶ $self->{printer} = sub{ for(@_){ print $fh Encode::encode($enc,$_); } };
Subroutine __ANON__: called CC=2 SCAR=6.9
1393 }else{
1394 0 ▶ $self->{printer} = sub{ print $fh @_; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1395 }
1396 1 $self->{param} = $param;
1397
1398 # start root node
1399 1 my $exit_tag = $self->printBlock( $self->{block}{""});
1400 }
1401
1402 61 ▶sub toString{
Subroutine toString: called CC=1 SCAR=0.0
Pod undocumented
1403 61 my($self,$param)=@_;
1404 61 my $result='';
1405 61 $self->{param} = $param;
1406 61 ▶ $self->{printer} = sub{ for(@_){ $result .= $_; } };
Subroutine __ANON__: called CC=2 SCAR=6.9
1407 61 $self->printBlock( $self->{block}{""} );
1408 61 return $result;
1409 }
1410
1411 3 1;
1412
1413 __END__
↑ Summary