[Catalyst] Problems with Encoding support in Catalyst.

Bill Moseley moseley at hank.org
Sun Jan 8 16:42:43 GMT 2017

On Sat, Jan 7, 2017 at 9:55 PM, Bill Moseley <moseley at hank.org> wrote:

>         # Let it be set to undef
>         if (my $wanted = shift)  {
>             $encoding = Encode::find_encoding($wanted)
>               or Carp::croak( qq/Unknown encoding '$wanted'/ );
>             *binmode(STDERR, ':encoding(' . $encoding->name . ')');*
> The problem with that is it seems to turn off autoflush on STDERR.   In my
> case that is causing intermixing of lines in the log files.
> If I turn on STDERR->autoflush(1) then the logging works again and log
> lines are not mangled.
> But, I'm not sure we should apply a layer to STDERR like that.   For
> example, I log to stderr with JSON and that is already encoded.

Just in case it isn't clear that is a problem:

use strict;
use warnings;
use Encode;
use JSON;

binmode( STDERR, ':utf8' );
my $json = encode_json( { chars => decode_utf8( '雨下降' ) } );
print STDERR "$json\n";

Results in:

{"chars":"é›¨ä¸‹é™ "}

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/catalyst/attachments/20170108/ebba16a8/attachment.htm>

More information about the Catalyst mailing list