| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Dancer2::Template::Tiny; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Template::Tiny engine for Dancer2 |
|
3
|
|
|
|
|
|
|
$Dancer2::Template::Tiny::VERSION = '2.1.0'; |
|
4
|
121
|
|
|
121
|
|
444007
|
use Moo; |
|
|
121
|
|
|
|
|
13212
|
|
|
|
121
|
|
|
|
|
1293
|
|
|
5
|
121
|
|
|
121
|
|
58930
|
use Carp qw/croak/; |
|
|
121
|
|
|
|
|
325
|
|
|
|
121
|
|
|
|
|
9441
|
|
|
6
|
121
|
|
|
121
|
|
1923
|
use Path::Tiny (); |
|
|
121
|
|
|
|
|
21588
|
|
|
|
121
|
|
|
|
|
3454
|
|
|
7
|
121
|
|
|
121
|
|
2983
|
use Dancer2::Core::Types; |
|
|
121
|
|
|
|
|
292
|
|
|
|
121
|
|
|
|
|
1747
|
|
|
8
|
121
|
|
|
121
|
|
2007544
|
use Template::Tiny; |
|
|
121
|
|
|
|
|
188386
|
|
|
|
121
|
|
|
|
|
32360
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with 'Dancer2::Core::Role::Template'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has '+engine' => ( |
|
13
|
|
|
|
|
|
|
isa => InstanceOf ['Template::Tiny'] |
|
14
|
|
|
|
|
|
|
); |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _build_engine { |
|
17
|
10
|
|
|
10
|
|
157
|
Template::Tiny->new( %{ $_[0]->config } ); |
|
|
10
|
|
|
|
|
157
|
|
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub render { |
|
21
|
23
|
|
|
23
|
1
|
165
|
my ( $self, $template, $tokens ) = @_; |
|
22
|
|
|
|
|
|
|
|
|
23
|
23
|
100
|
100
|
|
|
1255
|
( ref $template || -f $template ) |
|
24
|
|
|
|
|
|
|
or croak "$template is not a regular file or reference"; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $template_data = |
|
27
|
|
|
|
|
|
|
ref $template |
|
28
|
22
|
100
|
|
|
|
144
|
? ${$template} |
|
|
1
|
|
|
|
|
3
|
|
|
29
|
|
|
|
|
|
|
: Path::Tiny::path($template)->slurp_utf8; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Template::Tiny doesn't like empty template files (like .dancer), so |
|
32
|
|
|
|
|
|
|
# don't try to render them. Return an empty (not undef) value instead. |
|
33
|
22
|
50
|
|
|
|
5767
|
return '' unless $template_data; |
|
34
|
|
|
|
|
|
|
|
|
35
|
22
|
|
|
|
|
48
|
my $content; |
|
36
|
|
|
|
|
|
|
|
|
37
|
22
|
50
|
|
|
|
793
|
$self->engine->process( \$template_data, $tokens, \$content, ) |
|
38
|
|
|
|
|
|
|
or die "Could not process template file '$template'"; |
|
39
|
|
|
|
|
|
|
|
|
40
|
22
|
|
|
|
|
17850
|
return $content; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |