File Coverage

lib/Any/Template/Backend/TemplateToolkit.pm
Criterion Covered Total %
statement 32 46 69.5
branch 3 16 18.7
condition n/a
subroutine 9 14 64.2
pod 6 8 75.0
total 50 84 59.5


line stmt bran cond sub pod time code
1             package Any::Template::Backend::TemplateToolkit;
2              
3 1     1   25334 use strict;
  1         2  
  1         35  
4 1     1   5 use Template;
  1         2  
  1         19  
5 1     1   309 use Any::Template::Backend;
  1         2  
  1         25  
6 1     1   6 use vars qw(@ISA);
  1         1  
  1         42  
7             @ISA = qw(Any::Template::Backend);
8              
9 1     1   5 use vars qw($VERSION);
  1         2  
  1         522  
10             $VERSION = sprintf"%d.%03d", q$Revision: 1.7 $ =~ /: (\d+)\.(\d+)/;
11              
12             sub new {
13 1     1 1 348 my ($class, $options) = @_;
14 1         4 my $self = bless {}, $class;
15 1         3 my $marshalled = $self->_marshall_options($options);
16 1 50       12 $self->{engine} = new Template($marshalled) or die($Template::ERROR);
17 1         53992 return $self;
18             }
19              
20             sub native_object {
21 0     0 1 0 my $self = shift;
22 0         0 return $self->{engine};
23             }
24              
25             sub process_to_string {
26 1     1 1 462 my ($self, $data, $ref_buffer) = @_;
27 1         3 $$ref_buffer = '';
28 1         6 TRACE("Input", $self->{input});
29 1 50       7 $self->{engine}->process($self->{input}, $data, $ref_buffer) or die($self->{engine}->error());
30             }
31              
32             sub process_to_filehandle {
33 0     0 1 0 my ($self, $data, $fh) = @_;
34 0         0 TRACE("Input", $self->{input});
35 0 0       0 $self->{engine}->process($self->{input}, $data, $fh) or die($self->{engine}->error());
36             }
37              
38             sub process_to_file {
39 0     0 1 0 my ($self, $data, $filepath) = @_;
40 0         0 TRACE("Input", $self->{input});
41 0 0       0 $self->{engine}->process($self->{input}, $data, $filepath) or die($self->{engine}->error());
42             }
43              
44             sub process_to_sub {
45 0     0 1 0 my ($self, $data, $coderef) = @_;
46 0 0       0 return $self->{engine}->process($self->{input}, $data, $coderef) or die($self->{engine}->error());
47             }
48              
49             #
50             # This marshalls the Any::Template ctor options into the form required for Template-Toolkit
51             #
52             sub _marshall_options {
53 1     1   1 my $self = shift;
54 1         2 my $at_options = shift;
55 1         3 my %tt_options = %{$at_options->{Options}};
  1         4  
56 1 50       4 if(exists $at_options->{String}) {
    0          
    0          
57 1         7 $self->{input} = \$at_options->{String};
58             }
59             elsif(exists $at_options->{Filehandle}) {
60 0         0 $self->{input} = $at_options->{Filehandle};
61             }
62             elsif(exists $at_options->{Filename}) {
63 0         0 $self->{input} = $at_options->{Filename};
64             }
65             else {
66 0         0 die("No Filename, Filehandle or String");
67             }
68 1         2 return \%tt_options;
69             }
70              
71             #Log::Trace stubs
72 1     1 0 3 sub TRACE{}
73 0     0 0   sub DUMP{}
74              
75             1;
76              
77              
78             =head1 NAME
79              
80             Any::Template::Backend::TemplateToolkit - Any::Template backend for Template Toolkit
81              
82             =head1 SYNOPSIS
83              
84             use Any::Template;
85             my $template = new Any::Template(
86             Backend => 'TemplateToolkit',
87             Options => {
88             'POST_CHOMP' => 1, #Template ctor options
89             },
90             File => 'page.tmpl'
91             );
92             my $output = $template->process($data);
93              
94             =head1 DESCRIPTION
95              
96             All input and output methods are implemented using Template Toolkit's native features so they should
97             all be pretty efficient.
98              
99             =head1 SEE ALSO
100              
101             L, L, L