[Catalyst] Catalyst-plugin-prototype supports UTF8?
Jonathan Rockway
jon at jrock.us
Wed Nov 1 19:31:19 GMT 2006
> Encode::_utf8_on().
Don't touch the UTF8 flag. Do this:
$data = source_of_utf8_octets();
utf8::decode($data);
You can also get utf8 data like:
package foo;
use utf8;
my $data = "任天堂"; # 3 characters, no octets; don't call decode()
or
open(my $fh, '<:utf8', $filename)
my $data = do { local $/; <$fh> };
Playing with perl's internals isn't necessary, even though a few modules
do it any way. The key is to make sure you get everything. Try
encoding::warnings to help you. (I tried and failed a number of times
with Encode::_utf8_on()... weird crashes, double-encoding, etc. Just
use decode(); I do and everything works great. You don't even need
View::TT::ForceUTF8 anymore, since you're doing everything correctly.)
If you are using utf8, you'll want C::P::Unicode also. This will
encode() your output, so perl characters are transformed to utf8 octets.
Otherwise you'll get errors about wide-characters in print at
Catalyst::Engine line something. (This applies everywhere -- if you
pass characters where octets are expected, you'll receive a warning or
error from the interperter. In that case, encode the characters to
octets. Digest::MD5, for one, requires this because MD5 assumes 8-bit
characters.)
Regards,
Jonathan Rockway
--
package JAPH;use Catalyst qw/-Debug/;($;=JAPH)->config(name => do {
$,.=reverse qw[Jonathan tsu rehton lre rekca Rockway][$_].[split //,
";$;"]->[$_].q; ;for 1..4;$,=~s;^.;;;$,});$;->setup;
More information about the Catalyst
mailing list