HTTP-Response-Encoding-0.05/0000755000076500007650000000000010621304103017111 5ustar dankogaidankogai00000000000000HTTP-Response-Encoding-0.05/Changes0000644000076500007650000000152410621304062020412 0ustar dankogaidankogai00000000000000# Revision history for HTTP-Response-Encoding # # $Id: Changes,v 0.5 2007/05/12 09:24:15 dankogai Exp $ # $Revision: 0.5 $ $Date: 2007/05/12 09:24:15 $ ! lib/HTTP/Response/Encoding.pm removed method - decoded_content() because HTTP::Message already has that added methods + charset() -- returns the chraset as-is + encoder() -- encoding object that can be used to decode 0.4 2007/04/20 05:40:37 ! lib/HTTP/Response/Encoding.pm When you require Carp, you should surround arguments with (). Message-Id: <200704200454.l3K4sMHL008173@franz.ak.mind.de> 0.03 2007/04/18 04:50:40 ! MANIFEST + t/t-null.html forgot to add. sorry. 0.02 2007/04/17 13:56:12 ! lib/HTTP/Response/Encoding.pm t/01-file.pm + more descriptive error message for decoded_content(). + test case for failure added 0.01 2007/04/17 13:14:24 + * First version. HTTP-Response-Encoding-0.05/lib/0000755000076500007650000000000010621304103017657 5ustar dankogaidankogai00000000000000HTTP-Response-Encoding-0.05/lib/HTTP/0000755000076500007650000000000010621304103020436 5ustar dankogaidankogai00000000000000HTTP-Response-Encoding-0.05/lib/HTTP/Response/0000755000076500007650000000000010621304103022234 5ustar dankogaidankogai00000000000000HTTP-Response-Encoding-0.05/lib/HTTP/Response/Encoding.pm0000644000076500007650000000737010621304062024333 0ustar dankogaidankogai00000000000000package HTTP::Response::Encoding; use warnings; use strict; our $VERSION = sprintf "%d.%02d", q$Revision: 0.5 $ =~ /(\d+)/g; sub HTTP::Response::charset { my $self = shift; return $self->{__charset} if exists $self->{__charset}; my $content_type = $self->headers->header('Content-Type'); return unless $content_type; $content_type =~ /charset=([A-Za-z0-9_\-]+)/io; $self->{__charset} = $1 || undef; } sub HTTP::Response::encoder { require Encode; my $self = shift; return $self->{__encoder} if exists $self->{__encoder}; my $charset = $self->charset or return; my $enc = Encode::find_encoding($charset); $self->{__encoder} = $enc; } sub HTTP::Response::encoding { my $enc = shift->encoder or return; $enc->name; } =head1 NAME HTTP::Response::Encoding - Adds encoding() to HTTP::Response =head1 VERSION $Id: Encoding.pm,v 0.5 2007/05/12 09:24:15 dankogai Exp $ =cut =head1 SYNOPSIS use LWP::UserAgent; use HTTP::Response::Encoding; my $ua = LWP::UserAgent->new(); my $res = $ua->get("http://www.example.com/"); warn $res->encoding; =head1 EXPORT Nothing. =head1 METHODS This module adds the following methods to L objects. =over 2 =item C<< $res->charset >> Tells the charset I in the C header. Note that the presence of the charset does not guarantee if the response content is decodable via Encode. To normalize this, you should try $res->encoder->mime_name; # with Encode 2.21 or above or use I18N::Charset; # ... mime_charset_name($res->encoding); =item C<< $res->encoder >> Returns the corresponding encoder object or undef if it can't. =item C<< $res->encoding >> Tells the content encoding in the canonical name in L. Returns undef if it can't. For most cases, you are more likely to successfully find encoding after GET than HEAD. HTTP::Response is smart enough to parse But you need the content to let HTTP::Response parse it. If you don't want to retrieve the whole content but interested in its encoding, try something like below; my $req = HTTP::Request->new(GET => $uri); $req->headers->header(Range => "bytes=0-4095"); # just 1st 4k my $res = $ua->request($req); warn $res->encoding; =item C<< $res->decoded_content >> Discontinued since HTTP::Message already has this method. See L for details. =back =head1 INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install =head1 AUTHOR Dan Kogai, C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc HTTP::Response::Encoding You can also look for information at: =over 4 =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * RT: CPAN's request tracker L =item * Search CPAN L =back =head1 ACKNOWLEDGEMENTS GAAS for L. MIYAGAWA for suggestions. =head1 COPYRIGHT & LICENSE Copyright 2007 Dan Kogai, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # End of HTTP::Response::Encoding HTTP-Response-Encoding-0.05/Makefile.PL0000644000076500007650000000114710611126705021077 0ustar dankogaidankogai00000000000000use 5.008001; use strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'HTTP::Response::Encoding', AUTHOR => 'Dan Kogai ', VERSION_FROM => 'lib/HTTP/Response/Encoding.pm', ABSTRACT_FROM => 'lib/HTTP/Response/Encoding.pm', PL_FILES => {}, PREREQ_PM => { 'Encode' => 2.00, 'Test::More' => 0, 'HTTP::Response' => 0, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'HTTP-Response-Encoding-*' }, ); HTTP-Response-Encoding-0.05/MANIFEST0000644000076500007650000000040110611321330020235 0ustar dankogaidankogai00000000000000Changes MANIFEST META.yml # Will be created by "make dist" Makefile.PL README lib/HTTP/Response/Encoding.pm t/00-load.t t/01-file.t t/boilerplate.t t/pod-coverage.t t/pod.t t/t-euc-jp.html t/t-iso-2022-jp.html t/t-null.html t/t-shiftjis.html t/t-utf-8.html HTTP-Response-Encoding-0.05/META.yml0000644000076500007650000000100010621304103020351 0ustar dankogaidankogai00000000000000--- #YAML:1.0 name: HTTP-Response-Encoding version: 0.05 abstract: Adds encoding() to HTTP::Response license: ~ generated_by: ExtUtils::MakeMaker version 6.32 distribution_type: module requires: Encode: 2 HTTP::Response: 0 Test::More: 0 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.2.html version: 1.2 author: - Dan Kogai HTTP-Response-Encoding-0.05/README0000644000076500007650000000605410621304062020002 0ustar dankogaidankogai00000000000000NAME HTTP::Response::Encoding - Adds encoding() to HTTP::Response VERSION $Id: README,v 0.2 2007/05/12 09:24:15 dankogai Exp $ SYNOPSIS use LWP::UserAgent; use HTTP::Response::Encoding; my $ua = LWP::UserAgent->new(); my $res = $ua->get("http://www.example.com/"); warn $res->encoding; EXPORT Nothing. METHODS This module adds the following methods to HTTP::Response objects. "$res->charset" Tells the charset *exactly as appears* in the "Content-Type:" header. Note that the presence of the charset does not guarantee if the response content is decodable via Encode. To normalize this, you should try $res->encoder->mime_name; # with Encode 2.21 or above or use I18N::Charset; # ... mime_charset_name($res->encoding); "$res->encoder" Returns the corresponding encoder object or undef if it can't. "$res->encoding" Tells the content encoding in the canonical name in Encode. Returns undef if it can't. For most cases, you are more likely to successfully find encoding after GET than HEAD. HTTP::Response is smart enough to parse But you need the content to let HTTP::Response parse it. If you don't want to retrieve the whole content but interested in its encoding, try something like below; my $req = HTTP::Request->new(GET => $uri); $req->headers->header(Range => "bytes=0-4095"); # just 1st 4k my $res = $ua->request($req); warn $res->encoding; "$res->decoded_content" Discontinued since HTTP::Message already has this method. See HTTP::Message for details. INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install AUTHOR Dan Kogai, "" BUGS Please report any bugs or feature requests to "bug-http-response-encoding at rt.cpan.org", or through the web interface at . I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. SUPPORT You can find documentation for this module with the perldoc command. perldoc HTTP::Response::Encoding You can also look for information at: * AnnoCPAN: Annotated CPAN documentation * CPAN Ratings * RT: CPAN's request tracker * Search CPAN ACKNOWLEDGEMENTS GAAS for LWP. MIYAGAWA for suggestions. COPYRIGHT & LICENSE Copyright 2007 Dan Kogai, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. HTTP-Response-Encoding-0.05/t/0000755000076500007650000000000010621304103017354 5ustar dankogaidankogai00000000000000HTTP-Response-Encoding-0.05/t/00-load.t0000644000076500007650000000026610611125726020714 0ustar dankogaidankogai00000000000000#!perl -T use Test::More tests => 1; BEGIN { use_ok( 'HTTP::Response::Encoding' ); } diag( "Testing HTTP::Response::Encoding $HTTP::Response::Encoding::VERSION, Perl $], $^X" ); HTTP-Response-Encoding-0.05/t/01-file.t0000644000076500007650000000245010621301651020704 0ustar dankogaidankogai00000000000000#!perl #!perl -T use strict; use warnings; use LWP::UserAgent; use HTTP::Response::Encoding; use File::Spec; use Encode; use Cwd; use URI; use Test::More tests => 13; my $ua = LWP::UserAgent->new; my $cwd = getcwd; #BEGIN{ # package LWP::Protocol; # $^W = 0; #} for my $meth (qw/charset encoder encoding decoded_content/){ can_ok('HTTP::Response', $meth); } my %charset = qw( UTF-8 utf-8-strict; EUC-JP EUC-JP Shift_JIS SHIFT_JIS ISO-2022-JP ISO-2022-JP ); my %filename = qw( UTF-8 t-utf-8.html EUC-JP t-euc-jp.html Shift_JIS t-shiftjis.html ISO-2022-JP t-iso-2022-jp.html ); for my $charset (sort keys %charset){ my $uri = URI->new('file://'); $uri->path(File::Spec->catfile($cwd, "t", $filename{$charset})); my $res; { local $^W = 0; # to quiet LWP::Protocol $res = $ua->get($uri); } die unless $res->is_success; is $res->charset, $charset, "\$res->charset eq '$charset'"; my $canon = find_encoding($charset)->name; is $res->encoding, $canon, "\$res->encoding eq '$canon'"; } my $uri = URI->new('file://'); $uri->path(File::Spec->catfile($cwd, "t", "t-null.html")); my $res = $ua->get($uri); die unless $res->is_success; is $res->encoding, undef, "res->encoding eq undef"; HTTP-Response-Encoding-0.05/t/boilerplate.t0000644000076500007650000000233510611125726022061 0ustar dankogaidankogai00000000000000#!perl -T use strict; use warnings; use Test::More tests => 3; sub not_in_file_ok { my ($filename, %regex) = @_; open my $fh, "<", $filename or die "couldn't open $filename for reading: $!"; my %violated; while (my $line = <$fh>) { while (my ($desc, $regex) = each %regex) { if ($line =~ $regex) { push @{$violated{$desc}||=[]}, $.; } } } if (%violated) { fail("$filename contains boilerplate text"); diag "$_ appears on lines @{$violated{$_}}" for keys %violated; } else { pass("$filename contains no boilerplate text"); } } not_in_file_ok(README => "The README is used..." => qr/The README is used/, "'version information here'" => qr/to provide version information/, ); not_in_file_ok(Changes => "placeholder date/time" => qr(Date/time) ); sub module_boilerplate_ok { my ($module) = @_; not_in_file_ok($module => 'the great new $MODULENAME' => qr/ - The great new /, 'boilerplate description' => qr/Quick summary of what the module/, 'stub function definition' => qr/function[12]/, ); } module_boilerplate_ok('lib/HTTP/Response/Encoding.pm'); HTTP-Response-Encoding-0.05/t/pod-coverage.t0000644000076500007650000000025410611125726022130 0ustar dankogaidankogai00000000000000#!perl -T use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; all_pod_coverage_ok(); HTTP-Response-Encoding-0.05/t/pod.t0000644000076500007650000000021410611125726020333 0ustar dankogaidankogai00000000000000#!perl -T use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok(); HTTP-Response-Encoding-0.05/t/t-euc-jp.html0000644000076500007650000000051310611322012021663 0ustar dankogaidankogai00000000000000 Test

漢字、カタカナ、ひらがなの入ったhtml.

HTTP-Response-Encoding-0.05/t/t-iso-2022-jp.html0000644000076500007650000000052610611322012022270 0ustar dankogaidankogai00000000000000 Test

$B4A;z!"%+%?%+%J!"$R$i$,$J$NF~$C$?(Bhtml.

HTTP-Response-Encoding-0.05/t/t-null.html0000644000076500007650000000042210611322012021451 0ustar dankogaidankogai00000000000000 Test

The quick brown fox jumps over the black lazy dog.

HTTP-Response-Encoding-0.05/t/t-shiftjis.html0000644000076500007650000000051610611322012022326 0ustar dankogaidankogai00000000000000 Test

AJ^JiAhtml.

HTTP-Response-Encoding-0.05/t/t-utf-8.html0000644000076500007650000000053210611322012021444 0ustar dankogaidankogai00000000000000 Test

羲√帥蚊ャchtml.