Skip Menu |

This queue is for tickets about the HTML-Template CPAN distribution.

Report information
The Basics
Id: 18910
Status: resolved
Priority: 0/
Queue: HTML-Template

People
Owner: Nobody in particular
Requestors: lunch [...] ifrance.com
Cc: kas [...] fi.muni.cz
AdminCc:

Bug Information
Severity: Wishlist
Broken in:
  • 0.04
  • 0.05
  • 0.051
  • 0.06
  • 0.9
  • 0.91
  • 0.95
  • 0.96
  • 1.0
  • 1.1
  • 1.2.1
  • 1.3
  • 1.4
  • 1.5
  • 1.6
  • 1.7
  • 1.8
  • 2.0
  • 2.1
  • 2.2
  • 2.3
  • 2.4
  • 2.5
  • 2.6
  • 2.7
  • 2.8
Fixed in: (no value)



Subject: No way to deal with multi-bytes characters.
Hi, It seems that HTML::Template can't be used with Perl programs that use multi-bytes characters. It may be possible to open a template with the ':utf8' PerlIO layer and then pass the filehandle to HTML::Template->new(), but included templates are still read as if they were ascii encoded.
From: kas [...] informatics.muni.cz
Dne Ășt 25.dub.2006 06:20:27, guest napsal(a): Show quoted text
> It seems that HTML::Template can't be used with Perl programs that use > multi-bytes characters. It may be possible to open a template with the > ':utf8' PerlIO layer and then pass the filehandle to > HTML::Template->new(), but included templates are still read as if they > were ascii encoded.
I agree with that. It does not even honor the -CSD switch (or the use open ":utf8" pragma). I have created the attached patch, which fixes this problem. It works for the template file itself and for includes called from this template, but it is not tested in any way with caching (read: it probably does not work with caching). Apply this patch, and add binmode => ':utf8' to the HTML::Template constructor call. -Yenya
This patch allows HTML::Template to be used with UTF-8 encoded templates. It works for basic tasks (opening template files and includes), but it is untested (and probably does not work) with caching. The patch is (c) Jan "Yenya" Kasprzak <kas@fi.muni.cz>, http://www.fi.muni.cz/~kas/ and can be distributed under the same terms as HTML::Template itself. --- HTML/Template.pm.orig Mon Dec 17 13:21:08 2007 +++ HTML/Template.pm Mon Dec 17 13:35:19 2007 @@ -648,6 +648,20 @@ normal behavior is to look only in the current directory for a template to include. Defaults to 0. +=item * + +binmode - set the given binmode() when opening the template file and all its +includes. + +Example: + + my $template = HTML::Template->new( + filename => 'file.tmpl', + binmode => ':utf8' + ); + +NOTE: When the template is given as scalar or filehandle instead of +file name, this sets the binmode only on included templates). =back =item Debugging Options @@ -1662,13 +1676,16 @@ } confess("HTML::Template->new() : Cannot open included file $options->{filename} : $!") - unless defined(open(TEMPLATE, $filepath)); + unless defined(open(my $fh, $filepath)); $self->{mtime} = $self->_mtime($filepath); + if (defined $options->{binmode}) { + binmode $fh, $options->{binmode}; + } + # read into scalar, note the mtime for the record - $self->{template} = ""; - while (read(TEMPLATE, $self->{template}, 10240, length($self->{template}))) {} - close(TEMPLATE); + { local $/; $self->{template} = <$fh>; } + close($fh); } elsif (exists($options->{scalarref})) { # copy in the template text @@ -2264,12 +2281,14 @@ die "HTML::Template->new() : Cannot open included file $filename : file not found." unless defined($filepath); die "HTML::Template->new() : Cannot open included file $filename : $!" - unless defined(open(TEMPLATE, $filepath)); + unless defined(open(my $fh, $filepath)); - # read into the array - my $included_template = ""; - while(read(TEMPLATE, $included_template, 10240, length($included_template))) {} - close(TEMPLATE); + if ($self->{options}->{binmode}) { + binmode $fh, $self->{options}->{binmode}; + } + my $included_template; + { local $/; $included_template = <$fh>; } + close $fh; # call filters if necessary $self->_call_filters(\$included_template) if @{$options->{filter}};
There is also a related ticket at SourceForge: http://sourceforge.net/tracker/index.php?func=detail&aid=1023009&group_id=1075&atid=351075 - which is the prefered bug tracking system for HTML::Template? This one or the sf.net one?
Subject: Re: [rt.cpan.org #18910] No way to deal with multi-bytes characters.
Date: Mon, 17 Dec 2007 15:09:35 +0100
To: Jan Yenya Kasprzak via RT <bug-HTML-Template [...] rt.cpan.org>
From: Fred <lunch [...] ifrance.com>
Thank you for the patch ! Fred
Ping? Is HTML::Template maintained?
From: allard [...] byte.nl
Hi, I've been fixing a few bugs myself. Please find the fixed sources for HTML::Template at http://gitweb.byte.nl/git/html-template.git . Your patch is included in the sources. Please use the 'byte' branch. I'll be compiling Debian packages in a few days, so check back there if you want to use them as well. Regards, Allard
This is now possible in the upcoming HTML::Template 2.10 version using the new "utf8: parameter: my $template = HTML::Template->new( filename => 'file.tmpl', utf8 => 1, ); And if you don't want to use UTF-8, but need a different encoding, then you can use the "open_mode" parameter that uses perl's IO layers: my $template = HTML::Template->new( filename => 'file.tmpl', open_mode => '<:encoding(UTF-16)', );
2.10 works for me, thanks! Just a side note - I am not able to do git clone http://gitweb.byte.nl/git/html-template.git - you probably forgot to run git-update-server-info after modifying your repo. The error message I am getting is the following one: $ git clone http://gitweb.byte.nl/git/html-template.git Initialized empty Git repository in /home/kas/tmp/html-template/.git/ warning: remote HEAD refers to nonexistent ref, unable to checkout.
On Mon Aug 08 11:31:49 2011, YENYA wrote: Show quoted text
> git clone http://gitweb.byte.nl/git/html-template.git > > - you probably forgot to run git-update-server-info after modifying your > repo. The error message I am getting is the following one: > > $ git clone http://gitweb.byte.nl/git/html-template.git > Initialized empty Git repository in /home/kas/tmp/html-template/.git/ > warning: remote HEAD refers to nonexistent ref, unable to checkout.
Those aren't my repositories nor are they the official ones used for development. The official one is located at git://github.com/mpeters/html-template.git (on the web at https://github.com/mpeters/html-template)