Apache-Request-I18N
view release on metacpan or search on metacpan
package Apache::Request::I18N;
use 5.008;
use strict;
use warnings;
use Apache::Request 0.32;
use Carp;
use Encode qw(decode_utf8 encode_utf8);
our @ISA = 'Apache::Request';
our $VERSION = '0.08';
=head1 NAME
Apache::Request::I18N - Internationalization extension to Apache::Request
#
# TODO: Should we bother to re-encode?
return $self->SUPER::param(@_) if $self->encode_parms;
# param() is identical to parms() in scalar context
return $self->parms if !wantarray && !@_;
# Encode everything back to UTF-8. (The second argument may be an
# array reference.)
my @args = map ref($_)
? [ map encode_utf8($_), @$_ ]
: encode_utf8($_),
@_;
# param() is context-sensitive
if (wantarray) {
return map decode_utf8($_), $self->SUPER::param(@args);
} else {
return decode_utf8 scalar $self->SUPER::param(@args);
}
}
sub parms {
my $self = shift;
# parms() in list context returns an Apache::Table, which cannot
# handle wide characters, so we croak if ENCODE_PARMS is empty.
# (Maybe we could subclass Apache::Table and perform some magic?)
sub encode_parms { $_[0]->{_encode_parms} }
=back
=cut
# Our core decode/encode functions. If encode_parms is empty, we still need
# to encode to UTF-8, since libapreq won't handle wide characters.
sub _decode { Encode::decode($_[2] || $_[0]->decode_parms, $_[1]) }
sub _encode { Encode::encode($_[0]->encode_parms || 'utf8', $_[1]) }
# Handling of Content-Disposition parameter values (form field names and
# filenames in multipart/form-data) is a bit tricky. RFC 2047 clearly states
# (section 5) that parameter values cannot contain any encoded-word; however,
# RFC 1867 actually recommended using encoded-word for such purposes, and
# there are reports of browsers doing just that. So, we support it anyway.
#
# Many browsers don't even bother encoding parameter values, and send them in
# whatever encoding is used for the contents of each HTTP entity. So, if we
# can't find any encoded-word, we try the usual decoding method.
t/dump.d/06_encode.in view on Meta::CPAN
# Basic UTF-8 to UTF-7 conversion
POST /utf8/utf7 HTTP/1.0
Content-Type: application/x-www-form-urlencoded
string=Cha%c3%aene
t/response/TestApReqI18N/dump.pm view on Meta::CPAN
</Location>
<Location /TestApReqI18N__dump/latin1>
PerlSetVar DecodeParms ISO-8859-1
</Location>
<Location /TestApReqI18N__dump/utf7>
PerlSetVar DecodeParms UTF-7
</Location>
<Location /TestApReqI18N__dump/utf8>
PerlSetVar DecodeParms UTF-8
</Location>
<LocationMatch /TestApReqI18N__dump/[^/]+/latin1>
PerlSetVar EncodeParms ISO-8859-1
</LocationMatch>
<LocationMatch /TestApReqI18N__dump/[^/]+/utf7>
PerlSetVar EncodeParms UTF-7
</LocationMatch>
<LocationMatch /TestApReqI18N__dump/[^/]+/utf8>
PerlSetVar EncodeParms UTF-8
</LocationMatch>
( run in 1.075 second using v1.01-cache-2.11-cpan-49f99fa48dc )