line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Egg::View::HT; |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# $Id: HT.pm 337 2008-05-14 12:30:09Z lushe $ |
6
|
|
|
|
|
|
|
# |
7
|
1
|
|
|
1
|
|
343
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
97
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION= '3.00'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _setup { |
13
|
0
|
|
|
0
|
|
|
my($class, $e)= @_; |
14
|
0
|
|
0
|
|
|
|
"$e->{namespace}::View::HT"->config->{path} ||= $e->config->{template_path}; |
15
|
0
|
|
|
|
|
|
$class->next::method($e); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package Egg::View::HT::handler; |
19
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
20
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
29
|
|
|
1
|
|
|
|
|
24
|
|
21
|
1
|
|
|
1
|
|
5743
|
use HTML::Template; |
|
1
|
|
|
|
|
18561
|
|
|
1
|
|
|
|
|
30
|
|
22
|
1
|
|
|
1
|
|
561
|
use Egg::View::Template::GlobalParam; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
23
|
1
|
|
|
1
|
|
25
|
use base qw/ Egg::View /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
131
|
|
24
|
1
|
|
|
1
|
|
5
|
use Carp qw/ croak /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
584
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new { |
27
|
0
|
|
|
0
|
|
|
my $view= shift->SUPER::new(@_); |
28
|
0
|
|
|
|
|
|
$view->params({ Egg::View::Template::GlobalParam::set($view->e) }); |
29
|
0
|
|
|
|
|
|
$view->{filter} = []; |
30
|
0
|
|
|
|
|
|
$view->{associate}= [$view, $view->e->request]; |
31
|
0
|
|
|
|
|
|
$view; |
32
|
|
|
|
|
|
|
} |
33
|
0
|
|
|
0
|
|
|
sub push_filter { shift->_push('filter', @_) } |
34
|
0
|
|
|
0
|
|
|
sub push_associate { shift->_push('associate', @_) } |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub render { |
37
|
0
|
|
|
0
|
|
|
my $option= shift->_create_option(@_); |
38
|
0
|
|
|
|
|
|
my $tmpl= HTML::Template->new(%$option); |
39
|
0
|
|
|
|
|
|
my $body= $tmpl->output; |
40
|
0
|
|
|
|
|
|
return \$body; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
sub output { |
43
|
0
|
|
|
0
|
|
|
my $view= shift; |
44
|
0
|
|
0
|
|
|
|
my $tmpl= shift || $view->template || croak q{ I want template. }; |
45
|
0
|
|
|
|
|
|
$view->e->response->body( $view->render($tmpl, @_) ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
sub _push { |
48
|
0
|
|
|
0
|
|
|
my($view, $type)= splice @_, 0, 2; |
49
|
0
|
0
|
|
|
|
|
if (@_ > 1) { |
50
|
0
|
|
|
|
|
|
splice @{$view->{$type}}, scalar(@{$view->{$type}}), 0, @_; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
} else { |
52
|
0
|
|
|
|
|
|
push @{$view->{$type}}, $_[0]; |
|
0
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
sub _create_option { |
56
|
0
|
|
|
0
|
|
|
my $view= shift; |
57
|
0
|
|
0
|
|
|
|
my $tmpl= shift || return (undef); |
58
|
0
|
0
|
|
|
|
|
my $args= $_[0] ? ($_[1] ? {@_}: $_[0]): {}; |
|
|
0
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $params= $view->params; |
60
|
0
|
|
|
|
|
|
while (my($key, $value)= each %{$view->e->stash}) { |
|
0
|
|
|
|
|
|
|
61
|
0
|
|
0
|
|
|
|
$params->{$key} ||= $value; |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
my $class = $view->e->namespace. "::View::HT"; |
64
|
0
|
|
|
|
|
|
my %option= ( %{$class->config}, %$args ); |
|
0
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
if (ref($tmpl) eq 'SCALAR') { |
|
|
0
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$option{scalarref}= $tmpl; |
67
|
0
|
|
|
|
|
|
$option{cache} = 0; |
68
|
|
|
|
|
|
|
} elsif (ref($tmpl) eq 'ARRAY') { |
69
|
0
|
|
|
|
|
|
$option{arrayref}= $tmpl; |
70
|
|
|
|
|
|
|
} else { |
71
|
0
|
|
|
|
|
|
$option{filename}= $tmpl; |
72
|
|
|
|
|
|
|
} |
73
|
0
|
|
|
|
|
|
$option{associate}= $view->{associate}; |
74
|
0
|
0
|
|
|
|
|
$option{filter}= $view->{filter} if @{$view->{filter}}; |
|
0
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
\%option; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 NAME |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Egg::View::HT - View for HTML::Template. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SYNOPSIS |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__PACKAGE__->egg_startup( |
89
|
|
|
|
|
|
|
..... |
90
|
|
|
|
|
|
|
... |
91
|
|
|
|
|
|
|
VIEW => [ |
92
|
|
|
|
|
|
|
[ Template => { |
93
|
|
|
|
|
|
|
path => [qw{ <$e.template> <$e.comp> }], |
94
|
|
|
|
|
|
|
cache => 1, |
95
|
|
|
|
|
|
|
global_vars => 1, |
96
|
|
|
|
|
|
|
die_on_bad_params => 0, |
97
|
|
|
|
|
|
|
... etc. |
98
|
|
|
|
|
|
|
} ], |
99
|
|
|
|
|
|
|
], |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# The VIEW object is acquired. |
104
|
|
|
|
|
|
|
my $view= $e->view('HT'); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Associate is set. |
107
|
|
|
|
|
|
|
$view->push_associate( $object ); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Filter is set. |
110
|
|
|
|
|
|
|
$view->push_filter( $filter ); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# It outputs it specifying the template. |
113
|
|
|
|
|
|
|
my $content= $view->render('hoge.tmpl', \%option); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 DESCRIPTION |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
L<HTML::Template> it is a view to drink and to use the template. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Please add HT to the setting of VIEW to make it use. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
VIEW => [ |
122
|
|
|
|
|
|
|
[ HT => { ... HTML::Template option. (HASH) } ], |
123
|
|
|
|
|
|
|
], |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 HANDLER METHODS |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
L<Egg::View> has been succeeded to. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 new |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Constructor. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
L<Egg::View::Template::GlobalParam> is set up. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
The object and $e-E<gt>request of associate are set. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
my $view= $e->view('HT'); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 push_filter ([FILTER]) |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
FILTER is added to filter. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
$view->push_filter(sub { ... filter code }); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 push_associate ([CONTEXT]) |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
CONTEXT is added to associate. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
$view->push_associate($context); |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 render ([TEMPLATE_STR], [OPTION]) |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
It is L<HTML::Template> as for the template of TEMPLATE_STR. |
154
|
|
|
|
|
|
|
The result of evaluating is returned by the SCALAR reference. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
OPTION is L<HTML::Template>. It is an option to pass. |
157
|
|
|
|
|
|
|
OPTION overwrites a set value of the configuration. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
my $body= $view->render( 'foo.tt', |
160
|
|
|
|
|
|
|
.......... |
161
|
|
|
|
|
|
|
.... |
162
|
|
|
|
|
|
|
); |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 output ([TEMPLATE_STR], [OPTION]) |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
The result of the render method is set in $e-E<gt>response-E<gt>body. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
When TEMPLATE is omitted, it acquires it from $view-E<gt>template. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
OPTION is passed to the render method as it is. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
$view->output; |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 SEE ALSO |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
L<Egg::Release>, |
177
|
|
|
|
|
|
|
L<Egg::View>, |
178
|
|
|
|
|
|
|
L<Egg::View::Template::GlobalParam>, |
179
|
|
|
|
|
|
|
L<HTML::Template>, |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 AUTHOR |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
190
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
191
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
194
|
|
|
|
|
|
|
|