| 1 | package Any::Template::Backend::TemplateToolkit; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 1 | ▶ | use Template; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | 1 | ▶ | use Any::Template::Backend; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | 1 | ▶ | use vars qw(@ISA); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 7 | 1 | @ISA = qw(Any::Template::Backend); | |||||||||||||||||
| 8 | |||||||||||||||||||
| 9 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 10 | 1 | $VERSION = sprintf"%d.%03d", q$Revision: 1.7 $ =~ /: (\d+)\.(\d+)/; | |||||||||||||||||
| 11 | |||||||||||||||||||
| 12 | 1 | ▶ | sub new { | ||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||
| 13 | 1 | my ($class, $options) = @_; | |||||||||||||||||
| 14 | 1 | my $self = bless {}, $class; | |||||||||||||||||
| 15 | 1 | my $marshalled = $self->_marshall_options($options); | |||||||||||||||||
| 16 | 1 | ▶ | $self->{engine} = new Template($marshalled) or die($Template::ERROR); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 17 | 1 | return $self; | |||||||||||||||||
| 18 | } | ||||||||||||||||||
| 19 | |||||||||||||||||||
| 20 | 0 | ▶ | sub native_object { | ||||||||||||||||
|
Subroutine
native_object: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 21 | 0 | my $self = shift; | |||||||||||||||||
| 22 | 0 | return $self->{engine}; | |||||||||||||||||
| 23 | } | ||||||||||||||||||
| 24 | |||||||||||||||||||
| 25 | 1 | ▶ | sub process_to_string { | ||||||||||||||||
|
Subroutine
process_to_string: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||
| 26 | 1 | my ($self, $data, $ref_buffer) = @_; | |||||||||||||||||
| 27 | 1 | $$ref_buffer = ''; | |||||||||||||||||
| 28 | 1 | TRACE("Input", $self->{input}); | |||||||||||||||||
| 29 | 1 | ▶ | $self->{engine}->process($self->{input}, $data, $ref_buffer) or die($self->{engine}->error()); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 30 | } | ||||||||||||||||||
| 31 | |||||||||||||||||||
| 32 | 0 | ▶ | sub process_to_filehandle { | ||||||||||||||||
|
Subroutine
process_to_filehandle: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||
| 33 | 0 | my ($self, $data, $fh) = @_; | |||||||||||||||||
| 34 | 0 | TRACE("Input", $self->{input}); | |||||||||||||||||
| 35 | 0 | ▶ | $self->{engine}->process($self->{input}, $data, $fh) or die($self->{engine}->error()); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 36 | } | ||||||||||||||||||
| 37 | |||||||||||||||||||
| 38 | 0 | ▶ | sub process_to_file { | ||||||||||||||||
|
Subroutine
process_to_file: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||
| 39 | 0 | my ($self, $data, $filepath) = @_; | |||||||||||||||||
| 40 | 0 | TRACE("Input", $self->{input}); | |||||||||||||||||
| 41 | 0 | ▶ | $self->{engine}->process($self->{input}, $data, $filepath) or die($self->{engine}->error()); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 42 | } | ||||||||||||||||||
| 43 | |||||||||||||||||||
| 44 | 0 | ▶ | sub process_to_sub { | ||||||||||||||||
|
Subroutine
process_to_sub: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 45 | 0 | my ($self, $data, $coderef) = @_; | |||||||||||||||||
| 46 | 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 | 1 | ▶ | sub _marshall_options { | ||||||||||||||||
|
Subroutine
_marshall_options: called CC=4 SCAR=17.9
| |||||||||||||||||||
| 53 | 1 | my $self = shift; | |||||||||||||||||
| 54 | 1 | my $at_options = shift; | |||||||||||||||||
| 55 | 1 | my %tt_options = %{$at_options->{Options}}; | |||||||||||||||||
| 56 | 1 | ▶ | if(exists $at_options->{String}) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 57 | 1 | $self->{input} = \$at_options->{String}; | |||||||||||||||||
| 58 | } | ||||||||||||||||||
| 59 | elsif(exists $at_options->{Filehandle}) { | ||||||||||||||||||
| 60 | 0 | $self->{input} = $at_options->{Filehandle}; | |||||||||||||||||
| 61 | } | ||||||||||||||||||
| 62 | elsif(exists $at_options->{Filename}) { | ||||||||||||||||||
| 63 | 0 | $self->{input} = $at_options->{Filename}; | |||||||||||||||||
| 64 | } | ||||||||||||||||||
| 65 | else { | ||||||||||||||||||
| 66 | 0 | die("No Filename, Filehandle or String"); | |||||||||||||||||
| 67 | } | ||||||||||||||||||
| 68 | 1 | return \%tt_options; | |||||||||||||||||
| 69 | } | ||||||||||||||||||
| 70 | |||||||||||||||||||
| 71 | #Log::Trace stubs | ||||||||||||||||||
| 72 | 1 | ▶ | sub TRACE{} | ||||||||||||||||
|
Subroutine
TRACE: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||
| 73 | 0 | ▶ | sub DUMP{} | ||||||||||||||||
|
Subroutine
DUMP: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||
| 74 | |||||||||||||||||||
| 75 | 1 | 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<Any::Template>, L<Any::Template::Backend>, L<Template> | ||||||||||||||||||
| 102 | |||||||||||||||||||
| 103 | =head1 VERSION | ||||||||||||||||||
| 104 | |||||||||||||||||||
| 105 | $Revision: 1.7 $ on $Date: 2005/11/24 22:07:55 $ by $Author: johna $ | ||||||||||||||||||
| 106 | |||||||||||||||||||
| 107 | =head1 AUTHOR | ||||||||||||||||||
| 108 | |||||||||||||||||||
| 109 | John Alden <cpan _at_ bbc _dot_ co _dot_ uk> | ||||||||||||||||||
| 110 | |||||||||||||||||||
| 111 | =head1 COPYRIGHT | ||||||||||||||||||
| 112 | |||||||||||||||||||
| 113 | (c) BBC 2005. This program is free software; you can redistribute it and/or modify it under the GNU GPL. | ||||||||||||||||||
| 114 | |||||||||||||||||||
| 115 | See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt | ||||||||||||||||||
| 116 | |||||||||||||||||||
| 117 | =cut | ||||||||||||||||||