blib/lib/Plate.pm

filter: Statementstmt 100% 325 / 325 Branchbran 99.6% 265 / 266 Conditioncond 91.7% 155 / 169 MC/DCmcdc 79.7% 75 / 94 Subroutinesub 100% 65 / 65 Podpod 100% 11 / 11 totaltotal 96.3% 896 / 930 CC 204 SCAR 30.4
CC
204
Cov
98%
_parse
65.0
_load
18.1
set
17.0
CRAP 21.0
↑ Summary
1 7 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Plate 1.7;
4  
5 7 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 7 ▶use constant WINDOWS => $^O eq 'MSWin32';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 7 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 XSLoader::load __PACKAGE__, $Plate::VERSION;
14 }
15  
16 =encoding UTF-8
17  
18 =head1 NAME
19  
20 Plate - Fast templating engine with support for embedded Perl
21  
22 =head1 SYNOPSIS
23  
24 use Plate;
25
26 my $plate = Plate->new(
27 path => '/path/to/plate/files/',
28 cache_path => '/tmp/cache/',
29 auto_filter => 'trim',
30 );
31
32 $plate->set(filters => { html => \&HTML::Escape::escape_html });
33 $plate->set(filters => { trim => sub { $_[0] =~ s/^\s+|\s+$//gr } });
34
35 # Render /path/to/plate/files/hello.plate cached as /tmp/cache/hello.pl
36 my $output = $plate->serve('hello');
37 print $output;
38  
39 =cut
40  
41 7 my $re_pre = qr'(.*?)(?:
42 ^%%\h*(\V*?)\h*(?:\R|\z)|
43 ^<%%(perl)>(?:\R|\z)(?:(.*?)^</%%\g-2>(?:\R|\z))?|
44 ^<%%(def|filter)\h+([\w/\.-]+)>(?:\R|\z)|
45 <%%(\s*(?:\#.+?)?)%%>|
46 <%%\s*(.+?)\s*(?:\|\h*(|\w+(?:\s*\|\h*\w+)*)\s*)?%%>|
47 <&&(\|)?\s*(.+?)\s*(?:\|\h*(|\w+(?:\s*\|\h*\w+)*)\s*)?&&>|
48 </(%%def|%%filter|%%perl)>(?:\R|\z)|
49 </(&&)>|\z
50 )'mosx;
51 7 my $re_run = qr'(.*?)(?:
52 ^%\h*(\V*?)\h*(?:\R|\z)|
53 ^<%(perl)>(?:\R|\z)(?:(.*?)^</%\g-2>(?:\R|\z))?|
54 ^<%(def|filter)\h+([\w/\.-]+)>(?:\R|\z)|
55 <%(\s*(?:\#.+?)?)%>|
56 <%\s*(.+?)\s*(?:\|\h*(|\w+(?:\s*\|\h*\w+)*)\s*)?%>|
57 <&(\|)?\s*(.+?)\s*(?:\|\h*(|\w+(?:\s*\|\h*\w+)*)\s*)?&>|
58 </(%def|%filter|%perl)>(?:\R|\z)|
59 </(&)>|\z
60 )'mosx;
61  
62 334 ▶sub _parse_text {
Subroutine _parse_text: called CC=3 SCAR=11.0
63 334 my $text = $_[0];
64 334 ▶ $_[2] = $text =~ s/\\\R//g unless $_[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1] 192 142 334
65 334 $text =~ s/(\\|')/\\$1/g;
66 334 ▶ length $text ? "'$text'" : ();
Branch: 1 branch
BranchTrueFalseTotal
length $text ? : 312 22 334
67 }
68 79 ▶sub _parse_cmnt {
Subroutine _parse_cmnt: called CC=4 SCAR=13.9
69 79 my $cmnt = $_[0];
70 79 ▶ $cmnt =~ /^#(?:\s*line\s+(\d+)\s*(?:\s("?)([^"]+)\g2)?\s*|.*)$/
Branch: 3 branches
BranchTrueFalseTotal
$cmnt =~ /^#(?:\s*line\s+(\d+)\s*(?:\s("?)([^"]+)\g2)?\s*|.*)$/u ? : 10 69 79
defined $1 ? : 4 6 10
defined $3 ? : 3 1 4
71 ? defined $1
72 ? defined $3
73 ? "\n#line $1 $3"
74 : "\n#line $1"
75 : ''
76 : $cmnt;
77 }
78 9 ▶sub _parse_defn {
Subroutine _parse_defn: called CC=2 SCAR=6.9
79 9 my $defn = $_[0];
80 9 ▶ $defn =~ /\W/ ? "'".($defn =~ s/(\\|')/\\$1/gr)."'" : $defn;
Branch: 1 branch
BranchTrueFalseTotal
$defn =~ /\W/u ? : 3 6 9
81 }
82 180 ▶sub _parse_fltr {
Subroutine _parse_fltr: called CC=5 SCAR=16.1
83 180 my $expr = $_[0];
84 180 ▶ $expr .= "//''" unless $$Plate::_s{keep_undef};
Branch: 1 branch
BranchTrueFalseTotal
unless $Plate::_s->{"keep_undef"} 170 10 180
85 180 ▶ if (length $_[1]) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $_[1]) { } 83 97 180
elsif (not $Plate::_s->{'keep_undef'}) { } 90 7 97
86 83 $expr = "Plate::_f($_=>$expr)" for split /\s*\|\s*/, $_[1];
87 } elsif (not $$Plate::_s{keep_undef}) {
88 90 $expr = "($expr)";
89 }
90 180 $expr;
91 }
92 274 ▶sub _parse {
Subroutine _parse: called CC=65 SCAR=41.7
93 274 my @expr;
94 my $stmt;
95 274 my $pre = $_[1] == $re_pre;
96 274 my $fix_line_num;
97 197 ▶ my $expr2stmt = sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
98 197 ▶ if (@expr) {
Branch: 1 branch
BranchTrueFalseTotal
if (@expr) { } 125 72 197
99 125 ▶ if (defined $stmt) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stmt) { } 85 40 125
100 85 ▶ $stmt .= ';push@Plate::_l,length$Plate::_b,__LINE__' if $pre;
Branch: 1 branch
BranchTrueFalseTotal
if $pre 26 59 85
101 85 $stmt .= ';$Plate::_b.=';
102 } else {
103 40 $stmt = 'local$Plate::_b=';
104 }
105 125 ▶ $stmt .= join('.', $_[0] ? splice @expr, 0, $fix_line_num : splice @expr).';';
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 45 80 125
106 } else {
107 72 ▶ $stmt //= q"local$Plate::_b='';";
Condition100%2/2
$stmt //= "local\$Plate::_b='';"
l!l
2250
MC/DC100%1/1
$stmt //= "local\$Plate::_b='';"
$stmt
Truth table100%2/2
A
A= $stmt
Aresult
11
00
108 }
109 197 ▶ undef $fix_line_num unless $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 152 45 197
110 274 };
111 274 ▶ while ($_[0] =~ /$_[1]/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /$_[1]/gu) 551 0 551
112  
113 551 ▶ if (length $1) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $1) 334 217 551
114 334 push @expr, _parse_text $1, $pre, my $add_lines;
115 334 ▶ (@expr ? $expr[-1] : defined $stmt ? $stmt : ($expr[0] = "''")) .= "\n" x $add_lines if $add_lines;
Branch: 3 branches
BranchTrueFalseTotal
if $add_lines 36 298 334
@expr ? : 31 5 36
defined $stmt ? : 1 4 5
116 334 ▶ $fix_line_num = @expr if $fix_line_num;
Branch: 1 branch
BranchTrueFalseTotal
if $fix_line_num 115 219 334
117 }
118  
119 551 ▶ if (!$pre and @Plate::_l and $Plate::_l[0] <= $+[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $pre and @Plate::_l and $Plate::_l[0] <= $+[1]) 24 527 551
Condition100%6/6
not $pre and @Plate::_l and $Plate::_l[0] <= $+[1]
!ll&&!rl&&r
520724
not $pre and @Plate::_l
!ll&&!rl&&r
18533531
MC/DC100%3/3
not $pre and @Plate::_l and $Plate::_l[0] <= $+[1]
not $pre @Plate::_l $Plate::_l[0] <= $+[1]
Truth table100%4/4
not(A) and B and C
A= not $preB= @Plate::_lC= $Plate::_l[0] <= $+[1]
ABCresult
0XX0
10X0
1100
1111
120 24 my($pos, $line) = splice @Plate::_l, 0, 2;
121 24 ▶ ($pos, $line) = splice @Plate::_l, 0, 2 while @Plate::_l and $Plate::_l[0] <= $+[1];
Branch: 1 branch
BranchTrueFalseTotal
@Plate::_l and $Plate::_l[0] <= $+[1] and do { () = splice(@Plate::_l, 0, 2) } 16 24 40
Condition100%3/3
@Plate::_l and $Plate::_l[0] <= $+[1]
!ll&&!rl&&r
141016
MC/DC100%2/2
@Plate::_l and $Plate::_l[0] <= $+[1]
@Plate::_l $Plate::_l[0] <= $+[1]
Truth table100%3/3
A and B
A= @Plate::_lB= $Plate::_l[0] <= $+[1]
ABresult
0X0
100
111
122 24 my $rem = $+[1] - $pos;
123 24 ▶ $line += substr($_[0], $pos, $rem) =~ tr/\n// if $rem;
Branch: 1 branch
BranchTrueFalseTotal
if $rem 8 16 24
124 24 $expr2stmt->();
125 24 $stmt .= "\n#line $line\n";
126 }
127  
128 551 ▶ if (defined $2) {
Branch: 6 branches
BranchTrueFalseTotal
if (defined $2) { } 79 472 551
elsif (defined $3) { } 8 464 472
elsif (defined $5) { } 9 455 464
elsif (defined $7) { } 4 451 455
elsif (defined $8) { } 111 340 451
elsif (defined $11) { } 69 271 340
129 # % ...
130 79 $expr2stmt->();
131 79 $stmt .= _parse_cmnt $2;
132 79 $stmt .= "\n";
133  
134 } elsif (defined $3) {
135 # <%perl>
136 8 $expr2stmt->();
137 8 ▶ unless (defined $4) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $4) 2 6 8
138 2 my $line = 1 + $stmt =~ y/\n//;
139 2 ▶ $line = "$_[2] line $line.\nPlate ".($pre && 'pre').'compilation failed';
Condition100%2/2
$pre && 'pre'
!ll
11
MC/DC100%1/1
$pre && 'pre'
$pre
Truth table100%2/2
A
A= $pre
Aresult
00
11
140 2 ▶ my $tag = ($pre && '%').'%'.$3;
Condition100%2/2
$pre && '%'
!ll
11
MC/DC100%1/1
$pre && '%'
$pre
Truth table100%2/2
A
A= $pre
Aresult
00
11
141 2 croak "Opening <$tag...> tag without closing </$tag> tag at $line";
142 }
143 6 $stmt .= "\n$4\n";
144  
145 } elsif (defined $5) {
146 # <%def ...> or <%filter ...>
147 9 $expr2stmt->();
148 9 ▶ local $_[3] = ($pre && '%')."%$5";
Condition100%2/2
$pre && '%'
!ll
54
MC/DC100%1/1
$pre && '%'
$pre
Truth table100%2/2
A
A= $pre
Aresult
00
11
149 9 my $n = _parse_defn $6;
150 9 ▶ $stmt .= $5 eq 'def'
Branch: 1 branch
BranchTrueFalseTotal
$5 eq 'def' ? : 7 2 9
151 ? "local\$\$Plate::_s{mem}{$n}=\nsub{".&_parse.'};'
152 : "local\$\$Plate::_s{filters}{$n}=\nsub{my\$_c=\$_[0];local\@Plate::_c=sub{\$_c};".&_parse.'};';
153  
154 } elsif (defined $7) {
155 # <%# ... %>
156 4 my $add_lines = $7 =~ tr/\n//;
157 4 ▶ (@expr ? $expr[-1] : defined $stmt ? $stmt : ($expr[0] = "''")) .= "\n" x $add_lines if $add_lines;
Branch: 3 branches
BranchTrueFalseTotal
if $add_lines 3 1 4
@expr ? : 1 2 3
defined $stmt ? : 1 1 2
158 4 ▶ $fix_line_num = @expr if $fix_line_num;
Branch: 1 branch
BranchTrueFalseTotal
if $fix_line_num 1 3 4
159  
160 } elsif (defined $8) {
161 # <% ... %>
162 111 my $nl1 = "\n" x substr($_[0], $+[1], $-[8] - $+[1]) =~ tr/\n//;
163 111 my $nl2 = "\n" x substr($_[0], $+[8], $+[0] - $+[8]) =~ tr/\n//;
164 111 ▶ $expr2stmt->(1) if $fix_line_num;
Branch: 1 branch
BranchTrueFalseTotal
if $fix_line_num 30 81 111
165 $fix_line_num = push @expr,
166 111 ▶ _parse_fltr "do{$nl1$8}$nl2", $9 // $$Plate::_s{auto_filter};
Condition100%3/3
$9 // $Plate::_s->{"auto_filter"}
l!l&&r!l&&!r
44643
MC/DC100%2/2
$9 // $Plate::_s->{"auto_filter"}
$9 $Plate::_s->{"auto_filter"}
Truth table100%3/3
A // B
A= $9B= $Plate::_s->{"auto_filter"}
ABresult
1X1
011
000
167 111 ▶ $expr2stmt->() if $pre;
Branch: 1 branch
BranchTrueFalseTotal
if $pre 11 100 111
168  
169 } elsif (defined $11) {
170 # <& ... &> or <&| ... &>
171 69 my $nl = "\n" x (substr($_[0], $+[1], $+[0] - $+[1]) =~ tr/\n// - $11 =~ tr/\n//);
172 69 my($tmpl, $args) = do { $11 =~ /^([\w\/\.-]+)\s*(?:,\s*(.*))?$/s };
173 69 ▶ $expr2stmt->(!$pre) if $pre or $fix_line_num;
Branch: 1 branch
BranchTrueFalseTotal
if $pre or $fix_line_num 28 41 69
Condition100%3/3
$pre or $fix_line_num
l!l&&r!l&&!r
131541
MC/DC100%2/2
$pre or $fix_line_num
$pre $fix_line_num
Truth table100%3/3
A or B
A= $preB= $fix_line_num
ABresult
1X1
011
000
174 69 ▶ if (defined $tmpl) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmpl) { } 58 11 69
175 58 ▶ if ($tmpl eq '_') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmpl eq "_") 26 32 58
176 $fix_line_num = push @expr, _parse_fltr defined $10
177 26 ▶ ? do {
Branch: 1 branch
BranchTrueFalseTotal
defined $10 ? : 9 17 26
178 9 ▶ $args = defined $args ? "($args)" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $args ? : 4 5 9
179 9 ▶ local $_[3] = $pre ? '&&' : '&';
Branch: 1 branch
BranchTrueFalseTotal
$pre ? : 4 5 9
180 9 ▶ '(@Plate::_c?do{local@Plate::_c=@Plate::_c;&{splice@Plate::_c,-1,1,sub{'.&_parse."}}$args}:undef)$nl"
Branch: 1 branch
BranchTrueFalseTotal
defined $args ? : 3 14 17
181 }
182 : defined $args ? "do{Plate::content($args)}$nl" : "do{&Plate::content}$nl", $12;
183 26 ▶ $expr2stmt->() if $pre and $nl;
Branch: 1 branch
BranchTrueFalseTotal
if $pre and $nl 2 24 26
Condition100%3/3
$pre and $nl
!ll&&!rl&&r
2042
MC/DC100%2/2
$pre and $nl
$pre $nl
Truth table100%3/3
A and B
A= $preB= $nl
ABresult
0X0
100
111
184 26 next;
185 }
186 32 ▶ $tmpl = defined $args ? "Plate::_r('$tmpl',($args)," : "Plate::_r('$tmpl',";
Branch: 1 branch
BranchTrueFalseTotal
defined $args ? : 15 17 32
187 } else {
188 11 $tmpl = "Plate::_r($11,";
189 }
190 43 ▶ $fix_line_num = push @expr,
Branch: 2 branches
BranchTrueFalseTotal
defined $10 ? : 19 24 43
$pre ? : 2 17 19
191 _parse_fltr "do{$tmpl".(defined $10 ? (local $_[3] = $pre ? '&&' : '&', 'sub{'.&_parse.'}') : 'undef').")}$nl", $12;
192 43 ▶ $expr2stmt->() if $pre and $nl;
Branch: 1 branch
BranchTrueFalseTotal
if $pre and $nl 1 42 43
Condition100%3/3
$pre and $nl
!ll&&!rl&&r
3661
MC/DC100%2/2
$pre and $nl
$pre $nl
Truth table100%3/3
A and B
A= $preB= $nl
ABresult
0X0
100
111
193  
194 } else {
195 # </%...> or </&> or \z
196 271 ▶ my $tag = $13 // $14 // '';
Condition100%5/5
($13 // $14) // ""
l!l
38233
$13 // $14
l!l&&r!l&&!r
1028233
MC/DC100%2/2
($13 // $14) // ""
$13 $14
Truth table100%3/3
A // B
A= $13B= $14
ABresult
1X1
011
000
197 271 ▶ if ($tag ne $_[3]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag ne $_[3]) 3 268 271
198 3 ▶ my $line = 1 + join('', $stmt // '', @expr) =~ y/\n//;
Condition100%2/2
$stmt // ""
l!l
12
MC/DC100%1/1
$stmt // ""
$stmt
Truth table100%2/2
A
A= $stmt
Aresult
11
00
199 3 ▶ $line = "$_[2] line $line.\nPlate ".($pre && 'pre').'compilation failed';
Condition100%2/2
$pre && 'pre'
!ll
12
MC/DC100%1/1
$pre && 'pre'
$pre
Truth table100%2/2
A
A= $pre
Aresult
00
11
200 3 ▶ croak $tag
Branch: 1 branch
BranchTrueFalseTotal
$tag ? : 2 1 3
201 ? "Closing </$tag> tag without opening <$tag...> tag at $line"
202 : "Opening <$_[3]...> tag without closing </$_[3]> tag at $line";
203 }
204  
205 my $pl = defined $stmt
206 268 ▶ ? do {
Branch: 1 branch
BranchTrueFalseTotal
defined $stmt ? : 86 182 268
207 86 ▶ $stmt .= ';push@Plate::_l,length$Plate::_b,__LINE__' if $pre and @expr;
Branch: 1 branch
BranchTrueFalseTotal
if $pre and @expr 17 69 86
Condition100%3/3
$pre and @expr
!ll&&!rl&&r
62717
MC/DC100%2/2
$pre and @expr
$pre @expr
Truth table100%3/3
A and B
A= $preB= @expr
ABresult
0X0
100
111
208 86 ▶ $stmt.join('.', ';$Plate::_b', @expr);
Branch: 1 branch
BranchTrueFalseTotal
@expr ? : 174 8 182
209 }
210 : @expr ? join('.', @expr) : "''";
211 268 ▶ $pl .= '=~s/\R\z//r' if !$pre and $$Plate::_s{chomp};
Branch: 1 branch
BranchTrueFalseTotal
if not $pre and $Plate::_s->{"chomp"} 140 128 268
Condition100%3/3
not $pre and $Plate::_s->{"chomp"}
!ll&&!rl&&r
1271140
MC/DC100%2/2
not $pre and $Plate::_s->{"chomp"}
not $pre $Plate::_s->{"chomp"}
Truth table100%3/3
not(A) and B
A= not $preB= $Plate::_s->{"chomp"}
ABresult
0X0
100
111
212 268 ▶ $pl .= "\n" if defined $13;
Branch: 1 branch
BranchTrueFalseTotal
if defined $13 8 260 268
213 268 return $pl;
214 }
215  
216 251 ▶ if (!$pre and @Plate::_l and $Plate::_l[0] <= $+[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $pre and @Plate::_l and $Plate::_l[0] <= $+[0]) 5 246 251
Condition100%6/6
not $pre and @Plate::_l and $Plate::_l[0] <= $+[0]
!ll&&!rl&&r
234125
not $pre and @Plate::_l
!ll&&!rl&&r
4818617
MC/DC100%3/3
not $pre and @Plate::_l and $Plate::_l[0] <= $+[0]
not $pre @Plate::_l $Plate::_l[0] <= $+[0]
Truth table100%4/4
not(A) and B and C
A= not $preB= @Plate::_lC= $Plate::_l[0] <= $+[0]
ABCresult
0XX0
10X0
1100
1111
217 5 my($pos, $line) = splice @Plate::_l, 0, 2;
218 5 ▶ ($pos, $line) = splice @Plate::_l, 0, 2 while @Plate::_l and $Plate::_l[0] <= $+[0];
Branch: 1 branch
BranchTrueFalseTotal
@Plate::_l and $Plate::_l[0] <= $+[0] and do { () = splice(@Plate::_l, 0, 2) } 4 5 9
Condition66%2/3
@Plate::_l and $Plate::_l[0] <= $+[0]
!ll&&!rl&&r
504
MC/DC50%1/2
@Plate::_l and $Plate::_l[0] <= $+[0]
@Plate::_l $Plate::_l[0] <= $+[0]
Truth table66%2/3
A and B
A= @Plate::_lB= $Plate::_l[0] <= $+[0]
ABresult
0X0
100
111
219 5 my $rem = $+[0] - $pos;
220 5 ▶ $line += substr($_[0], $pos, $rem) =~ tr/\n// if $rem;
Branch: 1 branch
BranchTrueFalseTotal
if $rem 2 3 5
221 5 $expr2stmt->();
222 5 $stmt .= "\n#line $line\n";
223 }
224 }
225 }
226  
227 19 ▶sub _read {
Subroutine _read: called CC=2 SCAR=6.9
228 19 ▶ open my $fh, '<'.$_[0]{io_layers}, $_[1]
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, '<' . $_[0]{"io_layers"}, $_[1] or croak("Can't read $_[1]: $!") 16 3 19
229 or croak "Can't read $_[1]: $!";
230 16 local $/;
231 16 scalar <$fh>;
232 }
233 8 ▶sub _write {
Subroutine _write: called CC=2 SCAR=6.9
234 8 my $umask = umask $$Plate::_s{umask};
235 8 ▶ (open(my $fh, '>:utf8', $_[0]), umask $umask)[0]
Branch: 1 branch
BranchTrueFalseTotal
(open(my $fh, ">:utf8", $_[0]), umask $umask)[0] or croak("Can't write $_[0]: $!") 7 1 8
236 or croak "Can't write $_[0]: $!";
237 7 print $fh $_[1];
238 }
239 118 ▶sub _pkg {
Subroutine _pkg: called CC=1 SCAR=0.0
240 118 join ';', @{$$Plate::_s{pragmas}}, "package $$Plate::_s{package};";
241 }
242 232 ▶sub _eval {
Subroutine _eval: called CC=1 SCAR=0.0
243 232 ▶ eval $_[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
244 }
245 121 ▶sub _compile {
Subroutine _compile: called CC=7 SCAR=19.5
246 121 my($pl, $file) = @_;
247 121 my($line, $sub);
248 121 ▶ if (length $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $file) { } 46 75 121
249 46 $line = "\n#line 1 $_[1]\n";
250 } else {
251 75 $file = '-';
252 75 $line = '';
253 }
254 121 local @Plate::_l;
255 # Precompile
256 121 $pl = _parse $pl, $re_pre, $file, '';
257 118 my $pkg = _pkg;
258 118 $pl = "${pkg}sub{$line$pl}";
259 118 ▶ $sub = _eval $pl
Branch: 1 branch
BranchTrueFalseTotal
$sub = _eval($pl) or croak($@ . 'Plate precompilation failed') 117 1 118
260 or croak $@.'Plate precompilation failed';
261 117 ▶ defined($pl = eval { $sub->() })
Branch: 1 branch
BranchTrueFalseTotal
defined($pl = eval { do { &$sub() } }) or croak($@ . 'Plate precompilation failed') 116 1 117
262 or croak $@.'Plate precompilation failed';
263 # Compile
264 116 $pl = _parse $pl, $re_run, $file, '';
265 114 $pl = "$pkg$$Plate::_s{once}sub{$$Plate::_s{init}$line$pl}";
266 114 ▶ $sub = _eval $pl
Branch: 1 branch
BranchTrueFalseTotal
$sub = _eval($pl) or croak($@ . 'Plate compilation failed') 109 5 114
267 or croak $@.'Plate compilation failed';
268 # Cache
269 109 ▶ _write $_[2], $pkg.'use utf8;'.substr($pl, length $pkg) if defined $_[2];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[2] 8 101 109
270 108 ▶ $$Plate::_s{mod}{$_[3]} = $_[4] if defined $_[4];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[4] 8 100 108
271 108 return $sub;
272 }
273 10 ▶sub _make_cache_dir {
Subroutine _make_cache_dir: called CC=6 SCAR=17.9
274 10 my($dir, @mkdir) = $_[1];
275 10 ▶ unshift @mkdir, $_[0]{cache_path}.$dir until $dir !~ s|/[^/]*$|| or -d $_[0]{cache_path}.$dir;
Branch: 1 branch
BranchTrueFalseTotal
(not $dir =~ s[/[^/]*$][]u or -d $_[0]{"cache_path"} . $dir) or do { unshift @mkdir, $_[0]{"cache_path"} . $dir } 10 2 12
Condition100%3/3
not $dir =~ s[/[^/]*$][]u or -d $_[0]{"cache_path"} . $dir
l!l&&r!l&&!r
912
MC/DC100%2/2
not $dir =~ s[/[^/]*$][]u or -d $_[0]{"cache_path"} . $dir
not $dir =~ s[/[^/]*$][]u -d $_[0]{"cache_path"} . $dir
Truth table100%3/3
not(A) or B
A= not $dir =~ s[/[^/]*$][]uB= -d $_[0]{"cache_path"} . $dir
ABresult
1X1
011
000
276 10 ▶ return unless @mkdir;
Branch: 1 branch
BranchTrueFalseTotal
unless @mkdir 8 2 10
277 2 my $umask = umask $_[0]{umask};
278 2 ▶ mkdir $_ or umask $umask, croak "Can't create cache directory $_: $!" for @mkdir;
Branch: 1 branch
BranchTrueFalseTotal
mkdir $_ or umask $umask, croak("Can't create cache directory ${_}: $!") 1 1 2
279 1 umask $umask;
280 1 return;
281 }
282 55 ▶sub _plate_file {
Subroutine _plate_file: called CC=2 SCAR=6.9
283 55 ▶ defined $_[0]{path} ? $_[0]{path}.$_[1].$_[0]{suffix} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{'path'} ? : 49 6 55
284 }
285 41 ▶sub _cache_file {
Subroutine _cache_file: called CC=2 SCAR=6.9
286 41 ▶ defined $_[0]{cache_path} ? $_[0]{cache_path}.$_[1].$_[0]{cache_suffix} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{'cache_path'} ? : 30 11 41
287 }
288 40 ▶sub _load {
Subroutine _load: called CC=18 SCAR=28.9
289 40 my $plate = $_[0]->_plate_file($_[1]);
290 40 my $cache = $_[0]->_cache_file($_[1]);
291 40 my $_n;
292 40 ▶ if (defined $cache) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $cache) { } 29 11 40
elsif (defined $plate) { } 10 1 11
293 29 ▶ if ($_[0]{static}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{'static'}) { } 7 22 29
294 7 ▶ return do $cache // croak $@ ? $@.'Plate compilation failed' : "Couldn't load $cache: $!" if -f $cache;
Branch: 2 branches
BranchTrueFalseTotal
if -f $cache 5 2 7
$@ ? : 1 1 2
Condition100%2/2
do $cache // croak($@ ? $@ . 'Plate compilation failed' : "Couldn't load ${cache}: $!")
l!l
32
MC/DC100%1/1
do $cache // croak($@ ? $@ . 'Plate compilation failed' : "Couldn't load ${cache}: $!")
do $cache
Truth table100%2/2
A
A= do $cache
Aresult
11
00
295 2 ▶ $plate // croak "Plate template '$_[1]' does not exist";
Condition100%2/2
$plate // croak("Plate template '$_[1]' does not exist")
l!l
11
MC/DC100%1/1
$plate // croak("Plate template '$_[1]' does not exist")
$plate
Truth table100%2/2
A
A= $plate
Aresult
11
00
296 } else {
297 22 ▶ $_n = $_[2] // (stat $plate)[9] // croak "Can't read $plate: $!";
Condition100%5/5
($_[2] // (stat $plate)[9]) // croak("Can't read ${plate}: $!")
l!l
184
$_[2] // (stat $plate)[9]
l!l&&r!l&&!r
2164
MC/DC100%2/2
($_[2] // (stat $plate)[9]) // croak("Can't read ${plate}: $!")
$_[2] (stat $plate)[9]
Truth table100%3/3
A // B
A= $_[2]B= (stat $plate)[9]
ABresult
1X1
011
000
298 18 ▶ if (-f $cache and ($_[0]{mod}{$_[1]} // (stat _)[9]) >= $_n) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $cache and ($_[0]{"mod"}{$_[1]} // (stat _)[9]) >= $_n) 9 9 18
Condition83%5/6
-f $cache and ($_[0]{"mod"}{$_[1]} // (stat _)[9]) >= $_n
!ll&&!rl&&r
729
$_[0]{"mod"}{$_[1]} // (stat _)[9]
l!l&&r!l&&!r
560
MC/DC33%1/3
-f $cache and ($_[0]{"mod"}{$_[1]} // (stat _)[9]) >= $_n
-f $cache $_[0]{"mod"}{$_[1]} (stat _)[9]
Truth table75%3/4
A and B // C
A= -f $cacheB= $_[0]{"mod"}{$_[1]}C= (stat _)[9]
ABCresult
0XX0
1000
11X1
1011
299 9 ▶ my $sub = do $cache // croak $@ ? $@.'Plate compilation failed' : "Couldn't load $cache: $!";
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 1 1 2
Condition100%2/2
do $cache // croak($@ ? $@ . 'Plate compilation failed' : "Couldn't load ${cache}: $!")
l!l
72
MC/DC100%1/1
do $cache // croak($@ ? $@ . 'Plate compilation failed' : "Couldn't load ${cache}: $!")
do $cache
Truth table100%2/2
A
A= do $cache
Aresult
11
00
300 7 ▶ $_[0]{mod}{$_[1]} //= $_n;
Condition66%2/3
$_[0]{"mod"}{$_[1]} //= $_n
l!l&&r!l&&!r
430
MC/DC0%0/2
$_[0]{"mod"}{$_[1]} //= $_n
$_[0]{"mod"}{$_[1]} $_n
Truth table66%2/3
A //= B
A= $_[0]{"mod"}{$_[1]}B= $_n
ABresult
1X1
011
000
301 7 return $sub;
302 }
303 }
304 10 $_[0]->_make_cache_dir($_[1]);
305 } elsif (defined $plate) {
306 10 ▶ $_n = (stat $plate)[9] unless $_[0]{static} or exists $_[0]{mod}{$_[1]};
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]{"static"} or exists $_[0]{"mod"}{$_[1]} 3 7 10
Condition66%2/3
$_[0]{"static"} or exists $_[0]{"mod"}{$_[1]}
l!l&&r!l&&!r
703
MC/DC50%1/2
$_[0]{"static"} or exists $_[0]{"mod"}{$_[1]}
$_[0]{"static"} exists $_[0]{"mod"}{$_[1]}
Truth table66%2/3
A or B
A= $_[0]{"static"}B= exists $_[0]{"mod"}{$_[1]}
ABresult
1X1
011
000
307 } else {
308 1 croak "Plate template '$_[1]' does not exist";
309 }
310 19 _compile $_[0]->_read($plate), $plate, $cache, $_[1], $_n;
311 }
312 170 ▶sub _cached_sub {
Subroutine _cached_sub: called CC=7 SCAR=19.5
313 170 ▶ return $_[0]{mem}{$_[1]} //= $_[0]->_load($_[1]) if $_[0]{static} or not exists $_[0]{mod}{$_[1]};
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"static"} or not exists $_[0]{"mod"}{$_[1]} 164 6 170
Condition100%6/6
$_[0]{"static"} or not exists $_[0]{"mod"}{$_[1]}
l!l&&r!l&&!r
61586
$_[0]{"mem"}{$_[1]} //= $_[0]->_load($_[1])
l!l&&r!l&&!r
152111
MC/DC100%2/2
$_[0]{"static"} or not exists $_[0]{"mod"}{$_[1]}
$_[0]{"static"} not exists $_[0]{"mod"}{$_[1]}
MC/DC100%2/2
$_[0]{"mem"}{$_[1]} //= $_[0]->_load($_[1])
$_[0]{"mem"}{$_[1]} $_[0]->_load($_[1])
Truth table100%3/3
A or not(B)
A= $_[0]{"static"}B= not exists $_[0]{"mod"}{$_[1]}
ABresult
1X1
011
000
Truth table100%3/3
A //= B
A= $_[0]{"mem"}{$_[1]}B= $_[0]->_load($_[1])
ABresult
1X1
011
000
314 6 ▶ my $mod = (stat $_[0]->_plate_file($_[1]))[9]
Branch: 1 branch
BranchTrueFalseTotal
my $mod = (stat $_[0]->_plate_file($_[1]))[9] or croak("Plate template '$_[1]' does not exist") 4 2 6
315 or croak "Plate template '$_[1]' does not exist";
316 4 ▶ return $_[0]{mem}{$_[1]} //= $_[0]->_load($_[1], $mod) if $_[0]{mod}{$_[1]} == $mod;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"mod"}{$_[1]} == $mod 3 1 4
Condition66%2/3
$_[0]{"mem"}{$_[1]} //= $_[0]->_load($_[1], $mod)
l!l&&r!l&&!r
210
MC/DC0%0/2
$_[0]{"mem"}{$_[1]} //= $_[0]->_load($_[1], $mod)
$_[0]{"mem"}{$_[1]} $_[0]->_load($_[1], $mod)
Truth table66%2/3
A //= B
A= $_[0]{"mem"}{$_[1]}B= $_[0]->_load($_[1], $mod)
ABresult
1X1
011
000
317 1 $_[0]{mem}{$_[1]} = $_[0]->_load($_[1], $mod);
318 }
319 202 ▶sub _sub {
Subroutine _sub: called CC=3 SCAR=11.1
320 $$Plate::_s{cache_code}
321 ? $Plate::_s->_cached_sub($_[0])
322 202 ▶ : $$Plate::_s{mem}{$_[0]} // $Plate::_s->_load($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
$Plate::_s->{'cache_code'} ? : 170 32 202
Condition66%2/3
$Plate::_s->{"mem"}{$_[0]} // $Plate::_s->_load($_[0])
l!l&&r!l&&!r
6260
MC/DC0%0/2
$Plate::_s->{"mem"}{$_[0]} // $Plate::_s->_load($_[0])
$Plate::_s->{"mem"}{$_[0]} $Plate::_s->_load($_[0])
Truth table66%2/3
A // B
A= $Plate::_s->{"mem"}{$_[0]}B= $Plate::_s->_load($_[0])
ABresult
1X1
011
000
323 }
324  
325 3 ▶sub _empty {}
Subroutine _empty: called CC=1 SCAR=0.0
326 161 ▶sub _r {
Subroutine _r: called CC=6 SCAR=17.9
327 161 my $tmpl = shift;
328 161 ▶ if ($tmpl eq '_') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmpl eq "_") 6 155 161
329 6 ▶ return undef unless @Plate::_c;
Branch: 1 branch
BranchTrueFalseTotal
unless @Plate::_c 3 3 6
330 3 ▶ if (defined(my $c = pop)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $c = pop())) { } 2 1 3
331 2 local @Plate::_c = @Plate::_c;
332 2 return &{splice @Plate::_c, -1, 1, $c};
333 } else {
334 1 $tmpl = pop @Plate::_c;
335 1 local @Plate::_c = @Plate::_c;
336 1 return &{$tmpl};
337 }
338 }
339 155 ▶ if (@Plate::_c >= $$Plate::_s{max_call_depth}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@Plate::_c >= $Plate::_s->{"max_call_depth"}) 2 153 155
340 2 my($f, $l) = (caller 0)[1, 2];
341 2 die "Call depth limit exceeded while calling \"$tmpl\" at $f line $l.\n";
342 }
343 153 local @Plate::_c = @Plate::_c;
344 153 ▶ push @Plate::_c, pop // \&_empty;
Condition100%2/2
pop() // \&Plate::_empty
l!l
21132
MC/DC100%1/1
pop() // \&Plate::_empty
pop()
Truth table100%2/2
A
A= pop()
Aresult
11
00
345 153 &{_sub $tmpl};
346 }
347 128 ▶sub _f {
Subroutine _f: called CC=2 SCAR=6.9
348 128 my $f = shift;
349 128 ▶ goto &{$$Plate::_s{filters}{$f} // croak "No '$f' filter defined"};
Condition100%2/2
$Plate::_s->{"filters"}{$f} // croak("No '${f}' filter defined")
l!l
1253
MC/DC100%1/1
$Plate::_s->{"filters"}{$f} // croak("No '${f}' filter defined")
$Plate::_s->{"filters"}{$f}
Truth table100%2/2
A
A= $Plate::_s->{"filters"}{$f}
Aresult
11
00
350 }
351  
352 23 ▶sub _path {
Subroutine _path: called CC=8 SCAR=20.8
353 23 my $path = $_[0];
354 23 my $vol = WINDOWS ? $path =~ s'^[\\/]{2}(?=[^\\/])'' ? '//' : $path =~ s'^([a-zA-Z]:)'' ? ucfirst $1 : '' : '';
355 23 ▶ length $path or return (length $vol or not $_[1]) ? $vol : './';
Branch: 2 branches
BranchTrueFalseTotal
length $path or return length $vol || !$_[1] ? $vol : "./" 21 2 23
length $vol || !$_[1] ? : 1 1 2
Condition66%2/3
length $vol or not $_[1]
l!l&&r!l&&!r
011
MC/DC50%1/2
length $vol or not $_[1]
length $vol not $_[1]
Truth table66%2/3
A or not(B)
A= length $volB= not $_[1]
ABresult
1X1
011
000
356 21 my @dir = grep $_ ne '.', split WINDOWS ? qr'[\\/]+' : qr'/+', $path.'/', -1;
357 21 ▶ $vol = './' if $_[1] and not length $vol and (length $dir[0] or @dir == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] and not length $vol and length $dir[0] || @dir == 1 8 13 21
Condition88%8/9
$_[1] and not length $vol and length $dir[0] || @dir == 1
!ll&&!rl&&r
1128
$_[1] and not length $vol
!ll&&!rl&&r
11010
length $dir[0] or @dir == 1
l!l&&r!l&&!r
712
MC/DC75%3/4
$_[1] and not length $vol and length $dir[0] || @dir == 1
$_[1] not length $vol length $dir[0] @dir == 1
Truth table80%4/5
A and not(B) and C or D
A= $_[1]B= not length $volC= length $dir[0]D= @dir == 1
ABCDresult
0XXX0
10XX0
11000
111X1
11011
358 21 $vol.join('/', @dir);
359 }
360  
361 {
362 7 my %esc_html = ('"' => '&quot;', '&' => '&amp;', "'" => '&#39;', '<' => '&lt;', '>' => '&gt;');
363 7 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
364 119 ▶ sub _basic_html_filter { $_[0] =~ s/(["&'<>])/$esc_html{$1}/egr }
Subroutine _basic_html_filter: called CC=1 SCAR=0.0
365 }
366  
367 =head1 DESCRIPTION
368  
369 Plate is a very fast, efficient and full-featured templating engine.
370  
371 Inspired by L<HTML::Mason> and L<Tenjin>, the goal of this templating engine is speed and functionality.
372 It has no non-core dependencies, is a compact size and supports embedded Perl.
373  
374 Features include preprocessing templates,
375 caching compiled templates,
376 variable escaping/filtering,
377 localised global variables.
378 Templates can also include other templates, with optional content
379 and even define or override templates & filters locally.
380  
381 All templates have strict, warnings and Perl 5.20 features enabled by default.
382  
383 =head2 Example
384  
385 Here is an example template for a letter stored in the file: C<letter.plate>
386  
387 % my($title, $surname) = @_;
388 Dear <% $title %> <% $surname %>,
389
390 <& _ &>
391
392 Kind Regards,
393
394 E. X. Ample
395  
396 Another template could I<include> this template, Eg: C<job.plate>
397  
398 <&| letter, 'Dr.', 'No' &>\
399 In response to the recently advertised position, please
400 consider my résumé in your search for a professional sidekick.
401 </&>
402  
403 Serving the C<job.plate> template will result in the following output:
404  
405 Dear Dr. No,
406
407 In response to the recent advertised position, please
408 consider my résumé in your search for a professional sidekick.
409
410 Kind Regards,
411
412 E. X. Ample
413  
414 Here is the code to render this output:
415  
416 use Plate;
417
418 my $plate = Plate->new;
419 my $output = $plate->serve('job');
420  
421 =head2 Markup
422  
423 =head3 Variables
424  
425 <% $var %>
426 <% $unescaped |%>
427 <% $filtered |trim |html %>
428  
429 Variables are interpolated into the output and optionally filtered (escaped).
430 Filters are listed in the order to be applied preceded by a C<|> character.
431 If no filter is given as in the first example, then the default filter is applied.
432 To explicitly avoid the default filter use the empty string as a filter.
433  
434 =head3 Statements
435  
436 % my $user = db_lookup(user => 'bob');
437 % for my $var (@list) {
438  
439 Lines that start with a C<%> character are treated as Perl statements.
440  
441 =head3 Comments
442  
443 %# Comment line
444 <% # inline comment %>
445 <%#
446 Multi-line
447 comment
448 %>
449  
450 =head3 Perl blocks
451  
452 <%perl>
453 ...
454 </%perl>
455  
456 Perl code can also be wrapped in a perl block.
457  
458 =head3 Newlines
459  
460 Newline characters can be escaped with a backslash, Eg:
461  
462 % for my $var ('a' .. 'c') {
463 <% $var %>\
464 % }
465  
466 This will result in the output C<abc>, all on one line.
467  
468 =head3 Include other templates
469  
470 <& header, 'My Title' &>
471 ...
472 <& footer &>
473  
474 A template can include other templates with optional arguments.
475  
476 =head3 Include other templates with provided content
477  
478 <&| paragraph &>
479 This content is passed to the "paragraph" template.
480 </&>
481
482 Plain text, <&| bold &>bold text</&>, plain text.
483  
484 An included template can have its own content passed in.
485  
486 =head3 Content
487  
488 <& _ &>
489  
490 A template can be served with content. This markup will insert the content provided, if any.
491  
492 =head3 Def blocks
493  
494 <%def copyright>
495 Copyright © <% $_[0] %>
496 </%def>
497
498 <& copyright, 2018 &>
499  
500 Local templates can be defined in a template.
501 They will override existing templates until the end of the template or block.
502  
503 =head3 Filter blocks
504  
505 <%filter one_line>
506 <% $_[0] =~ tr/\n/ / |%>
507 </%filter>
508
509 <%filter bold>
510 <b><& _ &></b>
511 </%filter>
512
513 <% "Single\nLine\nOnly" |one_line |bold %>
514  
515 Local filters can also be defined in a template.
516 They will override existing filters until the end of the template or block.
517 The text to be filtered will be passed in as the only argument and also as content.
518  
519 =head1 SUBROUTINES/METHODS
520  
521 =head2 new
522  
523 my $plate = Plate->new(%options);
524  
525 Creates a new C<Plate> engine with the options provided.
526  
527 Options (with their defaults) are:
528  
529 =over
530  
531 =item C<< auto_filter => 'html' >>
532  
533 The name of the default filter to use for template variables when no filter is specified, S<C<< <% ... %> >>>.
534 The built-in default filter is a very basic HTML filter.
535 Set this to C<undef> to disable the default filter.
536  
537 To prevent the default filter being used for just a single variable,
538 just set the filter to an empty string. Eg: S<C<< <% $unfiltered |%> >>>
539  
540 =item C<< cache_code => 1 >>
541  
542 If set to a true value, the engine will cache compiled template code in memory.
543 This vastly improves performance at the expense of some memory.
544  
545 =item C<< cache_path => undef >>
546  
547 Set this to a directory to store compiled templates on the filesystem.
548 If the directory does not exist, it will attempt to create it using the C<umask> setting.
549  
550 =item C<< cache_suffix => '.pl' >>
551  
552 Compiled templates stored on the filesystem will have this suffix appended.
553  
554 =item C<< chomp => 1 >>
555  
556 If set to a true value (the default),
557 the final newline in every template will be removed.
558  
559 =item C<< encoding => 'UTF-8' >>
560  
561 Set this to the encoding of your template files.
562  
563 =item C<< filters => { html => \&_basic_html_filter } >>
564  
565 A hash of filters to set for use in templates.
566 The key is the name of the filter, and the value is the CODE ref, subroutine name or C<undef>.
567 The subroutine will be given one argument (the content to filter) as a string,
568 and must return the filtered string.
569 To remove a filter pass C<undef> as it's value.
570  
571 To remove all filters pass C<undef> instead of a HASH ref.
572  
573 =item C<< keep_undef => undef >>
574  
575 If set to a false value (the default),
576 then variables and calls that return C<undef> are converted to an empty string.
577  
578 =item C<< max_call_depth => 99 >>
579  
580 This sets the maximum call depth to prevent infinite recursion.
581  
582 =item C<< package => 'Plate::Template' >>
583  
584 The package name that templates are compiled and run in.
585  
586 =item C<< path => '' >>
587  
588 The path to the templates on the filesystem.
589 An empty string (the default) refers to the current directory.
590 If set to C<undef> then the filesystem will not be searched,
591 only cached templates will be served.
592  
593 =item C<< pragmas => [] >>
594  
595 A list of pragmas to use when compiling templates.
596  
597 All templates have strict, warnings and Perl 5.20 features enabled by default,
598 but these defaults can be changed. Eg:
599  
600 my $plate = Plate->new(pragmas => ['use 5.040', 'no strict', 'no warnings']);
601  
602 This will enable all features from Perl 5.40 and disable strict and warnings.
603  
604 =item C<< static => undef >>
605  
606 If set to a false value (the default),
607 the engine will reload and recompile templates whenever files are modified.
608  
609 If set to a true value,
610 file modification will not be checked nor will templates be reloaded.
611 While this improves performance in production, it is not recommended in development.
612  
613 =item C<< suffix => '.plate' >>
614  
615 The suffix appended to template names when searching on the filesystem.
616  
617 =item C<< umask => 077 >>
618  
619 The C<umask> used when creating cache files and directories.
620  
621 =item C<< vars => {} >>
622  
623 A hash of vars to set for use in templates.
624 This will define new local variables to be imported into the templating package when compiling and running templates.
625 Values to be imported must be unblessed references.
626 If the value is a blessed object or not a reference it will be imported as a constant into the templating package.
627 To remove a var pass C<undef> as it's value.
628  
629 To remove all vars pass C<undef> instead of a HASH ref.
630  
631 All templates will have access to these variables, subroutines and constants even under C<use strict>.
632  
633 =back
634  
635 =cut
636  
637 7 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
638 22 my $class = shift;
639 22 my $self = bless {
640 auto_filter => 'html',
641 cache_code => 1,
642 cache_path => undef,
643 cache_suffix => '.pl',
644 chomp => 1,
645 filters => {
646 html => \&_basic_html_filter,
647 },
648 init => '',
649 io_layers => ':encoding(UTF-8)',
650 keep_undef => undef,
651 max_call_depth => 99,
652 mem => {},
653 once => '',
654 package => 'Plate::Template',
655 path => '',
656 pragmas => [],
657 static => undef,
658 suffix => '.plate',
659 umask => 077,
660 vars => {},
661 }, $class;
662 22 ▶ $self->set(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 19 3 22
663 13 $self;
664 }
665  
666 =head2 serve
667  
668 my $output = $plate->serve($template_name, @arguments);
669  
670 Renders a template.
671 The C<@arguments> will be passed to the template as C<@_>.
672  
673 =head2 serve_with
674  
675 my $output = $plate->serve_with($content, $template_name, @arguments);
676  
677 Renders a template with the provided content.
678  
679 The content can be passed in one of three ways.
680 If C<$content> is a string then it is the name of a template to serve.
681 If C<$content> is a SCALAR ref then it is the contents of a template to be compiled and served.
682 C<$content> may also be a CODE ref which should return the content directly.
683  
684 =cut
685  
686 104 ▶sub serve { shift->serve_with(undef, @_) }
Subroutine serve: called CC=1 SCAR=0.0
Pod documented
687 110 ▶sub serve_with {
Subroutine serve_with: called CC=6 SCAR=17.9
Pod documented
688 110 local $Plate::_s = shift;
689 110 ▶ my($_c, $tmpl) = (shift // \&_empty, shift // croak 'Template name is undefined');
Condition100%4/4
shift() // \&Plate::_empty
l!l
6104
shift() // croak("Template name is undefined")
l!l
1091
MC/DC100%1/1
shift() // \&Plate::_empty
shift()
MC/DC100%1/1
shift() // croak("Template name is undefined")
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
Truth table100%2/2
A
A= shift()
Aresult
11
00
690 109 _local_vars $$Plate::_s{package}, $$Plate::_s{vars};
691 109 ▶ local @Plate::_c = ref $_c eq 'CODE' ? $_c : ref $_c eq 'SCALAR' ? _compile $$_c : _sub $_c;
Branch: 2 branches
BranchTrueFalseTotal
ref $_c eq 'CODE' ? : 103 6 109
ref $_c eq 'SCALAR' ? : 5 1 6
692  
693 109 ▶ my $sub = ref $tmpl eq 'SCALAR'
Branch: 1 branch
BranchTrueFalseTotal
ref $tmpl eq 'SCALAR' ? : 69 40 109
694 ? _compile $$tmpl
695 : _sub $tmpl;
696 92 &$sub;
697 }
698  
699 =head2 content
700  
701 % my $content = &Plate::content;
702  
703 Used from within a template to return the content passed to that template.
704  
705 =head2 has_content
706  
707 % if (Plate::has_content) { ...
708  
709 Used from within a template to determine if that template was called with content.
710  
711 =cut
712  
713 52 ▶sub content {
Subroutine content: called CC=2 SCAR=6.9
Pod documented
714 52 ▶ @Plate::_c ? do { local @Plate::_c = @Plate::_c; &{pop @Plate::_c} } : undef;
Branch: 1 branch
BranchTrueFalseTotal
@Plate::_c ? : 51 1 52
715 }
716 4 ▶sub has_content {
Subroutine has_content: called CC=2 SCAR=6.9
Pod documented
717 4 ▶ @Plate::_c and $Plate::_c[-1] != \&_empty;
Branch: 1 branch
BranchTrueFalseTotal
@Plate::_c and $Plate::_c[-1] != \&Plate::_empty 3 1 4
718 }
719  
720 =head2 define
721  
722 $plate->define($template_name => $content);
723  
724 This will cache a template in memory.
725 The C<$content> is the contents of a template (as a string) to be compiled or a CODE ref.
726  
727 This is useful if you need to use templates that are not stored on the file system,
728 for example from a database or a custom subroutine.
729  
730 =head2 undefine
731  
732 $plate->undefine;
733 $plate->undefine($template_name);
734  
735 This will delete a previously cached template,
736 or all templates if the name is C<undef>.
737  
738 =cut
739  
740 31 ▶sub define {
Subroutine define: called CC=3 SCAR=11.0
Pod documented
741 31 ▶ delete $_[0]{mod}{$_[1]} if $_[0]{mod};
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"mod"} 19 12 31
742 31 ▶ $_[0]{mem}{$_[1]} = ref $_[2] eq 'CODE' ? $_[2] : do {
Branch: 1 branch
BranchTrueFalseTotal
ref $_[2] eq 'CODE' ? : 1 30 31
743 30 local($Plate::_s, @Plate::_c) = $_[0];
744 30 _local_vars $$Plate::_s{package}, $$Plate::_s{vars};
745 30 _compile $_[2], $_[1];
746 };
747 }
748 3 ▶sub undefine {
Subroutine undefine: called CC=2 SCAR=6.9
Pod documented
749 3 ▶ if (defined $_[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) { } 2 1 3
750 2 delete $_[0]{mod}{$_[1]};
751 2 delete $_[0]{mem}{$_[1]};
752 } else {
753 1 delete $_[0]{mod};
754 1 undef %{$_[0]{mem}};
755 }
756 }
757  
758 =head2 does_exist
759  
760 my $exists = $plate->does_exist($template_name);
761
762 % my $exists = Plate::does_exist($template_name);
763  
764 Returns true if a template by that name is cached or exists on the filesystem.
765 No attempt will be made to compile the template.
766 The second invocation only works from within a template.
767  
768 =head2 can_serve
769  
770 my $ok = $plate->can_serve($template);
771
772 % my $ok = Plate::can_serve($template);
773  
774 Returns true if the template can be served (compiles successfully),
775 otherwise it sets C<$@> to the reason for failure.
776 If C<$template> is a string then it is the name of a template to compile.
777 If C<$template> is a SCALAR ref then it is the contents of a template to be compiled.
778 The second invocation only works from within a template.
779  
780 =cut
781  
782 11 ▶sub does_exist {
Subroutine does_exist: called CC=8 SCAR=20.8
Pod documented
783 11 ▶ my($self, $name) = Scalar::Util::blessed $_[0] ? @_
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) ? : 9 2 11
Condition100%2/2
$Plate::_s // croak("Can only be called as a subroutine from within a template")
l!l
11
MC/DC100%1/1
$Plate::_s // croak("Can only be called as a subroutine from within a template")
$Plate::_s
Truth table100%2/2
A
A= $Plate::_s
Aresult
11
00
784 : ($Plate::_s // croak('Can only be called as a subroutine from within a template'), @_);
785 10 ▶ $$self{cache_code} and not $$self{static} and exists $$self{mod}{$name}
Branch: 1 branch
BranchTrueFalseTotal
$self->{"cache_code"} and not $self->{"static"} and exists $self->{"mod"}{$name} and return -f $self->_plate_file($name) 2 8 10
Condition100%6/6
$self->{"cache_code"} and not $self->{"static"} and exists $self->{"mod"}{$name}
!ll&&!rl&&r
622
$self->{"cache_code"} and not $self->{"static"}
!ll&&!rl&&r
514
MC/DC100%3/3
$self->{"cache_code"} and not $self->{"static"} and exists $self->{"mod"}{$name}
$self->{"cache_code"} not $self->{"static"} exists $self->{"mod"}{$name}
Truth table100%4/4
A and not(B) and C
A= $self->{"cache_code"}B= not $self->{"static"}C= exists $self->{"mod"}{$name}
ABCresult
0XX0
10X0
1100
1111
786 and return -f $self->_plate_file($name);
787  
788 8 ▶ exists $$self{mem}{$name} or -f($self->_plate_file($name) // $self->_cache_file($name));
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"mem"}{$name} or -f ($self->_plate_file($name) // $self->_cache_file($name)) 1 7 8
Condition66%2/3
$self->_plate_file($name) // $self->_cache_file($name)
l!l&&r!l&&!r
610
MC/DC0%0/2
$self->_plate_file($name) // $self->_cache_file($name)
$self->_plate_file($name) $self->_cache_file($name)
Truth table66%2/3
A // B
A= $self->_plate_file($name)B= $self->_cache_file($name)
ABresult
1X1
011
000
789 }
790 10 ▶sub can_serve {
Subroutine can_serve: called CC=4 SCAR=13.9
Pod documented
791 10 ▶ my($self, $name) = Scalar::Util::blessed $_[0] ? @_
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) ? : 8 2 10
Condition100%2/2
$Plate::_s // croak("Can only be called as a subroutine from within a template")
l!l
11
MC/DC100%1/1
$Plate::_s // croak("Can only be called as a subroutine from within a template")
$Plate::_s
Truth table100%2/2
A
A= $Plate::_s
Aresult
11
00
792 : ($Plate::_s // croak('Can only be called as a subroutine from within a template'), @_);
793 9 local($Plate::_s, @Plate::_c) = $self;
794 9 _local_vars $$Plate::_s{package}, $$Plate::_s{vars};
795 9 ▶ !!eval { ref $name eq 'SCALAR' ? _compile $$name : _sub $name };
Branch: 1 branch
BranchTrueFalseTotal
ref $name eq 'SCALAR' ? : 1 8 9
796 }
797  
798 =head2 filter
799  
800 $text = $plate->filter($text, 'html', 'bold');
801
802 % $text = Plate::filter($text, 'trim');
803  
804 Filters the text using the named filters and returns the result.
805 The second invocation only works from within a template.
806  
807 =cut
808  
809 3 ▶sub filter {
Subroutine filter: called CC=5 SCAR=16.1
Pod documented
810 3 ▶ my($self, $text, @f) = Scalar::Util::blessed $_[0] ? @_
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) ? : 1 2 3
Condition100%2/2
$Plate::_s // croak("Can only be called as a subroutine from within a template")
l!l
11
MC/DC100%1/1
$Plate::_s // croak("Can only be called as a subroutine from within a template")
$Plate::_s
Truth table100%2/2
A
A= $Plate::_s
Aresult
11
00
811 : ($Plate::_s // croak('Can only be called as a subroutine from within a template'), @_);
812 2 ▶ $text = &{$$self{filters}{$_} // croak "No '$_' filter defined"}($text) for @f;
Condition50%1/2
$self->{"filters"}{$_} // croak("No '${_}' filter defined")
l!l
40
MC/DC0%0/1
$self->{"filters"}{$_} // croak("No '${_}' filter defined")
$self->{"filters"}{$_}
Truth table50%1/2
A
A= $self->{"filters"}{$_}
Aresult
11
00
813 2 return $text;
814 }
815  
816 =head2 set
817  
818 $plate->set(%options);
819  
820 Set the options for this C<Plate> engine.
821 Options are the same as those for L</new>.
822  
823 =cut
824  
825 7 my %sigil = (
826 ARRAY => '@',
827 CODE => '&',
828 GLOB => '*',
829 HASH => '%',
830 );
831  
832 2 ▶eval "sub _set_$_ { \$_[0]{$_} = \$_[1] }" for qw(auto_filter cache_code chomp keep_undef max_call_depth static umask);
Subroutine _set_auto_filter: called CC=1 SCAR=0.0
Subroutine _set_cache_code: called CC=1 SCAR=0.0
Subroutine _set_chomp: called CC=1 SCAR=0.0
Subroutine _set_keep_undef: called CC=1 SCAR=0.0
Subroutine _set_max_call_depth: called CC=1 SCAR=0.0
Subroutine _set_static: called CC=1 SCAR=0.0
Subroutine _set_umask: called CC=1 SCAR=0.0
833 1 ▶eval "sub _set_$_ { \$_[0]{$_} = \$_[1] // '' }" for qw(cache_suffix init io_layers once suffix);
Subroutine _set_cache_suffix: called CC=2 SCAR=7.1
Subroutine _set_init: called CC=2 SCAR=7.1
Subroutine _set_io_layers: called CC=2 SCAR=7.1
Subroutine _set_once: called CC=2 SCAR=7.1
Subroutine _set_suffix: called CC=2 SCAR=7.1
Condition70%7/10
$_[1] // ""
l!l
10
$_[1] // ""
l!l
11
$_[1] // ""
l!l
50
$_[1] // ""
l!l
11
$_[1] // ""
l!l
10
MC/DC0%0/1
$_[1] // ""
$_[1]
MC/DC100%1/1
$_[1] // ""
$_[1]
MC/DC0%0/1
$_[1] // ""
$_[1]
MC/DC100%1/1
$_[1] // ""
$_[1]
MC/DC0%0/1
$_[1] // ""
$_[1]
Truth table50%1/2
A
A= $_[1]
Aresult
11
00
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
Truth table50%1/2
A
A= $_[1]
Aresult
11
00
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
Truth table50%1/2
A
A= $_[1]
Aresult
11
00
834 12 ▶sub _set_cache_path {
Subroutine _set_cache_path: called CC=2 SCAR=6.9
835 # A relative cache_path must start with "./" to prevent searching @INC when sourcing the file
836 12 ▶ $_[0]{cache_path} = defined $_[1] ? _path $_[1], 1 : $_[1];
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 11 1 12
837 }
838 4 ▶sub _set_encoding {
Subroutine _set_encoding: called CC=3 SCAR=11.0
839 4 ▶ $_[0]->_set_io_layers(length $_[1] ? $_[1] eq 'utf8' ? ':utf8' : ":encoding($_[1])" : '');
Branch: 2 branches
BranchTrueFalseTotal
length $_[1] ? : 3 1 4
$_[1] eq 'utf8' ? : 1 2 3
840 }
841 9 ▶sub _set_filters {
Subroutine _set_filters: called CC=10 SCAR=23.0
842 9 ▶ $_[1] // return undef %{$_[0]{filters}};
Condition100%2/2
$_[1] // (return undef %{$_[0]{"filters"};})
l!l
81
MC/DC100%1/1
$_[1] // (return undef %{$_[0]{"filters"};})
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
843 8 ▶ ref $_[1] eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] eq "HASH" or croak("Invalid filters (not a hash reference)") 7 1 8
844 or croak "Invalid filters (not a hash reference)";
845  
846 7 ▶ while (my($name, $code) = each %{$_[1]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$_[1];}) 8 5 13
847 8 ▶ $name =~ /^\w+$/
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^\w+$/u or croak("Invalid filter name '${name}'") 7 1 8
848 or croak "Invalid filter name '$name'";
849 7 ▶ if (defined $code) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $code) { } 5 2 7
850 ref $code eq 'CODE'
851 or $code = ($code =~ /(.*)::(.*)/
852 ? $1->can($2)
853 5 ▶ : do {
Branch: 2 branches
BranchTrueFalseTotal
ref $code eq "CODE" or $code = $code =~ /(.*)::(.*)/u ? $1->can($2) : do { () = 0; ++$i while __PACKAGE__ eq ($p = caller $i); $p->can($code) } or croak("Invalid subroutine '$_[1]{$name}' for filter '${name}'") 4 1 5
$code =~ /(.*)::(.*)/u ? : 1 1 2
Condition100%3/3
ref $code eq "CODE" or $code = $code =~ /(.*)::(.*)/u ? $1->can($2) : do { () = 0; ++$i while __PACKAGE__ eq ($p = caller $i); $p->can($code) }
l!l&&r!l&&!r
311
MC/DC100%2/2
ref $code eq "CODE" or $code = $code =~ /(.*)::(.*)/u ? $1->can($2) : do { () = 0; ++$i while __PACKAGE__ eq ($p = caller $i); $p->can($code) }
ref $code eq "CODE" $code = $code =~ /(.*)::(.*)/u ? $1->can($2) : do { () = 0; ++$i while __PACKAGE__ eq ($p = caller $i); $p->can($code) }
Truth table100%3/3
A or B
A= ref $code eq "CODE"B= $code = $code =~ /(.*)::(.*)/u ? $1->can($2) : do { () = 0; ++$i while __PACKAGE__ eq ($p = caller $i); $p->can($code) }
ABresult
1X1
011
000
854 1 my($i,$p) = 0;
855 1 ▶ $i++ while __PACKAGE__ eq ($p = caller $i);
Branch: 1 branch
BranchTrueFalseTotal
__PACKAGE__ eq ($p = caller $i) and do { ++$i } 1 1 2
856 1 $p->can($code)
857 })
858 or croak "Invalid subroutine '$_[1]{$name}' for filter '$name'";
859 4 $_[0]{filters}{$name} = $code;
860 } else {
861 2 delete $_[0]{filters}{$name};
862 }
863 }
864 }
865 16 ▶sub _set_path {
Subroutine _set_path: called CC=2 SCAR=6.9
866 16 ▶ $_[0]{path} = length $_[1] ? _path $_[1] : $_[1];
Branch: 1 branch
BranchTrueFalseTotal
length $_[1] ? : 11 5 16
867 }
868 3 ▶sub _set_package {
Subroutine _set_package: called CC=4 SCAR=13.9
869 3 ▶ defined $_[1] and $_[1] =~ /^[A-Z_a-z][0-9A-Z_a-z]*(?:::[0-9A-Z_a-z]+)*$/
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] and $_[1] =~ /^[A-Z_a-z][0-9A-Z_a-z]*(?:::[0-9A-Z_a-z]+)*$/u or croak(q[Invalid package name '] . ($_[1] // "") . q[']) 1 2 3
Condition100%5/5
defined $_[1] and $_[1] =~ /^[A-Z_a-z][0-9A-Z_a-z]*(?:::[0-9A-Z_a-z]+)*$/u
!ll&&!rl&&r
111
$_[1] // ""
l!l
11
MC/DC100%2/2
defined $_[1] and $_[1] =~ /^[A-Z_a-z][0-9A-Z_a-z]*(?:::[0-9A-Z_a-z]+)*$/u
defined $_[1] $_[1] =~ /^[A-Z_a-z][0-9A-Z_a-z]*(?:::[0-9A-Z_a-z]+)*$/u
MC/DC100%1/1
$_[1] // ""
$_[1]
Truth table100%3/3
A and B
A= defined $_[1]B= $_[1] =~ /^[A-Z_a-z][0-9A-Z_a-z]*(?:::[0-9A-Z_a-z]+)*$/u
ABresult
0X0
100
111
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
870 or croak "Invalid package name '".($_[1] // '')."'";
871 1 $_[0]{package} = $_[1];
872 }
873 3 ▶sub _set_pragmas {
Subroutine _set_pragmas: called CC=2 SCAR=6.9
874 3 ▶ ref $_[1] eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] eq "ARRAY" or croak("Invalid pragmas (not an array reference)") 2 1 3
875 or croak "Invalid pragmas (not an array reference)";
876 2 @{$_[0]{pragmas}} = @{$_[1]};
877 }
878 5 ▶sub _set_vars {
Subroutine _set_vars: called CC=8 SCAR=20.8
879 5 ▶ $_[1] // return undef %{$_[0]{vars}};
Condition100%2/2
$_[1] // (return undef %{$_[0]{"vars"};})
l!l
41
MC/DC100%1/1
$_[1] // (return undef %{$_[0]{"vars"};})
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
880 4 ▶ ref $_[1] eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] eq "HASH" or croak("Invalid vars (not a hash reference)") 3 1 4
881 or croak "Invalid vars (not a hash reference)";
882  
883 3 ▶ while (my($name, $ref) = each %{$_[1]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$_[1];}) 8 3 11
884 8 ▶ if (defined $ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref) { } 7 1 8
885 7 ▶ my $sigil = $sigil{Scalar::Util::reftype $ref // 'CODE'} // '$';
Condition100%4/4
$sigil{builtin::reftype($ref) // "CODE"} // "\$"
l!l
52
builtin::reftype($ref) // "CODE"
l!l
61
MC/DC100%1/1
$sigil{builtin::reftype($ref) // "CODE"} // "\$"
$sigil{builtin::reftype($ref) // "CODE"}
MC/DC100%1/1
builtin::reftype($ref) // "CODE"
builtin::reftype($ref)
Truth table100%2/2
A
A= $sigil{builtin::reftype($ref) // "CODE"}
Aresult
11
00
Truth table100%2/2
A
A= builtin::reftype($ref)
Aresult
11
00
886 7 ▶ $name =~ s/^\Q$sigil\E?/$sigil ne '&' && $sigil/e;
Condition66%2/3
$sigil ne '&' && $sigil
!ll&&!rl&&r
205
MC/DC50%1/2
$sigil ne '&' && $sigil
$sigil ne '&' $sigil
Truth table66%2/3
A && B
A= $sigil ne '&'B= $sigil
ABresult
0X0
100
111
887 7 $_[0]{vars}{$name} = $ref;
888 } else {
889 1 delete $_[0]{vars}{$name};
890 }
891 }
892 }
893  
894 60 ▶sub set {
Subroutine set: called CC=17 SCAR=28.3
Pod documented
895 60 my($self, %opt) = @_;
896  
897 60 ▶ while (my($k, $v) = each %opt) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %opt) 82 52 134
898 82 ▶ my $c = $self->can("_set_$k")
Branch: 1 branch
BranchTrueFalseTotal
my $c = $self->can("_set_$k") or croak("Invalid setting '${k}'") 81 1 82
899 or croak "Invalid setting '$k'";
900 81 $c->($self, $v);
901 }
902  
903 52 ▶ if (defined $$self{path}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'path'}) { } 48 4 52
904 48 undef $!;
905 48 ▶ my $dir = length $$self{path} ? $$self{path} : '.';
Branch: 1 branch
BranchTrueFalseTotal
length $self->{'path'} ? : 22 26 48
906 48 ▶ -d $dir and -r _ or croak "Can't set path to $dir: ".($! || 'Not accessable');
Branch: 1 branch
BranchTrueFalseTotal
-d $dir and -r _ or croak("Can't set path to ${dir}: " . ($! || "Not accessable")) 46 2 48
Condition100%5/5
-d $dir and -r _
!ll&&!rl&&r
1146
$! || 'Not accessable'
l!l
11
MC/DC100%2/2
-d $dir and -r _
-d $dir -r _
MC/DC100%1/1
$! || 'Not accessable'
$!
Truth table100%3/3
A and B
A= -d $dirB= -r _
ABresult
0X0
100
111
Truth table100%2/2
A
A= $!
Aresult
11
00
907 46 ▶ undef $$self{static} if $$self{static} and $$self{static} eq 'auto';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"static"} and $self->{"static"} eq "auto" 7 39 46
Condition100%3/3
$self->{"static"} and $self->{"static"} eq "auto"
!ll&&!rl&&r
3727
MC/DC100%2/2
$self->{"static"} and $self->{"static"} eq "auto"
$self->{"static"} $self->{"static"} eq "auto"
Truth table100%3/3
A and B
A= $self->{"static"}B= $self->{"static"} eq "auto"
ABresult
0X0
100
111
908 } else {
909 4 ▶ $$self{static} ||= 'auto';
Condition100%2/2
$self->{"static"} ||= "auto"
l!l
13
MC/DC100%1/1
$self->{"static"} ||= "auto"
$self->{"static"}
Truth table100%2/2
A
A= $self->{"static"}
Aresult
11
00
910 }
911  
912 50 ▶ if (defined $$self{cache_path}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'cache_path'}) { } 18 32 50
elsif (not $self->{'cache_code'}) { } 9 23 32
913 18 my $dir = $$self{cache_path};
914 18 ▶ if (-d $dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $dir) { } 13 5 18
915 13 ▶ -w _ or croak "Cache directory $dir is not writeable";
Branch: 1 branch
BranchTrueFalseTotal
-w _ or croak("Cache directory $dir is not writeable") 12 1 13
916 } else {
917 5 my $umask = umask $$self{umask};
918 5 ▶ (mkdir($dir), umask $umask)[0]
Branch: 1 branch
BranchTrueFalseTotal
(mkdir($dir), umask $umask)[0] or croak("Can't create cache directory ${dir}: $!") 4 1 5
919 or croak "Can't create cache directory $dir: $!";
920 }
921 } elsif (not $$self{cache_code}) {
922 9 ▶ $$self{static} ||= 'auto';
Condition100%2/2
$self->{"static"} ||= "auto"
l!l
18
MC/DC100%1/1
$self->{"static"} ||= "auto"
$self->{"static"}
Truth table100%2/2
A
A= $self->{"static"}
Aresult
11
00
923 }
924 }
925  
926 =head1 AUTHOR
927  
928 Vernon Lyon C<< <vlyon@cpan.org> >>
929  
930 =head1 BUGS
931  
932 Please report any bugs or feature requests on L<GitHub issues|https://github.com/vlyon/Plate/issues>.
933  
934 =head1 SOURCE
935  
936 The source code is hosted on L<GitHub|https://github.com/vlyon/Plate>.
937 Feel free to fork the repository and submit pull requests!
938  
939 =head1 SUPPORT
940  
941 You can find documentation for this module with the perldoc command.
942  
943 perldoc Plate
944  
945 You can also read the documentation online on L<metacpan|https://metacpan.org/pod/Plate>.
946  
947 =head1 COPYRIGHT AND LICENSE
948  
949 Copyright (C) 2018, Vernon Lyon.
950  
951 This library is free software; you can redistribute it and/or modify
952 it under the same terms as Perl itself.
953  
954 =cut
955  
956 7 1;
↑ Summary