| 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.0.1'; |
|
4
|
118
|
|
|
118
|
|
444631
|
use Moo; |
|
|
118
|
|
|
|
|
12755
|
|
|
|
118
|
|
|
|
|
1030
|
|
|
5
|
118
|
|
|
118
|
|
60115
|
use Carp qw/croak/; |
|
|
118
|
|
|
|
|
283
|
|
|
|
118
|
|
|
|
|
9730
|
|
|
6
|
118
|
|
|
118
|
|
2367
|
use Dancer2::Core::Types; |
|
|
118
|
|
|
|
|
351
|
|
|
|
118
|
|
|
|
|
1616
|
|
|
7
|
118
|
|
|
118
|
|
1926630
|
use Template::Tiny; |
|
|
118
|
|
|
|
|
184379
|
|
|
|
118
|
|
|
|
|
5541
|
|
|
8
|
118
|
|
|
118
|
|
2789
|
use Dancer2::FileUtils 'read_file_content'; |
|
|
118
|
|
|
|
|
315
|
|
|
|
118
|
|
|
|
|
37351
|
|
|
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
|
|
|
|
|
185
|
|
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub render { |
|
21
|
23
|
|
|
23
|
1
|
79
|
my ( $self, $template, $tokens ) = @_; |
|
22
|
|
|
|
|
|
|
|
|
23
|
23
|
100
|
100
|
|
|
1442
|
( 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
|
|
|
|
208
|
? ${$template} |
|
|
1
|
|
|
|
|
3
|
|
|
29
|
|
|
|
|
|
|
: read_file_content($template); |
|
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
|
|
|
|
92
|
return '' unless $template_data; |
|
34
|
|
|
|
|
|
|
|
|
35
|
22
|
|
|
|
|
45
|
my $content; |
|
36
|
|
|
|
|
|
|
|
|
37
|
22
|
50
|
|
|
|
778
|
$self->engine->process( \$template_data, $tokens, \$content, ) |
|
38
|
|
|
|
|
|
|
or die "Could not process template file '$template'"; |
|
39
|
|
|
|
|
|
|
|
|
40
|
22
|
|
|
|
|
18840
|
return $content; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |