[Catalyst] Problems with Encoding support in Catalyst.

Bill Moseley moseley at hank.org
Sun Jan 8 05:55:11 GMT 2017

I just finally removed my custom encoding code to use the built-in code
Catalyst now provides to decode input data and encode output.

But, I came across two issues that I wanted to get some feedback on.

First one is simple.  This code will die if $value is already decoded.  Any
reason not to test it?

 sub _handle_param_unicode_decoding {
     my ( $self, $value, $check ) = @_;
     return unless defined $value; # not in love with just ignoring undefs
- jnap
     return $value if blessed($value); #don't decode when the value is an
+    return $value if Encode::is_utf8($value);  # already decoded?

This next one is what I have questions about.   This is also in Catalyst.pm
in the encoding() method:

        # 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.

Is there a compelling reason to binmode STDERR there?

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

More information about the Catalyst mailing list