From 9731c038acf73a68352fc622cf742b5940a517ef Mon Sep 17 00:00:00 2001 From: franck cuny Date: Thu, 25 Jun 2009 11:01:13 +0200 Subject: add dep --- lib/MooseX/UserAgent/Content.pm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 lib/MooseX/UserAgent/Content.pm (limited to 'lib/MooseX/UserAgent/Content.pm') diff --git a/lib/MooseX/UserAgent/Content.pm b/lib/MooseX/UserAgent/Content.pm new file mode 100644 index 0000000..0cae0df --- /dev/null +++ b/lib/MooseX/UserAgent/Content.pm @@ -0,0 +1,26 @@ +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; +} + +1; -- cgit v1.2.3