line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Data::Decode::Encode::HTTP::Response; |
3
|
2
|
|
|
2
|
|
31592
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use namespace::clean -except => qw(meta); |
5
|
|
|
|
|
|
|
use Data::Decode::Exception; |
6
|
|
|
|
|
|
|
use Data::Decode::Util qw(try_decode pick_encoding); |
7
|
|
|
|
|
|
|
use Encode(); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has parser => ( |
10
|
|
|
|
|
|
|
is => 'ro', |
11
|
|
|
|
|
|
|
isa => 'Data::Decode::Encode::HTTP::Response::Parser', |
12
|
|
|
|
|
|
|
lazy_build => 1, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _build_parser { |
16
|
|
|
|
|
|
|
require Data::Decode::Encode::HTTP::Response::Parser; |
17
|
|
|
|
|
|
|
return Data::Decode::Encode::HTTP::Response::Parser->new(); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub decode { |
21
|
|
|
|
|
|
|
my ($self, $decoder, $string, $hints) = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
if (! $hints->{response} || ! eval { $hints->{response}->isa('HTTP::Response') }) { |
24
|
|
|
|
|
|
|
Data::Decode::Exception::Deferred->throw; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
my $res = $hints->{response}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $decoded; |
29
|
|
|
|
|
|
|
{ # Attempt to decode from header information |
30
|
|
|
|
|
|
|
my $from_header; |
31
|
|
|
|
|
|
|
if ( ($res->header('Content-Type') || '') =~ /charset=([\w\-_]+)/i ) { |
32
|
|
|
|
|
|
|
$from_header = $1; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
my $encoding = pick_encoding( $from_header ); |
35
|
|
|
|
|
|
|
$decoded = try_decode($encoding, $string); |
36
|
|
|
|
|
|
|
return $decoded if $decoded; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
{ # Attempt to decode from meta information |
40
|
|
|
|
|
|
|
my $p = $self->parser(); |
41
|
|
|
|
|
|
|
my $encoding = pick_encoding( |
42
|
|
|
|
|
|
|
$p->extract_encodings( $res->content ) |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
$decoded = try_decode($encoding, $string); |
45
|
|
|
|
|
|
|
return $decoded if $decoded; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Data::Decode::Exception::Deferred->throw; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 NAME |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Data::Decode::Encode::HTTP::Response - Get Encoding Hints From HTTP::Response |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 METHODS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 new |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 decode |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 parser |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |