| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
=head1 NAME |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
OpenFrame::WebApp::Template - abstract class for template processing wrappers |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# abstract class - does nothing on its own |
|
8
|
|
|
|
|
|
|
use OpenFrame::WebApp::Template::SomeClass; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $tmpl = new OpenFrame::WebApp::Template::SomeClass() |
|
11
|
|
|
|
|
|
|
->file( $local_path ) |
|
12
|
|
|
|
|
|
|
->template_vars( { some => vars } ); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
try { |
|
15
|
|
|
|
|
|
|
$ofResponse = $tmpl->process; |
|
16
|
|
|
|
|
|
|
} catch OpenFrame::WebApp::Template::Error with { |
|
17
|
|
|
|
|
|
|
my $e = shift; |
|
18
|
|
|
|
|
|
|
print $e->flag, $e->message; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
package OpenFrame::WebApp::Template; |
|
24
|
|
|
|
|
|
|
|
|
25
|
4
|
|
|
4
|
|
57083
|
use strict; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
139
|
|
|
26
|
4
|
|
|
4
|
|
22
|
use warnings::register; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
493
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
4
|
|
|
4
|
|
2253
|
use Error qw( :try ); |
|
|
4
|
|
|
|
|
16129
|
|
|
|
4
|
|
|
|
|
22
|
|
|
29
|
4
|
|
|
4
|
|
4390
|
use OpenFrame::Response; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use OpenFrame::WebApp::Error::Abstract; |
|
31
|
|
|
|
|
|
|
use OpenFrame::WebApp::Template::Error; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use base qw ( OpenFrame::Object ); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
our $VERSION = (split(/ /, '$Revision: 1.13 $'))[1]; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
our $TYPES = { |
|
38
|
|
|
|
|
|
|
tt2 => 'OpenFrame::WebApp::Template::TT2', |
|
39
|
|
|
|
|
|
|
petal => 'OpenFrame::WebApp::Template::Petal', |
|
40
|
|
|
|
|
|
|
}; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
## get hash of known template types |
|
43
|
|
|
|
|
|
|
sub types { |
|
44
|
|
|
|
|
|
|
my $self = shift; |
|
45
|
|
|
|
|
|
|
if (@_) { |
|
46
|
|
|
|
|
|
|
$TYPES = shift; |
|
47
|
|
|
|
|
|
|
return $self; |
|
48
|
|
|
|
|
|
|
} else { |
|
49
|
|
|
|
|
|
|
return $TYPES; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
## object init |
|
54
|
|
|
|
|
|
|
sub init { |
|
55
|
|
|
|
|
|
|
my $self = shift; |
|
56
|
|
|
|
|
|
|
$self->template_vars( {} ); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
## template processor |
|
60
|
|
|
|
|
|
|
sub processor { |
|
61
|
|
|
|
|
|
|
my $self = shift; |
|
62
|
|
|
|
|
|
|
if (@_) { |
|
63
|
|
|
|
|
|
|
$self->{template_processor} = shift; |
|
64
|
|
|
|
|
|
|
return $self; |
|
65
|
|
|
|
|
|
|
} else { |
|
66
|
|
|
|
|
|
|
return $self->{template_processor}; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
## override this method |
|
71
|
|
|
|
|
|
|
sub default_processor { |
|
72
|
|
|
|
|
|
|
my $self = shift; |
|
73
|
|
|
|
|
|
|
throw OpenFrame::WebApp::Error::Abstract( class => ref($self) ); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
## local path to the template file |
|
77
|
|
|
|
|
|
|
sub file { |
|
78
|
|
|
|
|
|
|
my $self = shift; |
|
79
|
|
|
|
|
|
|
if (@_) { |
|
80
|
|
|
|
|
|
|
$self->{template_file} = shift; |
|
81
|
|
|
|
|
|
|
return $self; |
|
82
|
|
|
|
|
|
|
} else { |
|
83
|
|
|
|
|
|
|
return $self->{template_file}; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
## hash of template processing vars |
|
88
|
|
|
|
|
|
|
sub template_vars { |
|
89
|
|
|
|
|
|
|
my $self = shift; |
|
90
|
|
|
|
|
|
|
if (@_) { |
|
91
|
|
|
|
|
|
|
$self->{template_vars} = shift; |
|
92
|
|
|
|
|
|
|
return $self; |
|
93
|
|
|
|
|
|
|
} else { |
|
94
|
|
|
|
|
|
|
return $self->{template_vars}; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
## process the template file |
|
99
|
|
|
|
|
|
|
sub process { |
|
100
|
|
|
|
|
|
|
my $self = shift; |
|
101
|
|
|
|
|
|
|
my $file = $self->file; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
return ($self->file_not_found) unless (-e $file); |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$self->processor( $self->default_processor ) unless $self->processor; |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $output = $self->process_template; |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my $response = new OpenFrame::Response; |
|
110
|
|
|
|
|
|
|
$response->code( ofOK ); |
|
111
|
|
|
|
|
|
|
$response->message( $output ); |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
return $response; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
## override this method |
|
117
|
|
|
|
|
|
|
sub process_template { |
|
118
|
|
|
|
|
|
|
my $self = shift; |
|
119
|
|
|
|
|
|
|
throw OpenFrame::WebApp::Error::Abstract( class => ref($self) ); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
## what to do when template file is not found |
|
123
|
|
|
|
|
|
|
sub file_not_found { |
|
124
|
|
|
|
|
|
|
my $self = shift; |
|
125
|
|
|
|
|
|
|
throw OpenFrame::WebApp::Template::Error( |
|
126
|
|
|
|
|
|
|
flag => eTemplateNotFound, |
|
127
|
|
|
|
|
|
|
template => $self->file, |
|
128
|
|
|
|
|
|
|
); |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |