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