File Coverage

blib/lib/Eidolon/Driver/Template/HTML.pm
Criterion Covered Total %
statement 12 28 42.8
branch 0 4 0.0
condition 0 2 0.0
subroutine 4 7 57.1
pod 3 3 100.0
total 19 44 43.1


line stmt bran cond sub pod time code
1             package Eidolon::Driver::Template::HTML;
2             # ==============================================================================
3             #
4             # Eidolon
5             # Copyright (c) 2009, Atma 7
6             # ---
7             # Eidolon/Driver/Template/HTML.pm - HTML::Template driver
8             #
9             # ==============================================================================
10              
11 1     1   51610 use base qw/Eidolon::Driver::Template/;
  1         2  
  1         71  
12 1     1   1726 use HTML::Template;
  1         18510  
  1         41  
13 1     1   10 use warnings;
  1         9  
  1         30  
14 1     1   5 use strict;
  1         1  
  1         307  
15              
16             our $VERSION = "0.01"; # 2008-07-20 05:10:45
17              
18             # ------------------------------------------------------------------------------
19             # \% new()
20             # constructor
21             # ------------------------------------------------------------------------------
22             sub new
23             {
24 0     0 1   my ($class, $templates_dir, $additional, $self);
25              
26 0           ($class, $templates_dir, $additional) = @_;
27              
28 0           $self = $class->SUPER::new($templates_dir);
29 0   0       $self->{"additional"} = $additional || {};
30              
31 0           return $self;
32             }
33              
34             # ------------------------------------------------------------------------------
35             # parse($tpl)
36             # parse template
37             # ------------------------------------------------------------------------------
38             sub parse
39             {
40 0     0 1   my ($self, $tpl) = @_;
41              
42 0 0         throw DriverError::Template::Open($tpl) if (!-f $self->{"templates_dir"}.$tpl);
43              
44             # create object
45 0           $self->{"object"} = HTML::Template->new
46             (
47             "filename" => $tpl,
48             "path" => [ $self->{"templates_dir"} ],
49             "die_on_bad_params" => 0,
50 0           %{ $self->{"additional"} }
51             );
52              
53             # set variables
54 0           foreach (keys %{ $self->{"vars"} })
  0            
55             {
56 0           $self->{"object"}->param($_ => $self->{"vars"}->{$_});
57             }
58              
59 0           $self->{"result"} = $self->{"object"}->output;
60             }
61              
62             # ------------------------------------------------------------------------------
63             # render()
64             # render template
65             # ------------------------------------------------------------------------------
66             sub render
67             {
68 0     0 1   my $self = shift;
69              
70 0 0         throw DriverError::Template::NotParsed if (!$self->{"object"});
71              
72 0           print $self->{"result"};
73             }
74              
75             1;
76              
77             __END__