Andy,
Since the patches are flying, here's something from the list
discussion a week or so ago.
Should Provider test for utf8-ness before attempting to check for BOM?
If you pass in a file handle that's already opened with a layer then
you get warnings.
And would it be smart to have a TEMPLATE_ENCODING config option to
tell Provider how to decode the content if not BOM is not found?
An unanswered question is should TT also encode output, or should
setting the output io layer be left to the user?
If you want I can try and find time for docs and test case, although
the decode() I added only generates warnings (CHECK not set), and I'm
not sure how to get Template::Test to check for warnings. That's
something you are probably more familiar with.
I also think something like Tatsuhiko Miyagawa's T::P::Encoding
module would be nice core feature since specifying the encoding of a
template is rather fundamental. Could it be part of META, I wonder?
[% META encoding = 'utf8' %]
although I suppose the encoding needs to be determined before META is
parsed.
First pass, something like:
cvs server: Diffing lib/Template
Index: lib/Template/Provider.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Provider.pm,v
retrieving revision 2.86
diff -u -B -r2.86 Provider.pm
--- lib/Template/Provider.pm 2006/01/30 20:04:54 2.86
+++ lib/Template/Provider.pm 2006/01/31 15:37:48
@@ -405,6 +405,7 @@
$self->{ DEFAULT } = $params->{ DEFAULT };
# $self->{ PREFIX } = $params->{ PREFIX };
$self->{ PARAMS } = $params;
+ $self->{ TEMPLATE_ENCODING } = $params->{ TEMPLATE_ENCODING };
# look for user-provided UNICODE parameter or use default from package var
$self->{ UNICODE } = defined $params->{ UNICODE }
@@ -1008,6 +1009,8 @@
my $self = shift;
my $string = shift;
+ return $string if Encode::is_utf8( $string );
+
# try all the BOMs in order looking for one (order is important
# 32bit BOMs look like 16bit BOMs)
my $count = 0;
@@ -1023,8 +1026,9 @@
}
}
- # no boms matched so it must be a non unicode string which we return as is
- return $string;
+ return $self->{TEMPLATE_ENCODING}
+ ? Encode::decode( $self->{TEMPLATE_ENCODING}, $string )
+ : $string;
}
--
Bill Moseley
[EMAIL PROTECTED]
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates