File Coverage

blib/lib/Gears/Template/TT.pm
Criterion Covered Total %
statement 30 30 100.0
branch 8 8 100.0
condition 3 8 37.5
subroutine 6 6 100.0
pod 1 1 100.0
total 48 53 90.5


line stmt bran cond sub pod time code
1             package Gears::Template::TT;
2             $Gears::Template::TT::VERSION = '0.102';
3 1     1   17 use v5.40;
  1         4  
4 1     1   7 use Mooish::Base -standard;
  1         3  
  1         11  
5              
6 1     1   20925 use Template;
  1         39285  
  1         92  
7 1     1   11 use Gears::X::Template;
  1         31  
  1         595  
8              
9             extends 'Gears::Template';
10              
11             has param 'conf' => (
12             isa => HashRef,
13             default => sub { {} },
14             );
15              
16             has field 'engine' => (
17             isa => InstanceOf ['Template'],
18             lazy => 1,
19             );
20              
21             sub _build_engine ($self)
22 1     1   11 {
  1         1  
  1         2  
23 1         5 my %conf = $self->conf->%*;
24 1   33     12 $conf{ENCODING} //= $self->encoding;
25 1   33     8 $conf{INCLUDE_PATH} //= $self->paths;
26              
27 1         13 return Template->new(\%conf);
28             }
29              
30             # override process to let TT load the templates itself
31 6         9 sub process ($self, $template, $vars)
  6         36  
32 6     6 1 9 {
  6         9  
  6         5  
33 6 100       22 my $pos = ref $template eq 'GLOB' ? tell $template : undef;
34              
35 6 100 50     35 $template =~ s{(\..+)?$}{$1 // '.tt' }e
  3         31  
36             unless ref $template;
37              
38 6         10 my $output;
39 6 100       173 $self->engine->process($template, $vars, \$output)
40             or Gears::X::Template->raise('' . $self->engine->error);
41              
42             # rewind if we were passed a handle
43 5 100       91673 seek $template, $pos, 0
44             if defined $pos;
45              
46 5         62 return $output;
47             }
48