[Templates] PROCESS and file encoding

Olivier Salaün - CRU olivier.salaun@cru.fr
Fri, 11 Aug 2006 15:52:36 +0200


This is a multi-part message in MIME format.
--------------000309020504090608080406
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by listes.cru.fr id k7BDqbZR011968

Bill Moseley wrote:

>On Fri, Aug 11, 2006 at 02:09:56PM +0200, Olivier Sala=FCn - CRU wrote:
> =20
>
>>If I read the TT2 documentation and part of the code carefully, there i=
s
>>no way to tell Template::Provider::_load() to use a provided encoding
>>while opening the template file.
>>   =20
>>
>IIRC, it will look for a BOM, or you can also look at using:
>
>    http://search.cpan.org/~miyagawa/Template-Provider-Encoding-0.05/
> =20
>
I missed this one, thank you.

>Which adds a way to flag individual templates so templates can be in dif=
ferent encodings.
>
>There's also the ENCODING provider option to define an encoding for
>all templates.
>
>    [% USE encoding 'utf-8' -%]
> =20
>
Any plan to include these features natively in the Template package ?
It would make sense for any non-English user to have these feature easy=20
to find.

>>Currently the code looks like that :
>>         if (open(FH, $name)) {
>>            my $text =3D <FH>;
>>            $text =3D $self->_decode_unicode($text) if $self->{ UNICODE=
 };
>>
>>The open() call should take a third argument to define the file encodin=
g :
>>   open FH, '<:utf8', $name;
>>OR
>>   open FH, '<:encoding(iso-8859-1)', $name;
>>   =20
>>
>The advantage of _decode_unicode() is that it is used for both file name=
s and file handles as templates.
>
>Is there a difference between using a perl io layer vs calling Encode::d=
ecode?
> =20
>
Perl IO layer also uses the Encode package.
I think it makes sense to solve these encoding problems in the lowest=20
layer ; doing it while opening the files seem the right place and=20
doesn't cost much effort.

Thank you.


--------------000309020504090608080406
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Bill Moseley wrote:
<blockquote cite="mid20060811131844.GB24855@hank.org" type="cite">
  <pre wrap="">On Fri, Aug 11, 2006 at 02:09:56PM +0200, Olivier Sala&uuml;n - CRU wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">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.
    </pre>
  </blockquote>
  <pre wrap=""><!---->IIRC, it will look for a BOM, or you can also look at using:

    <a class="moz-txt-link-freetext" href="http://search.cpan.org/~miyagawa/Template-Provider-Encoding-0.05/">http://search.cpan.org/~miyagawa/Template-Provider-Encoding-0.05/</a>
  </pre>
</blockquote>
I missed this one, thank you.<br>
<blockquote cite="mid20060811131844.GB24855@hank.org" type="cite">
  <pre wrap="">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' -%]
  </pre>
</blockquote>
Any plan to include these features natively in the Template package ?<br>
It would make sense for any non-English user to have these feature easy
to find.<br>
<blockquote cite="mid20060811131844.GB24855@hank.org" type="cite">
  <blockquote type="cite">
    <pre wrap="">Currently the code looks like that :
         if (open(FH, $name)) {
            my $text = &lt;FH&gt;;
            $text = $self-&gt;_decode_unicode($text) if $self-&gt;{ UNICODE };

The open() call should take a third argument to define the file encoding :
   open FH, '&lt;:utf8', $name;
OR
   open FH, '&lt;:encoding(iso-8859-1)', $name;
    </pre>
  </blockquote>
  <pre wrap=""><!---->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?
  </pre>
</blockquote>
Perl IO layer also uses the Encode package. <br>
I think it makes sense to solve these encoding problems in the lowest
layer ; doing it while opening the files seem the right place and
doesn't cost much effort.<br>
<br>
Thank you.<br>
<br>
</body>
</html>

--------------000309020504090608080406--