| 1 | =head1 NAME | ||||||||||
| 2 | |||||||||||
| 3 | OpenFrame::WebApp::Template::TT2 - a TT2 template processing wrapper | ||||||||||
| 4 | |||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||
| 6 | |||||||||||
| 7 | use OpenFrame::WebApp::Template::TT2; | ||||||||||
| 8 | |||||||||||
| 9 | my $tmpl = new OpenFrame::WebApp::Template::TT2; | ||||||||||
| 10 | $tmpl->file( $local_file_path ) | ||||||||||
| 11 | ->template_vars( { fred => fish } ); | ||||||||||
| 12 | |||||||||||
| 13 | $response = $tmpl->process; | ||||||||||
| 14 | |||||||||||
| 15 | =cut | ||||||||||
| 16 | |||||||||||
| 17 | package OpenFrame::WebApp::Template::TT2; | ||||||||||
| 18 | |||||||||||
| 19 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 1 | ▶ | use warnings::register; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | 1 | ▶ | use Error qw( :try ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 1 | ▶ | use Template; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 1 | ▶ | use OpenFrame::WebApp::Template::Error; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | |||||||||||
| 26 | 1 | ▶ | use base qw( OpenFrame::WebApp::Template ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | |||||||||||
| 28 | 1 | our $VERSION = (split(/ /, '$Revision: 1.10 $'))[1]; | |||||||||
| 29 | |||||||||||
| 30 | 1 | our $TT2 = new Template; | |||||||||
| 31 | |||||||||||
| 32 | ## set/get the TT2 processor | ||||||||||
| 33 | 0 | ▶ | sub tt2 { | ||||||||
|
Subroutine
tt2: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 34 | 0 | my $self = shift; | |||||||||
| 35 | 0 | ▶ | if (@_) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 0 | $TT2 = shift; | |||||||||
| 37 | 0 | return $self; | |||||||||
| 38 | } else { | ||||||||||
| 39 | 0 | return $TT2; | |||||||||
| 40 | } | ||||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | ## use tt2 as default | ||||||||||
| 44 | 0 | ▶ | sub default_processor { | ||||||||
|
Subroutine
default_processor: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 45 | 0 | my $self = shift; | |||||||||
| 46 | 0 | return $self->tt2; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | ## process the template file | ||||||||||
| 50 | 2 | ▶ | sub process_template { | ||||||||
|
Subroutine
process_template: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 51 | 2 | my $self = shift; | |||||||||
| 52 | |||||||||||
| 53 | 2 | my $output; | |||||||||
| 54 | 2 | $self->processor->process( $self->file, $self->template_vars, \$output ); | |||||||||
| 55 | |||||||||||
| 56 | 2 | ▶ | unless ($output) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 1 | throw OpenFrame::WebApp::Template::Error( | |||||||||
| 58 | flag => eTemplateError, | ||||||||||
| 59 | template => $self->file, | ||||||||||
| 60 | message => $self->processor->error->as_string, | ||||||||||
| 61 | ); | ||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 1 | return $output; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | |||||||||||
| 68 | 1 | 1; | |||||||||
| 69 | |||||||||||
| 70 | __END__ | ||||||||||