| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Egg::Plugin::Response::ErrorDocument; |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# $Id: ErrorDocument.pm 337 2008-05-14 12:30:09Z lushe $ |
|
6
|
|
|
|
|
|
|
# |
|
7
|
1
|
|
|
1
|
|
401
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
33
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
389
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION= '3.00'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _setup { |
|
13
|
0
|
|
|
0
|
|
|
my($e)= @_; |
|
14
|
0
|
|
0
|
|
|
|
my $c= $e->config->{plugin_response_errordocument} ||= {}; |
|
15
|
0
|
|
0
|
|
|
|
$c->{view_name} ||= do { |
|
16
|
0
|
|
0
|
|
|
|
my $view= $e->config->{VIEW} || die q{ I want setup 'VIEW' }; |
|
17
|
0
|
0
|
|
|
|
|
ref($view->[0]) eq 'ARRAY' ? $view->[0][0]: $view->[0]; |
|
18
|
|
|
|
|
|
|
}; |
|
19
|
0
|
0
|
|
|
|
|
$e->is_view($c->{view_name}) |
|
20
|
|
|
|
|
|
|
|| die qq{ I want setup VIEW of '$c->{view_name}'. }; |
|
21
|
0
|
0
|
|
|
|
|
$c->{template} || die q{ I want setup 'template'. }; |
|
22
|
0
|
|
0
|
|
|
|
my $ignore= $c->{ignore_status} ||= [qw/ 200 301 302 303 304 307 /]; |
|
23
|
0
|
0
|
|
|
|
|
$ignore= [$ignore] unless ref($ignore) eq 'ARRAY'; |
|
24
|
0
|
0
|
|
|
|
|
if (my $in= $c->{include_ignore_status}) { |
|
25
|
0
|
0
|
|
|
|
|
splice @$ignore, 0, 0, (ref($in) eq 'ARRAY' ? @$in: $in); |
|
26
|
|
|
|
|
|
|
} |
|
27
|
0
|
|
|
|
|
|
$c->{ignore_hash}= { map{ $_=> 1 }@$ignore }; |
|
|
0
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
$e->next::method; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
sub _output { |
|
31
|
0
|
|
|
0
|
|
|
my($e)= @_; |
|
32
|
0
|
|
0
|
|
|
|
my $status= $e->response->status || return $e->next::method; |
|
33
|
0
|
0
|
|
|
|
|
return $e->next::method if $e->request->is_head; |
|
34
|
0
|
|
|
|
|
|
my $c= $e->config->{plugin_response_errordocument}; |
|
35
|
0
|
0
|
|
|
|
|
return $e->next::method if $c->{ignore_hash}{$status}; |
|
36
|
0
|
|
|
|
|
|
my $res= $e->response; |
|
37
|
0
|
0
|
|
|
|
|
$res->no_cache(1) if $c->{no_cache}; |
|
38
|
0
|
0
|
|
|
|
|
$res->status($c->{always_status}) if $c->{always_status}; |
|
39
|
0
|
|
|
|
|
|
$e->page_title( "$status -". $res->status_string ); |
|
40
|
0
|
|
0
|
|
|
|
$res->content_type |
|
41
|
|
|
|
|
|
|
( $c->{content_type} || $e->config->{content_type} || 'text/html' ); |
|
42
|
0
|
|
|
|
|
|
$e->stash->{response_status}= $status; |
|
43
|
0
|
|
|
|
|
|
$e->stash->{"status_$status"}= 1; |
|
44
|
0
|
|
|
|
|
|
$e->view($c->{view_name})->output($c->{template}); |
|
45
|
0
|
|
|
|
|
|
$e->next::method; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 NAME |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Egg::Plugin::Response::ErrorDocument? - Plugin that outputs error document. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
package MyApp; |
|
59
|
|
|
|
|
|
|
use Egg qw/ Response::ErrorDocument /; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__PACKAGE__->egg_startup( |
|
62
|
|
|
|
|
|
|
........... |
|
63
|
|
|
|
|
|
|
... |
|
64
|
|
|
|
|
|
|
plugin_response_errordocument=> { |
|
65
|
|
|
|
|
|
|
view_name => 'mason', |
|
66
|
|
|
|
|
|
|
template => 'error/document.tt', |
|
67
|
|
|
|
|
|
|
ignore_status => [qw/ 200 301 302 303 304 307 /], |
|
68
|
|
|
|
|
|
|
no_cache => 1, |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
}, |
|
71
|
|
|
|
|
|
|
); |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
It is a plugin to output the error screens such as '404 Not Found' and '500 Inta |
|
76
|
|
|
|
|
|
|
rnal Server Error'. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
The template for this plugin is needed for use. |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
The template of the following content is assumed. |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
<html> |
|
83
|
|
|
|
|
|
|
<head> |
|
84
|
|
|
|
|
|
|
<title><% $e->page_title %></title> |
|
85
|
|
|
|
|
|
|
</head> |
|
86
|
|
|
|
|
|
|
<body> |
|
87
|
|
|
|
|
|
|
<h1><% $e->page_title %></h1> |
|
88
|
|
|
|
|
|
|
<div> |
|
89
|
|
|
|
|
|
|
% |
|
90
|
|
|
|
|
|
|
% if ($s->{status_401}) { |
|
91
|
|
|
|
|
|
|
% |
|
92
|
|
|
|
|
|
|
This server could not verify that you are authorized to access the document requested. |
|
93
|
|
|
|
|
|
|
Either you supplied the wrong credentials (e.g., bad password), |
|
94
|
|
|
|
|
|
|
or your browser doesn't understand how to supply the credentials required. |
|
95
|
|
|
|
|
|
|
% |
|
96
|
|
|
|
|
|
|
% } elsif ($s->{status_403}) { |
|
97
|
|
|
|
|
|
|
% |
|
98
|
|
|
|
|
|
|
You don't have permission to access on this server. |
|
99
|
|
|
|
|
|
|
% |
|
100
|
|
|
|
|
|
|
% } elsif ($s->{status_404}) { |
|
101
|
|
|
|
|
|
|
% |
|
102
|
|
|
|
|
|
|
The requested URL <% $e->request->path %> was not found on this server. |
|
103
|
|
|
|
|
|
|
% |
|
104
|
|
|
|
|
|
|
% } else { |
|
105
|
|
|
|
|
|
|
% |
|
106
|
|
|
|
|
|
|
The server encountered an internal error and was unable to complete your request. |
|
107
|
|
|
|
|
|
|
Please contact the server administrator, |
|
108
|
|
|
|
|
|
|
% |
|
109
|
|
|
|
|
|
|
% } |
|
110
|
|
|
|
|
|
|
% |
|
111
|
|
|
|
|
|
|
</div> |
|
112
|
|
|
|
|
|
|
</body> |
|
113
|
|
|
|
|
|
|
</html> |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Such a template is preserved by a suitable name, and it sets it to 'template' of |
|
116
|
|
|
|
|
|
|
the configuration. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
The configuration of this plugin is done by 'plugin_response_errordocument'. |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 view_name => [VIEW_NAME] |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Name of view that error document outputs. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
view_name => 'Mason', |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 template => [TEMPLATE] |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Template used to output error document. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
template => 'document/error.tt', |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Thing that is template treatable by view specified by 'view_name' |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 ignore_status => [STATUS_ARRAY] |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
List of status code in which processing of this plugin is passed. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Default is 200,301,302,303,304,307. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
ignore_status => [qw/ 200 301 302 303 304 307 403 /], |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 include_ignore_status => [STATUS_ARRAY] |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
STATUS_ARRAY is added to 'ignore_status'. |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
include_ignore_status => 403, |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 always_status ([STATUS_CODE]) |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
When the error document is output, the response status is compulsorily made |
|
153
|
|
|
|
|
|
|
STATUS_CODE. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Especially, because it tries to output an original error document by the result |
|
156
|
|
|
|
|
|
|
code in mod_perl, it is necessary to always return the success code by this |
|
157
|
|
|
|
|
|
|
setting. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
always_status => 200, |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
L<Egg::Release>, |
|
164
|
|
|
|
|
|
|
L<Egg::View>, |
|
165
|
|
|
|
|
|
|
L<Egg::View::Mason>, |
|
166
|
|
|
|
|
|
|
L<Egg::View::HT>, |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 AUTHOR |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>. |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
177
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
|
178
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
|
181
|
|
|
|
|
|
|
|