« blib/lib/Any/Template/Backend/Text/MicroMason.pm
↑ Summary
blib/lib/Any/Template/Backend/Text/Template.pm »
| 1 | package Any::Template::Backend::HTML::Template; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use HTML::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.7 $ =~ /: (\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 HTML::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 | my $engine = $self->{engine}; | ||
| 30 | $engine->clear_params(); | ||
| 31 | $engine->param($data); | ||
| 32 | $$ref_buffer = $engine->output(); | ||
| 33 | } | ||
| 34 | |||
| 35 | sub 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 | # | ||
| 46 | sub _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 | ||
| 56 | sub TRACE {} | ||
| 57 | sub DUMP{} | ||
| 58 | |||
| 59 | 1; | ||
| 60 | |||
| 61 | =head1 NAME | ||
| 62 | |||
| 63 | Any::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 | |||
| 79 | All template input methods are provided natively by HTML::Template. | ||
| 80 | Output to a coderef uses the default implementation of buffering all the output in a string and passing this to a coderef, | ||
| 81 | so beware of the memory consumption if the output is large. Output to a string and filehandle all use HTML::Template's native implementation. | ||
| 82 | Output to a file uses the default wrapper around output to a fileshandle. | ||
| 83 | |||
| 84 | =head1 SEE ALSO | ||
| 85 | |||
| 86 | L<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 | |||
| 94 | John 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 | |||
| 100 | See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt | ||
| 101 | |||
| 102 | =cut |