| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Eve::HttpResource::Template; |
|
2
|
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
42
|
use parent qw(Eve::HttpResource); |
|
|
8
|
|
|
|
|
15
|
|
|
|
8
|
|
|
|
|
81
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
8
|
|
|
8
|
|
313
|
use utf8; |
|
|
8
|
|
|
|
|
19
|
|
|
|
8
|
|
|
|
|
87
|
|
|
6
|
8
|
|
|
8
|
|
176
|
use strict; |
|
|
8
|
|
|
|
|
16
|
|
|
|
8
|
|
|
|
|
212
|
|
|
7
|
8
|
|
|
8
|
|
9003
|
use autodie; |
|
|
8
|
|
|
|
|
141338
|
|
|
|
8
|
|
|
|
|
54
|
|
|
8
|
8
|
|
|
8
|
|
58697
|
use warnings; |
|
|
8
|
|
|
|
|
42
|
|
|
|
8
|
|
|
|
|
414
|
|
|
9
|
8
|
|
|
8
|
|
8973
|
use open qw(:std :utf8); |
|
|
8
|
|
|
|
|
11376
|
|
|
|
8
|
|
|
|
|
59
|
|
|
10
|
8
|
|
|
8
|
|
11041
|
use charnames qw(:full); |
|
|
8
|
|
|
|
|
127121
|
|
|
|
8
|
|
|
|
|
63
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
8
|
|
|
8
|
|
12966
|
use Encode qw(); |
|
|
8
|
|
|
|
|
98645
|
|
|
|
8
|
|
|
|
|
5255
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
B - a simple HTTP resource with a template. |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use Eve::HttpResource::Template; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Bind it to an URL using the HTTP resource dispatcher. See |
|
23
|
|
|
|
|
|
|
# B class. |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $resource = Eve::HttpResource::Template->new( |
|
26
|
|
|
|
|
|
|
response => $response, |
|
27
|
|
|
|
|
|
|
session_constructor => $session_constructor, |
|
28
|
|
|
|
|
|
|
dispatcher => $dispatcher, |
|
29
|
|
|
|
|
|
|
template => $template, |
|
30
|
|
|
|
|
|
|
template_file => 'template.html', |
|
31
|
|
|
|
|
|
|
template_var_hash => {'some_var' => 1, 'other_var' => 2}, |
|
32
|
|
|
|
|
|
|
require_auth => 1, |
|
33
|
|
|
|
|
|
|
content_type => 'text/plain', |
|
34
|
|
|
|
|
|
|
charset => 'CP1251', |
|
35
|
|
|
|
|
|
|
text_var_hash => $text_var_hash); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$dispatcher->bind( |
|
38
|
|
|
|
|
|
|
name => 'some_unique_name', |
|
39
|
|
|
|
|
|
|
pattern => '/some_uri', |
|
40
|
|
|
|
|
|
|
base_uri => $some_base_uri, |
|
41
|
|
|
|
|
|
|
resource_constructor => sub { |
|
42
|
|
|
|
|
|
|
return $resource; |
|
43
|
|
|
|
|
|
|
}); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
B is a simple HTTP resource that only |
|
48
|
|
|
|
|
|
|
displays a parsed template. All the templates have the following |
|
49
|
|
|
|
|
|
|
objects available in their scope: |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=over 4 |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item C |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
an instance of the B object for the current user, |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=back |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head3 Constructor arguments |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=over 4 |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item C |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
an HTTP response object, |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item C |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
a reference to a subroutine that returns a session object, |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item C |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
an HTTP dispatcher object, |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item C |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
a template object, |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item C |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
a template file name, |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item C |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
(optional) a hash of variables to be passed to the processed template, |
|
86
|
|
|
|
|
|
|
defaults to an empty hash, |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item C |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
(optional) if a user is not authenticated, throw a |
|
91
|
|
|
|
|
|
|
C, |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item C |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
(optional) response content-type, defaults to C, |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item C |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
(optional) response character set, defaults to C. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=back |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 METHODS |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 B |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub init { |
|
110
|
0
|
|
|
0
|
1
|
|
my ($self, %arg_hash) = @_; |
|
111
|
0
|
|
|
|
|
|
my $arg_hash = Eve::Support::arguments(\%arg_hash, |
|
112
|
|
|
|
|
|
|
my ($template, $template_file), |
|
113
|
|
|
|
|
|
|
my ( |
|
114
|
|
|
|
|
|
|
$template_var_hash, |
|
115
|
|
|
|
|
|
|
$require_auth, |
|
116
|
|
|
|
|
|
|
$content_type, |
|
117
|
|
|
|
|
|
|
$charset) = |
|
118
|
|
|
|
|
|
|
({}, \undef, 'text/html', \undef)); |
|
119
|
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
$self->{'_template'} = $template; |
|
121
|
0
|
|
|
|
|
|
$self->{'_template_file'} = $template_file; |
|
122
|
0
|
|
|
|
|
|
$self->{'_template_var_hash'} = $template_var_hash; |
|
123
|
0
|
|
|
|
|
|
$self->{'_require_auth'} = $require_auth; |
|
124
|
0
|
|
|
|
|
|
$self->{'_content_type'} = $content_type; |
|
125
|
0
|
|
|
|
|
|
$self->{'_charset'} = $charset; |
|
126
|
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
$self->SUPER::init(%{$arg_hash}); |
|
|
0
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
return; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub _get { |
|
133
|
0
|
|
|
0
|
|
|
my ($self, %matches_hash) = @_; |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
my $account_id = $self->_session->get_parameter(name => 'account_id'); |
|
136
|
|
|
|
|
|
|
|
|
137
|
0
|
0
|
0
|
|
|
|
if ($self->_require_auth and not defined $account_id) { |
|
138
|
0
|
|
|
|
|
|
Eve::Exception::Http::401Unauthorized->throw(); |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
my $output = $self->_template->process( |
|
142
|
|
|
|
|
|
|
file => $self->_template_file, |
|
143
|
|
|
|
|
|
|
var_hash => { |
|
144
|
0
|
|
|
|
|
|
%{$self->_template_var_hash}, |
|
145
|
|
|
|
|
|
|
'session' => $self->_session, |
|
146
|
|
|
|
|
|
|
'dispatcher' => $self->_dispatcher, |
|
147
|
|
|
|
|
|
|
'request' => $self->_request, |
|
148
|
|
|
|
|
|
|
'matches_hash' => \%matches_hash}); |
|
149
|
|
|
|
|
|
|
|
|
150
|
0
|
0
|
|
|
|
|
if (defined $self->_content_type) { |
|
151
|
0
|
|
|
|
|
|
$self->_response->set_header( |
|
152
|
|
|
|
|
|
|
name => 'Content-type', |
|
153
|
|
|
|
|
|
|
value => $self->_content_type); |
|
154
|
|
|
|
|
|
|
} |
|
155
|
0
|
0
|
|
|
|
|
if (defined $self->_charset) { |
|
156
|
0
|
|
|
|
|
|
$self->_response->set_header( |
|
157
|
|
|
|
|
|
|
name => 'charset', |
|
158
|
|
|
|
|
|
|
value => $self->_charset); |
|
159
|
|
|
|
|
|
|
} |
|
160
|
0
|
|
|
|
|
|
$self->_response->set_body(text => $output); |
|
161
|
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
return; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=over 4 |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item C |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item C |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item C |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=back |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Copyright 2012 Igor Zinovyev. |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
182
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
183
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 AUTHOR |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=over 4 |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item L |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=back |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=cut |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
1; |