line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ark::Response; |
2
|
61
|
|
|
61
|
|
441
|
use Mouse; |
|
61
|
|
|
|
|
121
|
|
|
61
|
|
|
|
|
461
|
|
3
|
61
|
|
|
61
|
|
20663
|
use Scalar::Util (); |
|
61
|
|
|
|
|
139
|
|
|
61
|
|
|
|
|
6351
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
extends 'Plack::Response'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has body => ( |
8
|
|
|
|
|
|
|
is => 'rw', |
9
|
|
|
|
|
|
|
predicate => 'has_body', |
10
|
|
|
|
|
|
|
); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has status => ( |
13
|
|
|
|
|
|
|
is => 'rw', |
14
|
|
|
|
|
|
|
default => 200, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has binary => ( |
18
|
|
|
|
|
|
|
is => 'rw', |
19
|
|
|
|
|
|
|
default => 0, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has streaming => ( |
23
|
|
|
|
|
|
|
is => 'rw', |
24
|
|
|
|
|
|
|
isa => 'CodeRef', |
25
|
|
|
|
|
|
|
predicate => 'is_streaming', |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has deferred => ( |
29
|
|
|
|
|
|
|
is => 'rw', |
30
|
|
|
|
|
|
|
isa => 'CodeRef', |
31
|
|
|
|
|
|
|
predicate => 'is_deferred', |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has deferred_response => ( |
35
|
|
|
|
|
|
|
is => 'rw', |
36
|
|
|
|
|
|
|
isa => 'CodeRef', |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
61
|
|
|
61
|
|
422
|
no Mouse; |
|
61
|
|
|
|
|
131
|
|
|
61
|
|
|
|
|
403
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub finalize { |
42
|
281
|
|
|
281
|
1
|
579
|
my $self = shift; |
43
|
|
|
|
|
|
|
|
44
|
281
|
50
|
33
|
|
|
1904
|
if (!$self->is_deferred && !$self->is_streaming) { |
45
|
281
|
|
|
|
|
1971
|
return $self->SUPER::finalize; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $headers = $self->headers->clone; |
49
|
0
|
|
|
|
|
|
$self->_finalize_cookies($headers); |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
if ($self->is_deferred) { |
52
|
0
|
0
|
|
|
|
|
if (my $cb = $self->deferred_response) { |
53
|
0
|
|
|
|
|
|
my $body = $self->_body; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $response = [ |
56
|
|
|
|
|
|
|
$self->status, |
57
|
|
|
|
|
|
|
+[ |
58
|
|
|
|
|
|
|
map { |
59
|
0
|
|
|
|
|
|
my $k = $_; |
|
0
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
map { ( $k => $_ ) } $headers->header($_); |
|
0
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} $headers->header_field_names |
62
|
|
|
|
|
|
|
], |
63
|
|
|
|
|
|
|
$body, |
64
|
|
|
|
|
|
|
]; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$cb->($response); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
else { |
69
|
|
|
|
|
|
|
my $r = sub { |
70
|
0
|
|
|
0
|
|
|
my $respond = shift; |
71
|
0
|
|
|
|
|
|
$self->deferred_response($respond); |
72
|
0
|
|
|
|
|
|
$self->deferred->($respond); |
73
|
0
|
|
|
|
|
|
}; |
74
|
0
|
|
|
|
|
|
Scalar::Util::weaken($self); |
75
|
0
|
|
|
|
|
|
return $r; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
else { # streaming |
79
|
|
|
|
|
|
|
my $response = [ |
80
|
|
|
|
|
|
|
$self->status, |
81
|
|
|
|
|
|
|
+[ |
82
|
|
|
|
|
|
|
map { |
83
|
0
|
|
|
|
|
|
my $k = $_; |
|
0
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# steal from Plack::Response |
85
|
|
|
|
|
|
|
map { |
86
|
0
|
|
|
|
|
|
my $v = $_; |
|
0
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
$v =~ s/\015\012[\040|\011]+/chr(32)/ge; # replace LWS with a single SP |
|
0
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$v =~ s/\015|\012//g; # remove CR and LF since the char is invalid here |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
( $k => $v ) |
91
|
|
|
|
|
|
|
} $headers->header($_); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} $headers->header_field_names |
94
|
|
|
|
|
|
|
], |
95
|
|
|
|
|
|
|
]; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
return sub { |
98
|
0
|
|
|
0
|
|
|
my $respond = shift; |
99
|
0
|
|
|
|
|
|
my $writer = $respond->($response); |
100
|
0
|
|
|
|
|
|
$self->streaming->($writer); |
101
|
0
|
|
|
|
|
|
}; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |