blob: 653b5d97d6817585d81afb998bfabf8cda1f8448 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
package MooseX::UserAgent::Content;
use Encode;
use Moose::Role;
use Compress::Zlib;
use HTML::Encoding 'encoding_from_http_message';
sub get_content {
my ( $self, $res ) = @_;
my $enc = encoding_from_http_message($res);
my $content = $res->content;
if ( $res->content_encoding && $res->content_encoding eq 'gzip' ) {
$content = Compress::Zlib::memGunzip($content);
}
if ( $enc && $enc !~ /utf-8/i ) {
$content = $res->decoded_content( raise_error => 1 );
if ($@) {
$content = Encode::decode( $enc, $content );
}
$content = Encode::encode("utf-8", $content);
}
$content;
}
1;
__END__
=head1 NAME
RTGI::Role::UserAgent::Content
=head1 DESCRIPTION
=head1 BUGS AND LIMITATIONS
=head1 AUTHOR
franck cuny C<< <franck.cuny@rtgi.fr> >>
=head1 LICENCE AND COPYRIGHT
Copyright (c) 2009, RTGI
All rights reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic>.
|