stas 2003/09/22 16:53:16
Added: t/modperl print_utf8_2.t t/response/TestModperl print_utf8_2.pm Log: similar to TestModperl::print_utf8, testing utf8 print, but via $r->print which just works Revision Changes Path 1.1 modperl-2.0/t/modperl/print_utf8_2.t Index: print_utf8_2.t =================================================================== use strict; use warnings FATAL => 'all'; use Apache::Test; use Apache::TestRequest; use Apache::TestUtil; use Config; # utf encode/decode was added only in 5.8.0 # perlio is needed only for the client side, because it calls binmode(STDOUT, ':utf8'); plan tests => 1, have_min_perl_version(5.008); my $location = "/TestModperl__print_utf8_2"; my $expected = "\$r->print() just works \x{263A}"; my $res = GET $location; my $received = $res->content; # response body includes wide-chars, but perl doesn't know about it utf8::decode($received) if ($res->header('Content-Type')||'') =~ /utf-8/i; if ($Config{useperlio}) { # needed for debugging print out of utf8 strings # but works only if perl is built w/ perlio binmode(STDOUT, ':utf8'); ok t_cmp($expected, $received, 'UTF8 response via $r->print'); } else { ok $expected eq $received; } 1.1 modperl-2.0/t/response/TestModperl/print_utf8_2.pm Index: print_utf8_2.pm =================================================================== package TestModperl::print_utf8_2; # testing the utf8-encoded response via direct $r->print, which does the # right thing without any extra provisions. # see print_utf8.pm for tied STDOUT/perlio STDOUT, which requires extra work use strict; use warnings FATAL => 'all'; use Apache::RequestIO (); use Apache::RequestRec (); use Apache::Const -compile => 'OK'; sub handler { my $r = shift; $r->content_type('text/plain; charset=UTF-8'); # must be non-$r->print(), so we go through the tied STDOUT # \x{263A} == :-) $r->print("\$r->print() just works \x{263A}"); Apache::OK; } 1; __DATA__ SetHandler modperl