File Coverage

blib/lib/Dancer2/Template/MojoTemplate.pm
Criterion Covered Total %
statement 18 29 62.0
branch 0 6 0.0
condition n/a
subroutine 6 8 75.0
pod 0 1 0.0
total 24 44 54.5


line stmt bran cond sub pod time code
1             package Dancer2::Template::MojoTemplate;
2              
3             # ABSTRACT: Mojo::Template wrapper for Dancer2
4              
5 1     1   1315 use strict;
  1         2  
  1         49  
6 1     1   7 use warnings;
  1         2  
  1         40  
7 1     1   7 use Carp;
  1         14  
  1         115  
8 1     1   2780 use Moo;
  1         23500  
  1         6  
9 1     1   2317 use Dancer2::Core::Types;
  1         11763  
  1         361  
10 1     1   1057 use Mojo::Template;
  1         146112  
  1         11  
11              
12             with 'Dancer2::Core::Role::Template';
13              
14             has '+engine' => (
15             isa => InstanceOf ['Mojo::Template']
16             );
17              
18             has "+default_tmpl_ext" => (
19             default => sub { 'html.ep' },
20             );
21            
22              
23             sub _build_engine {
24 0     0     my $self = shift;
25 0           my $charset = $self->charset;
26 0           my %config = (
27 0           %{$self->config}
28             );
29              
30 0           return Mojo::Template->new(%config);
31             }
32              
33             sub render {
34 0     0 0   my ($self, $template, $tokens) = @_;
35              
36 0 0         if (!ref $template) {
37 0 0         -f $template
38             or croak "'$template' doesn't exist or not a regular file";
39             }
40              
41 0           my $content = $self->engine->render_file($template, $tokens);
42              
43 0 0         die "Couldn't render template: $@" if $@;
44              
45 0           return $content;
46             }
47              
48             1;
49             __END__