<div dir="ltr"><div>I just finally removed my custom encoding code to use the built-in code Catalyst now provides to decode input data and encode output.</div><div><br></div><div>But, I came across two issues that I wanted to get some feedback on.</div><div><br></div><div>First one is simple. This code will die if $value is already decoded. Any reason not to test it?</div><div><br></div><div><div><br></div><div><font face="monospace, monospace"> sub _handle_param_unicode_decoding {</font></div><div><font face="monospace, monospace"> my ( $self, $value, $check ) = @_;</font></div><div><font face="monospace, monospace"> return unless defined $value; # not in love with just ignoring undefs - jnap</font></div><div><font face="monospace, monospace"> return $value if blessed($value); #don't decode when the value is an object.</font></div></div><div><font face="monospace, monospace">+ return $value if Encode::is_utf8($value); # already decoded?</font></div><div><font face="monospace, monospace"><br></font></div><div>This next one is what I have questions about. This is also in Catalyst.pm in the encoding() method:</div><br clear="all"><div><div><font face="monospace, monospace"> # Let it be set to undef</font></div><div><font face="monospace, monospace"> if (my $wanted = shift) {</font></div><div><font face="monospace, monospace"> $encoding = Encode::find_encoding($wanted)</font></div><div><font face="monospace, monospace"> or Carp::croak( qq/Unknown encoding '$wanted'/ );</font></div><div><font face="monospace, monospace"> <b>binmode(STDERR, ':encoding(' . $encoding->name . ')');</b></font></div></div><div><b><br></b></div><div><br></div><div>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.</div><div><br></div><div>If I turn on STDERR->autoflush(1) then the logging works again and log lines are not mangled.</div><div><br></div><div>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.</div><div><br></div><div>Is there a compelling reason to binmode STDERR there?</div><div><br></div><div><br></div><div><br></div><div><br></div>-- <br><div class="gmail_signature">Bill Moseley<br><a href="mailto:moseley@hank.org" target="_blank">moseley@hank.org</a></div>
</div>