| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 334 | $text =~ s/(\\|')/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 334 | ▶ | length $text ? "'$text'" : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 180 | ▶ | if (length $_[1]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 125 | ▶ | if (defined $stmt) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 85 | ▶ | $stmt .= ';push@Plate::_l,length$Plate::_b,__LINE__' if $pre; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 72 | ▶ | $stmt //= q"local$Plate::_b='';"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$stmt //= "local\$Plate::_b='';"
MC/DC100%1/1
$stmt //= "local\$Plate::_b='';"
$stmt
Truth table100%2/2
A
A= $stmt
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 197 | ▶ | undef $fix_line_num unless $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 274 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 274 | ▶ | while ($_[0] =~ /$_[1]/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 551 | ▶ | if (length $1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 334 | ▶ | $fix_line_num = @expr if $fix_line_num; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 551 | ▶ | if (!$pre and @Plate::_l and $Plate::_l[0] <= $+[1]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not $pre and @Plate::_l and $Plate::_l[0] <= $+[1]
not $pre and @Plate::_l
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
@Plate::_l and $Plate::_l[0] <= $+[1]
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 24 | my $rem = $+[1] - $pos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 24 | ▶ | $line += substr($_[0], $pos, $rem) =~ tr/\n// if $rem; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 24 | $expr2stmt->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 24 | $stmt .= "\n#line $line\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 551 | ▶ | if (defined $2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | my $line = 1 + $stmt =~ y/\n//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | ▶ | $line = "$_[2] line $line.\nPlate ".($pre && 'pre').'compilation failed'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$pre && 'pre'
MC/DC100%1/1
$pre && 'pre'
$pre
Truth table100%2/2
A
A= $pre
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 2 | ▶ | my $tag = ($pre && '%').'%'.$3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$pre && '%'
MC/DC100%1/1
$pre && '%'
$pre
Truth table100%2/2
A
A= $pre
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 && '%'
MC/DC100%1/1
$pre && '%'
$pre
Truth table100%2/2
A
A= $pre
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 9 | my $n = _parse_defn $6; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 9 | ▶ | $stmt .= $5 eq 'def' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 4 | ▶ | $fix_line_num = @expr if $fix_line_num; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 111 | ▶ | $expr2stmt->() if $pre; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$pre or $fix_line_num
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 69 | ▶ | if (defined $tmpl) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 58 | ▶ | if ($tmpl eq '_') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | $fix_line_num = push @expr, _parse_fltr defined $10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 26 | ▶ | ? do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 9 | ▶ | $args = defined $args ? "($args)" : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 9 | ▶ | local $_[3] = $pre ? '&&' : '&'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 9 | ▶ | '(@Plate::_c?do{local@Plate::_c=@Plate::_c;&{splice@Plate::_c,-1,1,sub{'.&_parse."}}$args}:undef)$nl" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | : defined $args ? "do{Plate::content($args)}$nl" : "do{&Plate::content}$nl", $12; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 26 | ▶ | $expr2stmt->() if $pre and $nl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$pre and $nl
MC/DC100%2/2
$pre and $nl
$pre
$nl
Truth table100%3/3
A and B
A= $preB= $nl
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 26 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 32 | ▶ | $tmpl = defined $args ? "Plate::_r('$tmpl',($args)," : "Plate::_r('$tmpl',"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 11 | $tmpl = "Plate::_r($11,"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 43 | ▶ | $fix_line_num = push @expr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$pre and $nl
MC/DC100%2/2
$pre and $nl
$pre
$nl
Truth table100%3/3
A and B
A= $preB= $nl
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # </%...> or </&> or \z | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 271 | ▶ | my $tag = $13 // $14 // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%5/5
($13 // $14) // ""
$13 // $14
MC/DC100%2/2
($13 // $14) // ""
$13
$14
Truth table100%3/3
A // B
A= $13B= $14
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 271 | ▶ | if ($tag ne $_[3]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 3 | ▶ | my $line = 1 + join('', $stmt // '', @expr) =~ y/\n//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$stmt // ""
MC/DC100%1/1
$stmt // ""
$stmt
Truth table100%2/2
A
A= $stmt
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 3 | ▶ | $line = "$_[2] line $line.\nPlate ".($pre && 'pre').'compilation failed'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$pre && 'pre'
MC/DC100%1/1
$pre && 'pre'
$pre
Truth table100%2/2
A
A= $pre
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 3 | ▶ | croak $tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 86 | ▶ | $stmt .= ';push@Plate::_l,length$Plate::_b,__LINE__' if $pre and @expr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$pre and @expr
MC/DC100%2/2
$pre and @expr
$pre
@expr
Truth table100%3/3
A and B
A= $preB= @expr
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 86 | ▶ | $stmt.join('.', ';$Plate::_b', @expr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | : @expr ? join('.', @expr) : "''"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 268 | ▶ | $pl .= '=~s/\R\z//r' if !$pre and $$Plate::_s{chomp}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $pre and $Plate::_s->{"chomp"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 268 | ▶ | $pl .= "\n" if defined $13; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 268 | return $pl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 251 | ▶ | if (!$pre and @Plate::_l and $Plate::_l[0] <= $+[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not $pre and @Plate::_l and $Plate::_l[0] <= $+[0]
not $pre and @Plate::_l
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
@Plate::_l and $Plate::_l[0] <= $+[0]
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 5 | my $rem = $+[0] - $pos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 5 | ▶ | $line += substr($_[0], $pos, $rem) =~ tr/\n// if $rem; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | or croak $@.'Plate precompilation failed'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 117 | ▶ | defined($pl = eval { $sub->() }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 108 | ▶ | $$Plate::_s{mod}{$_[3]} = $_[4] if defined $_[4]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
not $dir =~ s[/[^/]*$][]u or -d $_[0]{"cache_path"} . $dir
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 10 | ▶ | return unless @mkdir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 2 | my $umask = umask $_[0]{umask}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 2 | ▶ | mkdir $_ or umask $umask, croak "Can't create cache directory $_: $!" for @mkdir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 29 | ▶ | if ($_[0]{static}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 7 | ▶ | return do $cache // croak $@ ? $@.'Plate compilation failed' : "Couldn't load $cache: $!" if -f $cache; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%2/2
do $cache // croak($@ ? $@ . 'Plate compilation failed' : "Couldn't load ${cache}: $!")
MC/DC100%1/1
do $cache // croak($@ ? $@ . 'Plate compilation failed' : "Couldn't load ${cache}: $!")
do $cache
Truth table100%2/2
A
A= do $cache
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 2 | ▶ | $plate // croak "Plate template '$_[1]' does not exist"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$plate // croak("Plate template '$_[1]' does not exist")
MC/DC100%1/1
$plate // croak("Plate template '$_[1]' does not exist")
$plate
Truth table100%2/2
A
A= $plate
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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}: $!")
$_[2] // (stat $plate)[9]
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 18 | ▶ | if (-f $cache and ($_[0]{mod}{$_[1]} // (stat _)[9]) >= $_n) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
-f $cache and ($_[0]{"mod"}{$_[1]} // (stat _)[9]) >= $_n
$_[0]{"mod"}{$_[1]} // (stat _)[9]
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 9 | ▶ | my $sub = do $cache // croak $@ ? $@.'Plate compilation failed' : "Couldn't load $cache: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
do $cache // croak($@ ? $@ . 'Plate compilation failed' : "Couldn't load ${cache}: $!")
MC/DC100%1/1
do $cache // croak($@ ? $@ . 'Plate compilation failed' : "Couldn't load ${cache}: $!")
do $cache
Truth table100%2/2
A
A= do $cache
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 7 | ▶ | $_[0]{mod}{$_[1]} //= $_n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_[0]{"mod"}{$_[1]} //= $_n
MC/DC0%0/2
$_[0]{"mod"}{$_[1]} //= $_n
$_[0]{"mod"}{$_[1]}
$_n
Truth table66%2/3
A //= B
A= $_[0]{"mod"}{$_[1]}B= $_n
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$_[0]{"static"} or exists $_[0]{"mod"}{$_[1]}
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]}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
$_[0]{"static"} or not exists $_[0]{"mod"}{$_[1]}
$_[0]{"mem"}{$_[1]} //= $_[0]->_load($_[1])
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]}
Truth table100%3/3
A //= B
A= $_[0]{"mem"}{$_[1]}B= $_[0]->_load($_[1])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 6 | ▶ | my $mod = (stat $_[0]->_plate_file($_[1]))[9] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$_[0]{"mem"}{$_[1]} //= $_[0]->_load($_[1], $mod)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$Plate::_s->{"mem"}{$_[0]} // $Plate::_s->_load($_[0])
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])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 6 | ▶ | return undef unless @Plate::_c; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 3 | ▶ | if (defined(my $c = pop)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC100%1/1
pop() // \&Plate::_empty
pop()
Truth table100%2/2
A
A= pop()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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")
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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
length $vol or not $_[1]
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition88%8/9
$_[1] and not length $vol and length $dir[0] || @dir == 1
$_[1] and not length $vol
length $dir[0] or @dir == 1
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 21 | $vol.join('/', @dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 7 | my %esc_html = ('"' => '"', '&' => '&', "'" => ''', '<' => '<', '>' => '>'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
shift() // croak("Template name is undefined")
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()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 109 | ▶ | my $sub = ref $tmpl eq 'SCALAR' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 31 | ▶ | $_[0]{mem}{$_[1]} = ref $_[2] eq 'CODE' ? $_[2] : do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%2/2
$Plate::_s // croak("Can only be called as a subroutine from within a template")
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
$self->{"cache_code"} and not $self->{"static"} and exists $self->{"mod"}{$name}
$self->{"cache_code"} and not $self->{"static"}
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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$self->_plate_file($name) // $self->_cache_file($name)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%2/2
$Plate::_s // croak("Can only be called as a subroutine from within a template")
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%2/2
$Plate::_s // croak("Can only be called as a subroutine from within a template")
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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")
MC/DC0%0/1
$self->{"filters"}{$_} // croak("No '${_}' filter defined")
$self->{"filters"}{$_}
Truth table50%1/2
A
A= $self->{"filters"}{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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] // ""
$_[1] // ""
$_[1] // ""
$_[1] // ""
$_[1] // ""
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]
Truth table100%2/2
A
A= $_[1]
Truth table50%1/2
A
A= $_[1]
Truth table100%2/2
A
A= $_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"};})
MC/DC100%1/1
$_[1] // (return undef %{$_[0]{"filters"};})
$_[1]
Truth table100%2/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 8 | ▶ | ref $_[1] eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | or croak "Invalid filters (not a hash reference)"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 7 | ▶ | while (my($name, $code) = each %{$_[1]}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 8 | ▶ | $name =~ /^\w+$/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | or croak "Invalid filter name '$name'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 7 | ▶ | if (defined $code) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | ref $code eq 'CODE' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | or $code = ($code =~ /(.*)::(.*)/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | ? $1->can($2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 5 | ▶ | : do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
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)
}
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)
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 1 | my($i,$p) = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 1 | ▶ | $i++ while __PACKAGE__ eq ($p = caller $i); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%5/5
defined $_[1] and $_[1] =~ /^[A-Z_a-z][0-9A-Z_a-z]*(?:::[0-9A-Z_a-z]+)*$/u
$_[1] // ""
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
Truth table100%2/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"};})
MC/DC100%1/1
$_[1] // (return undef %{$_[0]{"vars"};})
$_[1]
Truth table100%2/2
A
A= $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 4 | ▶ | ref $_[1] eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | or croak "Invalid vars (not a hash reference)"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 3 | ▶ | while (my($name, $ref) = each %{$_[1]}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 8 | ▶ | if (defined $ref) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 7 | ▶ | my $sigil = $sigil{Scalar::Util::reftype $ref // 'CODE'} // '$'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%4/4
$sigil{builtin::reftype($ref) // "CODE"} // "\$"
builtin::reftype($ref) // "CODE"
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"}
Truth table100%2/2
A
A= builtin::reftype($ref)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 7 | ▶ | $name =~ s/^\Q$sigil\E?/$sigil ne '&' && $sigil/e; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$sigil ne '&' && $sigil
MC/DC50%1/2
$sigil ne '&' && $sigil
$sigil ne '&'
$sigil
Truth table66%2/3
A && B
A= $sigil ne '&'B= $sigil
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 82 | ▶ | my $c = $self->can("_set_$k") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | or croak "Invalid setting '$k'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 81 | $c->($self, $v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 52 | ▶ | if (defined $$self{path}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 48 | undef $!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 48 | ▶ | my $dir = length $$self{path} ? $$self{path} : '.'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 48 | ▶ | -d $dir and -r _ or croak "Can't set path to $dir: ".($! || 'Not accessable'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
-d $dir and -r _
$! || 'Not accessable'
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 _
Truth table100%2/2
A
A= $!
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 46 | ▶ | undef $$self{static} if $$self{static} and $$self{static} eq 'auto'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"static"} and $self->{"static"} eq "auto"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 4 | ▶ | $$self{static} ||= 'auto'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"static"} ||= "auto"
MC/DC100%1/1
$self->{"static"} ||= "auto"
$self->{"static"}
Truth table100%2/2
A
A= $self->{"static"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 50 | ▶ | if (defined $$self{cache_path}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 18 | my $dir = $$self{cache_path}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 18 | ▶ | if (-d $dir) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 13 | ▶ | -w _ or croak "Cache directory $dir is not writeable"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 5 | my $umask = umask $$self{umask}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | 5 | ▶ | (mkdir($dir), umask $umask)[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
MC/DC100%1/1
$self->{"static"} ||= "auto"
$self->{"static"}
Truth table100%2/2
A
A= $self->{"static"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||