blib/lib/Any/Template/Backend/Text/Template.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 66 CC 4 SCAR 19.2
CC
4
Cov
0%
_marshall_options
20.0
new
2.0
native_object
2.0
CRAP 6.8
1 package Any::Template::Backend::Text::Template;
2  
3 use strict;
4 use Text::Template;
5 use Any::Template::Backend;
6 use vars qw(@ISA);
7 @ISA = qw(Any::Template::Backend);
8  
9 use vars qw($VERSION);
10 $VERSION = sprintf"%d.%03d", q$Revision: 1.6 $ =~ /: (\d+)\.(\d+)/;
11  
12 sub new {
13 my ($class, $options) = @_;
14 my $marshalled = _marshall_options($options);
15 DUMP($marshalled);
16 my $self = {
17 engine => new Text::Template(%$marshalled)
18 };
19 return bless($self, $class);
20 }
21  
22 sub native_object {
23 my $self = shift;
24 return $self->{engine};
25 }
26  
27 sub process_to_string {
28 my ($self, $data, $ref_buffer) = @_;
29 $$ref_buffer = $self->{engine}->fill_in(HASH => $data);
30 return 1;
31 }
32  
33 sub process_to_filehandle {
34 my ($self, $data, $fh) = @_;
35 $self->{engine}->fill_in(HASH => $data, OUTPUT => $fh);
36 return 1;
37 }
38  
39 #
40 # This marshalls the Any::Template ctor options into the form required for Text::Template
41 #
42 sub _marshall_options {
43 my $at_options = shift;
44 my %tt_options = %{$at_options->{Options}};
45 if(exists $at_options->{String}) {
46 $tt_options{TYPE} = 'STRING';
47 $tt_options{SOURCE} = $at_options->{String};
48 }
49 elsif(exists $at_options->{Filename}) {
50 $tt_options{TYPE} = 'FILE';
51 $tt_options{SOURCE} = $at_options->{Filename};
52 }
53 elsif(exists $at_options->{Filehandle}) {
54 $tt_options{TYPE} = 'FILEHANDLE';
55 $tt_options{SOURCE} = $at_options->{Filehandle};
56 }
57 return \%tt_options;
58 }
59  
60 sub DUMP {}
61 sub TRACE {}
62  
63 1;
64  
65 =head1 NAME
66  
67 Any::Template::Backend::Text::Template - Any::Template backend for Text::Template
68  
69 =head1 SYNOPSIS
70  
71 use Any::Template;
72 my $template = new Any::Template(
73 Backend => 'Text::Template',
74 Options => {
75 UNTAINT => 1 #Pass in Text::Template ctor options
76 },
77 File => 'page.tmpl'
78 );
79 my $output = $template->process($data);
80  
81 =head1 DESCRIPTION
82  
83 All template input methods are provided natively by Text::Template.
84 Output to a coderef uses the default implementation of buffering all the output in a string and passing this to a coderef,
85 so beware of the memory consumption if the output is large. Output to a string and filehandle all use Text::Template's native implementation.
86 Output to a file uses the default wrapper around output to a fileshandle.
87  
88 =head1 SEE ALSO
89  
90 L<Any::Template>, L<Any::Template::Backend>, L<Text::Template>
91  
92 =head1 VERSION
93  
94 $Revision: 1.6 $ on $Date: 2005/05/08 18:25:18 $ by $Author: johna $
95  
96 =head1 AUTHOR
97  
98 John Alden <cpan _at_ bbc _dot_ co _dot_ uk>
99  
100 =head1 COPYRIGHT
101  
102 (c) BBC 2005. This program is free software; you can redistribute it and/or modify it under the GNU GPL.
103  
104 See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt
105  
106 =cut