[cgiapp] UTF-8 output

Michael Lackhoff lackhoff at zbmed.uni-koeln.de
Mon Nov 2 00:43:40 EST 2009


I would like to switch the encoding of my app from latin1 to UTF-8 and
got it going somehow but am not sure if I am doing it right.

These are my changes in my base class

# seems to be necessary for form input
use CGI '-utf8';

# is there no better way?
sub tt_post_process {
    my $self    = shift;
    my $htmlref = shift;
    utf8::encode($$htmlref);
}

sub cgiapp_init {
    ...
    $self->header_add(-charset => 'utf-8');
}

I am using CAP::Dispatch and the TT-plugin. Without the header_add I get
a HTTP header with an ISO-8859-1 charset definition so the browser
thinks it is latin1 and even a
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
in the template won't help.

And is there no better way for the template output than to post_process
the whole template? Is there no way to get the output of tt_process as
UTF-8 so that there is no post_processing necessary?

Any comments?

Thanks
-Michael



More information about the cgiapp mailing list