line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Web::Dispatcher::Simple::Response; |
2
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
143
|
|
3
|
3
|
|
|
3
|
|
19
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
82
|
|
4
|
3
|
|
|
3
|
|
4923
|
use Encode; |
|
3
|
|
|
|
|
37970
|
|
|
3
|
|
|
|
|
409
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
28
|
use base qw/Plack::Response/; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
3103
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub encode_body { |
9
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
10
|
0
|
|
|
|
|
|
my $body = $self->body; |
11
|
0
|
|
|
|
|
|
my $body_type = ref($body); |
12
|
0
|
0
|
|
|
|
|
if ( $body_type eq 'ARRAY' ) { |
13
|
0
|
|
|
|
|
|
$body = join '', @$body; |
14
|
|
|
|
|
|
|
} |
15
|
0
|
0
|
|
|
|
|
my $encoded_body |
16
|
|
|
|
|
|
|
= Encode::is_utf8($body) ? Encode::encode( 'utf8', $body ) : $body; |
17
|
0
|
|
|
|
|
|
$self->body($encoded_body); |
18
|
0
|
|
|
|
|
|
$encoded_body; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub not_found { |
22
|
0
|
|
|
0
|
0
|
|
my ( $self, $error ) = @_; |
23
|
0
|
|
|
|
|
|
$self->status(500); |
24
|
0
|
|
|
|
|
|
$self->content_type('text/html; charset=UTF-8'); |
25
|
0
|
|
0
|
|
|
|
$error ||= 'Not Found'; |
26
|
0
|
|
|
|
|
|
$self->body($error); |
27
|
0
|
|
|
|
|
|
$self->content_length($error); |
28
|
0
|
|
|
|
|
|
$self; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub server_error { |
32
|
0
|
|
|
0
|
0
|
|
my ( $self, $error ) = @_; |
33
|
0
|
|
|
|
|
|
$self->status(500); |
34
|
0
|
|
|
|
|
|
$self->content_type('text/html; charset=UTF-8'); |
35
|
0
|
|
0
|
|
|
|
$error ||= 'Internal Server Error'; |
36
|
0
|
|
|
|
|
|
$self->body($error); |
37
|
0
|
|
|
|
|
|
$self->content_length($error); |
38
|
0
|
|
|
|
|
|
$self; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |