| 1 | package Dancer2::Template::Tiny; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Template::Tiny engine for Dancer2 | ||||||||||||||||||||||||||||
| 3 | 140 | $Dancer2::Template::Tiny::VERSION = '2.3.0'; | |||||||||||||||||||||||||||
| 4 | 140 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 140 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 140 | ▶ | use Path::Tiny (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 140 | ▶ | use Dancer2::Core::Types; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 140 | ▶ | use Template::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 140 | with 'Dancer2::Core::Role::Template'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 140 | has '+engine' => ( | |||||||||||||||||||||||||||
| 13 | isa => InstanceOf ['Template::Tiny'] | ||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 16 | ▶ | sub _build_engine { | ||||||||||||||||||||||||||
|
Subroutine
_build_engine: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 16 | Template::Tiny->new( %{ $_[0]->config } ); | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 110 | ▶ | sub render { | ||||||||||||||||||||||||||
|
Subroutine
render: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 110 | my ( $self, $template, $tokens ) = @_; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 110 | ▶ | ( ref $template || -f $template ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $template or -f $template
MC/DC100%2/2
ref $template or -f $template
ref $template
-f $template
Truth table100%3/3
A or B
A= ref $templateB= -f $template
| |||||||||||||||||||||||||||||
| 24 | or croak "$template is not a regular file or reference"; | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | my $template_data = | ||||||||||||||||||||||||||||
| 27 | ref $template | ||||||||||||||||||||||||||||
| 28 | 109 | ▶ | ? ${$template} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 109 | ▶ | return '' unless $template_data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 104 | my $content; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 104 | ▶ | $self->engine->process( \$template_data, $tokens, \$content, ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | or die "Could not process template file '$template'"; | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 104 | return $content; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 140 | 1; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | __END__ | ||||||||||||||||||||||||||||