line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Alice::HTTP::Response; |
2
|
2
|
|
|
2
|
|
15
|
use parent 'Plack::Response'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
18
|
|
3
|
2
|
|
|
2
|
|
5217
|
use Encode; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
883
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub new { |
6
|
0
|
|
|
0
|
1
|
|
my($class, $cb, $rc, $headers, $content) = @_; |
7
|
|
|
|
|
|
|
|
8
|
0
|
0
|
0
|
|
|
|
Carp::croak(q{$cb is required}) |
9
|
|
|
|
|
|
|
unless defined $cb && ref($cb) eq 'CODE'; |
10
|
|
|
|
|
|
|
|
11
|
0
|
|
|
|
|
|
my $self = bless {cb => $cb}, $class; |
12
|
0
|
0
|
|
|
|
|
$self->status($rc) if defined $rc; |
13
|
0
|
0
|
|
|
|
|
$self->headers($headers) if defined $headers; |
14
|
0
|
0
|
|
|
|
|
$self->body($content) if defined $content; |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
$self; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub send { |
20
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
21
|
0
|
|
|
|
|
|
my $res = $self->SUPER::finalize; |
22
|
0
|
|
|
|
|
|
$res->[2] = [map encode("utf8", $_), @{$res->[2]}]; |
|
0
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
return $self->{cb}->($res); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub notfound { |
27
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
28
|
0
|
|
|
|
|
|
return $self->{cb}->([404, ["Content-Type", "text/plain", "Content-Length", 9], ['not found']]); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub ok { |
32
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
33
|
0
|
|
|
|
|
|
return $self->{cb}->([200, ["Content-Type", "text/plain", "Content-Length", 2], ['ok']]); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub writer { |
37
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
38
|
0
|
|
|
|
|
|
my $response = $self->SUPER::finalize; |
39
|
0
|
|
|
|
|
|
return $self->{cb}->([@$response[0,1]]); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |