[Catalyst] CSV / UTF-8 / Unicode
Lars Dɪᴇᴄᴋᴏᴡ 迪拉斯
daxim at cpan.org
Tue Jul 2 09:06:04 GMT 2013
> I seem to be having major problems getting the application devel
> server (my_app_server.pl) to accept an IO::File Handle as CSV and
> correctly encode as UTF-8.
No, the code does exactly what you said. The problem is rather that
Catalyst::Response::body wants octets, not characters. Either pass the
handle through in raw mode, or encode the content again for output as
UTF-8. If the input file is not under your control, I recommend going
through a manual decoding/encoding step instead of IO layers, and make
decoding errors fatal (see FB_CROAK in <http://p3rl.org/Encode>) in
order to catch malformed encoding before it's delivered to the client.
One can't be too careful.
> # close file
> undef $iof;
That's not necessary. When the reference falls out of scope, the
destructor that closes the file is called automatically.
PS: IO::File does not throw exceptions when the file could not be read.
Instead I recommend to use the `open` built-in in conjuction with
<http://p3rl.org/autodie> for better error checking.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 836 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/catalyst/attachments/20130702/26152c10/signature.pgp
More information about the Catalyst