lib/Dancer2/Template/Tiny.pm

filter: Statementstmt 100% 29 / 29 Branchbran 87.5% 7 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 98.0% 49 / 50 CC 6 SCAR 12.5
CC
6
Cov
98%
render
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.5
« blib/lib/Dancer2/Serializer/JSON.pm ↑ Summary blib/lib/Dancer2/Logger/File.pm »
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
BranchTrueFalseTotal
ref $template or -f $template or croak("$template is not a regular file or reference") 109 1 110
Condition100%3/3
ref $template or -f $template
l!l&&r!l&&!r
86231
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
ref $template ? : 86 23 109
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
BranchTrueFalseTotal
unless $template_data 5 104 109
34  
35 104 my $content;
36  
37 104 ▶ $self->engine->process( \$template_data, $tokens, \$content, )
Branch: 1 branch
BranchTrueFalseTotal
$self->engine->process(\$template_data, $tokens, \$content) or die "Could not process template file '${template}'" 104 0 104
38 or die "Could not process template file '$template'";
39  
40 104 return $content;
41 }
42  
43 140 1;
44  
45 __END__
« blib/lib/Dancer2/Serializer/JSON.pm ↑ Summary blib/lib/Dancer2/Logger/File.pm »