File Coverage

blib/lib/Prancer/Template.pm
Criterion Covered Total %
statement 18 39 46.2
branch 0 8 0.0
condition 0 6 0.0
subroutine 6 11 54.5
pod 0 1 0.0
total 24 65 36.9


line stmt bran cond sub pod time code
1             package Prancer::Template;
2              
3 4     4   2831 use strict;
  4         5  
  4         131  
4 4     4   10 use warnings FATAL => 'all';
  4         4  
  4         100  
5              
6 4     4   10 use Carp;
  4         3  
  4         161  
7 4     4   12 use Try::Tiny;
  4         3  
  4         173  
8 4     4   12 use Module::Load ();
  4         4  
  4         67  
9 4     4   21 use Prancer qw(logger);
  4         4  
  4         1140  
10              
11             sub load {
12 0     0 0       my ($class, $config) = @_;
13              
14 0 0 0           unless (ref($config) && ref($config) eq "HASH" && $config->{'driver'}) {
      0        
15 0                   logger->warn("could not initialize template engine: no template engine configuration");
16 0                   return;
17                 }
18              
19 0               my $module = $config->{'driver'};
20              
21                 try {
22 0     0             Module::Load::load($module);
23                 } catch {
24 0 0   0             my $error = (defined($_) ? $_ : "unknown");
25 0                   logger->fatal("could not initialize template engine: not able to load ${module}: ${error}");
26 0                   croak;
27 0               };
28              
29 0 0             unless ($module->can("render")) {
30 0                   logger->fatal("could not initialize template engine: ${module} doesn't implement 'render'");
31 0                   croak;
32                 }
33              
34 0               my $engine = undef;
35                 try {
36 0     0             $engine = $module->new($config->{'options'});
37 0                   logger->info("initialized template engine with ${module}");
38                 } catch {
39 0 0   0             my $error = (defined($_) ? $_ : "unknown");
40 0                   logger->fatal("could not initialize template engine: ${error}");
41 0                   croak;
42 0               };
43              
44 0               return $engine;
45             }
46              
47             1;
48              
49             =head1 NAME
50            
51             Prancer::Template
52            
53             =head1 SYNOPSIS
54            
55             This module should not be used directly to access templates. Instead, one
56             should use L<Prancer>. For configuration options, please refer to the
57             documentation for the specific template engine you wish to use.
58            
59             =head1 SEE ALSO
60            
61             =over 4
62            
63             =item1 L<Prancer::Template::TemplateToolkit>
64            
65             =back
66            
67             =cut
68