line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Web::Machine::Util::BodyEncoding; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
13
|
|
|
13
|
|
449
|
$Web::Machine::Util::BodyEncoding::AUTHORITY = 'cpan:STEVAN'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: Module to handle body encoding |
6
|
|
|
|
|
|
|
$Web::Machine::Util::BodyEncoding::VERSION = '0.15'; |
7
|
13
|
|
|
13
|
|
69
|
use strict; |
|
13
|
|
|
|
|
27
|
|
|
13
|
|
|
|
|
500
|
|
8
|
13
|
|
|
13
|
|
67
|
use warnings; |
|
13
|
|
|
|
|
21
|
|
|
13
|
|
|
|
|
444
|
|
9
|
|
|
|
|
|
|
|
10
|
13
|
|
|
13
|
|
75
|
use Scalar::Util qw/ weaken isweak /; |
|
13
|
|
|
|
|
24
|
|
|
13
|
|
|
|
|
808
|
|
11
|
13
|
|
|
13
|
|
14593
|
use Encode (); |
|
13
|
|
|
|
|
159851
|
|
|
13
|
|
|
|
|
386
|
|
12
|
13
|
|
|
13
|
|
118
|
use Web::Machine::Util qw[ first pair_key pair_value ]; |
|
13
|
|
|
|
|
29
|
|
|
13
|
|
|
|
|
151
|
|
13
|
|
|
|
|
|
|
|
14
|
13
|
|
|
|
|
130
|
use Sub::Exporter -setup => { |
15
|
|
|
|
|
|
|
exports => [qw[ |
16
|
|
|
|
|
|
|
encode_body_if_set |
17
|
|
|
|
|
|
|
encode_body |
18
|
|
|
|
|
|
|
]] |
19
|
13
|
|
|
13
|
|
6982
|
}; |
|
13
|
|
|
|
|
30
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub encode_body_if_set { |
22
|
7
|
|
|
7
|
1
|
16
|
my ($resource, $response) = @_; |
23
|
7
|
100
|
|
|
|
197
|
encode_body( $resource, $response ) if $response->body; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub encode_body { |
27
|
36
|
|
|
36
|
1
|
100
|
my ($resource, $response) = @_; |
28
|
|
|
|
|
|
|
|
29
|
36
|
|
|
|
|
151
|
my $metadata = $resource->request->env->{'web.machine.context'}; |
30
|
36
|
|
|
|
|
192
|
my $chosen_encoding = $metadata->{'Content-Encoding'}; |
31
|
36
|
|
|
|
|
115
|
my $encoder = $resource->encodings_provided->{ $chosen_encoding }; |
32
|
|
|
|
|
|
|
|
33
|
36
|
|
|
|
|
198
|
my $chosen_charset = $metadata->{'Charset'}; |
34
|
36
|
|
|
|
|
58
|
my $charsetter; |
35
|
36
|
100
|
66
|
|
|
168
|
if ( $chosen_charset && $resource->charsets_provided ) { |
36
|
|
|
|
|
|
|
my $match = first { |
37
|
18
|
100
|
66
|
18
|
|
295
|
my $name = $_ && ref $_ ? pair_key($_) : $_; |
38
|
18
|
50
|
|
|
|
98
|
$name && $name eq $chosen_charset; |
39
|
|
|
|
|
|
|
} |
40
|
14
|
|
|
|
|
180
|
@{ $resource->charsets_provided }; |
|
14
|
|
|
|
|
40
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$charsetter |
43
|
|
|
|
|
|
|
= ref $match |
44
|
|
|
|
|
|
|
? pair_value($match) |
45
|
14
|
100
|
|
6
|
|
123
|
: sub { Encode::encode( $match, $_[1] ) }; |
|
6
|
|
|
|
|
35
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
36
|
|
100
|
125
|
|
291
|
$charsetter ||= sub { $_[1] }; |
|
125
|
|
|
|
|
390
|
|
49
|
|
|
|
|
|
|
|
50
|
36
|
|
50
|
|
|
137
|
push @{ $resource->request->env->{'web.machine.content_filters'} ||= [] }, |
51
|
|
|
|
|
|
|
sub { |
52
|
145
|
|
|
145
|
|
2065
|
my $chunk = shift; |
53
|
145
|
100
|
|
|
|
681
|
weaken $resource unless isweak $resource; |
54
|
145
|
100
|
|
|
|
308
|
return unless defined $chunk; |
55
|
139
|
|
|
|
|
282
|
return $resource->$encoder($resource->$charsetter($chunk)); |
56
|
36
|
|
|
|
|
113
|
}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |