File Coverage

blib/lib/Dancer2/Template/HTCompiled.pm
Criterion Covered Total %
statement 33 33 100.0
branch 5 6 83.3
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 46 47 97.8


line stmt bran cond sub pod time code
1             package Dancer2::Template::HTCompiled;
2 2     2   27408 use strict;
  2         4  
  2         77  
3 2     2   11 use warnings;
  2         3  
  2         86  
4             our $VERSION = '0.003'; # VERSION
5              
6 2     2   1251 use Moo;
  2         25246  
  2         10  
7 2     2   2339 use Carp qw/ croak /;
  2         2  
  2         86  
8 2     2   1532 use HTML::Template::Compiled;
  2         87869  
  2         12  
9              
10             with 'Dancer2::Core::Role::Template';
11              
12             has '+default_tmpl_ext' => (
13             default => sub { 'html' }
14             );
15             has '+engine' => (
16             isa => sub {
17             $_[0] eq "HTML::Template::Compiled"
18             },
19             );
20              
21             sub _build_engine {
22 1     1   421 'HTML::Template::Compiled'
23             }
24              
25             sub render {
26 4     4 1 1754 my ($self, $tmpl, $vars) = @_;
27              
28 4         6 my %config = %{ $self->config };
  4         19  
29 4         7 my $env = delete $config{environment};
30 4         6 my $location = delete $config{location};
31 4 50       46 $config{path} = File::Spec->catfile($location, $config{path})
32             if defined $location;
33 4         70 my $htc = $self->engine;
34 4         22 my $content = eval {
35 4         4 my $t;
36 4 100       10 if ( ref($tmpl) eq 'SCALAR' ) {
37 2         7 $t = $htc->new_scalar_ref($tmpl, %config);
38             }
39             else {
40 2         15 $t = $htc->new_file($tmpl, %config);
41             }
42 3         3930 $t->param($vars);
43 3         49 $t->output;
44             };
45              
46 4 100       833 if (my $error = $@) {
47 1         19 croak $error;
48             }
49              
50 3         9 return $content;
51             }
52              
53             1;
54              
55             __END__