in reply to Re^2: 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

so the faster ASCII semantics can be used where possible.

Almost. The UTF8=1 format is still unnecessarily used if the string is "É", for example. You'd have to include the following after decoding if you wanted to always use the UTF8=0 format when possible.

utf8::downgrade($p, 1);

It's safer not to do that, though, as it affects \w*, uc()*, buggy XS, etc.

* — \w and uc() are unaffected when using use 5.012; or use feature qw( unicode_strings );.

Replies are listed 'Best First'.
Re^4: CGI::Application - Which is the proper way of handling and outputting utf8
by Anonymous Monk on Dec 14, 2010 at 10:01 UTC

    Is there a way to have imports automatically forwarded to CGI?

    For example with:

    use CGI::as_utf8 qw/-no_xhtml/;
    -no_xhtml is not forwarded to CGI!

      I think, with the current version of CGI.pm, you could get the -no_xhtml pragma into CGI.pm by putting this into your application module. (It overrides the cgiapp_get_query method in the CGI::Application parent.)

      sub cgiapp_get_query { my $self = shift; use CGI ('-no_xhmtml'); my $q = CGI->new; return $q; }

      The current version of CGI.pm doesn't use that particular pragma, but the code would work if some other pragma were desired, such as -utf8.

        No. Make a subclass.
      I think the following will do the trick.
      sub import { shift; unshift(@_, 'CGI'); goto &CGI::import; }