| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Catalyst::View::HTML::Template; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
928
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
44
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use base 'Catalyst::View'; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
590
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
236882
|
use HTML::Template; |
|
|
1
|
|
|
|
|
60259
|
|
|
|
1
|
|
|
|
|
2467
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Catalyst::View::HTML::Template - HTML::Template View Class |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# use the helper |
|
17
|
|
|
|
|
|
|
create.pl view HTML::Template HTML::Template |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# lib/MyApp/View/HTML/Template.pm |
|
20
|
|
|
|
|
|
|
package MyApp::View::HTML::Template; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use base 'Catalyst::View::HTML::Template'; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
__PACKAGE__->config( |
|
25
|
|
|
|
|
|
|
die_on_bad_params => 0, |
|
26
|
|
|
|
|
|
|
file_cache => 1, |
|
27
|
|
|
|
|
|
|
file_cache_dir => '/tmp/cache' |
|
28
|
|
|
|
|
|
|
); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
1; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Meanwhile, maybe in an 'end' action |
|
33
|
|
|
|
|
|
|
$c->forward('MyApp::View::HTML::Template'); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
This is the C<HTML::Template> view class. Your subclass should inherit from this |
|
39
|
|
|
|
|
|
|
class. |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 METHODS |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=over 4 |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item process |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Renders the template specified in C<< $c->stash->{template} >> or C<< |
|
48
|
|
|
|
|
|
|
$c->request->match >>. |
|
49
|
|
|
|
|
|
|
Template params are set up from the contents of C<< $c->stash >>, |
|
50
|
|
|
|
|
|
|
augmented with C<base> set to C<< $c->req->base >> and C<name> to |
|
51
|
|
|
|
|
|
|
C<< $c->config->{name} >>. Output is stored in C<< $c->response->body >>. |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub process { |
|
56
|
0
|
|
|
0
|
1
|
|
my ( $self, $c ) = @_; |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
|
0
|
|
|
|
my $filename = $c->stash->{template} || $c->req->match; |
|
59
|
0
|
|
|
|
|
|
my $body = $self->render($c,$filename); |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
unless ( $c->response->headers->content_type ) { |
|
62
|
0
|
|
|
|
|
|
$c->res->headers->content_type('text/html; charset=utf-8'); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$c->response->body($body); |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return 1; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item render |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Renders the given template and returns output. Template params are set up |
|
73
|
|
|
|
|
|
|
either from the contents of C<%$args> if $args is a hashref, or C<< $c->stash >>, |
|
74
|
|
|
|
|
|
|
augmented with C<base> set to C<< $c->req->base >> and C<name> to |
|
75
|
|
|
|
|
|
|
C<< $c->config->{name} >>. |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub render { |
|
80
|
0
|
|
|
0
|
1
|
|
my ( $self, $c, $filename, $args ) = @_; |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
unless ($filename) { |
|
83
|
0
|
0
|
|
|
|
|
$c->log->debug('No template specified for rendering') if $c->debug; |
|
84
|
0
|
|
|
|
|
|
return 0; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my %options = ( |
|
88
|
|
|
|
|
|
|
cache => 1, |
|
89
|
|
|
|
|
|
|
filename => $filename, |
|
90
|
|
|
|
|
|
|
path => [ $c->path_to('root'), $c->path_to('root','base') ], |
|
91
|
|
|
|
|
|
|
); |
|
92
|
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
|
$c->log->debug(qq/Rendering template "$filename"/) if $c->debug; |
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $template = HTML::Template->new( %options, %{ $self } ); |
|
|
0
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
|
97
|
0
|
0
|
0
|
|
|
|
my $template_params = $args && ref($args) eq 'HASH' ? $args : $c->stash; |
|
98
|
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
$template->param( |
|
100
|
|
|
|
|
|
|
base => $c->req->base, |
|
101
|
|
|
|
|
|
|
name => $c->config->{name}, |
|
102
|
|
|
|
|
|
|
%$template_params |
|
103
|
|
|
|
|
|
|
); |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $output; |
|
106
|
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
eval { $output = $template->output }; |
|
|
0
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
if ( my $error = $@ ) { |
|
110
|
0
|
|
|
|
|
|
chomp $error; |
|
111
|
0
|
|
|
|
|
|
$error = qq/Couldn't render template "$filename". Error: "$error"/; |
|
112
|
0
|
|
|
|
|
|
$c->log->error($error); |
|
113
|
0
|
|
|
|
|
|
$c->error($error); |
|
114
|
0
|
|
|
|
|
|
return 0; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
0
|
|
|
|
|
|
return $output; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item config |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This allows your view subclass to pass additional settings to the |
|
122
|
|
|
|
|
|
|
HTML::Template config hash. |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=back |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
L<HTML::Template>, L<Catalyst>, L<Catalyst::Base>. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 AUTHOR |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Christian Hansen, C<ch@ngmedia.com> |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it |
|
137
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |