in reply to Re: CGI::Application - Which is the proper way of handling and outputting utf8
in thread CGI::Application - Which is the proper way of handling and outputting utf8

With the 'as_utf8' hack, you do not need binmode STDIN, ":encoding(utf8)";. In fact, it will cause problems if you have a binary/file upload field in a web form, since it will try to UTF-8 decode the incoming binary file/data. The as_utf8 hack correctly only decodes text form field data.

Instead of binmode STDOUT, ":encoding(utf8)";, you can put the following in cgiapp_postrun():

sub cgiapp_postrun { # overrides my ($self, $output_ref) = @_; utf8::encode( $$output_ref ) if utf8::is_utf8($$output_ref) }
This will only UTF-8 encode the output if it needs encoding -- i.e., only if it $output_ref contains non-ASCII characters.

  • Comment on Re^2: CGI::Application - Which is the proper way of handling and outputting utf8
  • Download Code