[Templates] PROCESS and file encoding

Bill Moseley moseley@hank.org
Fri, 11 Aug 2006 06:18:45 -0700


On Fri, Aug 11, 2006 at 02:09:56PM +0200, Olivier Salaün - CRU wrote:
> If I read the TT2 documentation and part of the code carefully, there is
> no way to tell Template::Provider::_load() to use a provided encoding
> while opening the template file.

IIRC, it will look for a BOM, or you can also look at using:

    http://search.cpan.org/~miyagawa/Template-Provider-Encoding-0.05/

Which adds a way to flag individual templates so templates can be in
different encodings.

There's also the ENCODING provider option to define an encoding for
all templates.

    [% USE encoding 'utf-8' -%]


> Currently the code looks like that :
>          if (open(FH, $name)) {
>             my $text = <FH>;
>             $text = $self->_decode_unicode($text) if $self->{ UNICODE };
> 
> The open() call should take a third argument to define the file encoding :
>    open FH, '<:utf8', $name;
> OR
>    open FH, '<:encoding(iso-8859-1)', $name;

The advantage of _decode_unicode() is that it is used for both file
names and file handles as templates.

Is there a difference between using a perl io layer vs calling
Encode::decode?

-- 
Bill Moseley
moseley@hank.org