[Catalyst] utf8 on c->res-write or c->res->print

Tomas Doran bobtfish at bobtfish.net
Thu Feb 20 14:53:08 GMT 2014

On Feb 20, 2014, at 2:19 PM, Dmitry L. <dim0xff at gmail.com> wrote:

>    use utf8;

You shouldn’t need this unless you have actual utf8 characters (rather than escapes) in your source code.

>    my $fh = $c->res->write_fh;
>    my $test = "\x{41f}\x{440}\x{43e}\x{431}\x{430}";
>    utf8::encode($test);

You probably actually want Encode::encode(‘UTF-8’, $test);

>    $fh->write($test);
> On 20 February 2014 17:45, Sergey Dmitriev <sergey.programmer at gmail.com> wrote:
>> Hello,
>> I'm trying to put some utf8 strings as a part of Catalyst response as
>> follows:

Right, you can’t do that :)

If you try to use the raw write interfaces you have to send bytes not characters (and so need to encode your utf8 character strings).

>> $c->res->print ( ... )
>> and
>> $c->res->write( ... )
>> line by line.
>> However it dies with
>>   Wide character in syswrite at ..... IO/Handle.pm line 474
>> Any ideas how can utf8 be written to response?
>> E.g. set binmode on output handle. Cannot find how.
>> Using Catalyst Runtime 5.90042.

This is not what you want to do.

The handle is already binary - just you’re not writing binary to it, you’re writing characters (and perl does not know how to translate those characters into bytes).


More information about the Catalyst mailing list