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.