More problems with UTF-8

Michele Beltrame <mb-pzZ8rf8/[email protected]>
Newsgroups gmane.comp.lang.perl.modules.petal
Message-ID <[email protected]>
Hi all!

I'm experiencing some more problems with charsets. I subclassed Petal's
process() to always output UTF-8:

package Petal::AlwaysUTF8;
use strict;
use base qw /Petal/;
use Encode;

sub process
{
   my $self = shift;
   my $res = $self->SUPER::process (@_);
   return Encode::encode ('utf8', $res);
}

This works just fine as all entities on the templates get correctly
( &agrave;, &nbsp;, ...) get correctly converted to UTF-8.

The problem arises with UTF-8 data which is inserted into the template at
runtime (from the script, data I get from the database). This data is
already UTF-8 and it seems it gets converted again by my subclassed
process() method, which of course leads to weird display.

I tried:

use encoding 'utf8';

The results are a mess: if I don't use my subclassed process() method
everything appears nice, except for entities of the template (&nbsp; ...);
if I use the subclassed method, then everything gets encoded twice and
the result is something impossible to describe. ;-)

I guess that what I need to do is ensure that the template is UTF-8
(maybe by using Encode), but this should probably happen before the
insertion of the data ( process() ), as that data is already UTF-8!
I tried, without any success, to mix the decode_charset setting of
Petal with all what I described above.

Any suggestion?

	Thank you in advance, Michele.

-- 
Michele Beltrame
http://www.italpro.net/mb/
ICQ# 76660101 - e-mail: mb-pzZ8rf8/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.