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)

Attachments


Subject: No way to deal with multi-bytes characters.
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Type: text/plain; charset="utf8"
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 291
Download (untitled) / with headers
text/plain 291b
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.
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Charset: utf8
Message-Id: <rt-3.6.HEAD-11457-1197895404-1507.18910-0-0 [...] rt.cpan.org>
Content-Type: multipart/mixed; boundary="----------=_1197895405-11457-1"
From: kas [...] informatics.muni.cz
X-RT-Original-Encoding: utf-8
Content-Length: 0
Content-Disposition: inline
Content-Type: text/plain
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 771
Download (untitled) / with headers
text/plain 771b
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
MIME-Version: 1.0
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Type: multipart/mixed; boundary="----------=_1197895404-11457-0"
Charset: utf8
Content-Length: 0
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: iso-8859-1
X-RT-Original-Encoding: iso-8859-1
Content-Length: 0
Content-Type: application/octet-stream; name="HTML-Template-2.9-utf8.patch"
Content-Disposition: inline; filename="HTML-Template-2.9-utf8.patch"
Content-Transfer-Encoding: base64
Content-Length: 2426
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}};
MIME-Version: 1.0
In-Reply-To: <rt-3.6.HEAD-11457-1197895404-1507.18910-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.418 (Entity 5.418)
Content-Disposition: inline
Charset: utf8
References: <rt-3.6.HEAD-11457-1197895404-1507.18910-0-0 [...] rt.cpan.org>
Message-Id: <rt-3.6.HEAD-11443-1197898109-1378.18910-0-0 [...] rt.cpan.org>
Content-Type: text/plain
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Original-Encoding: utf-8
Content-Length: 233
Download (untitled) / with headers
text/plain 233b
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?
MIME-Version: 1.0
X-Spam-Status: No, hits=-2.0 required=8.0 tests=BAYES_00,SPF_SOFTFAIL
In-Reply-To: <rt-3.6.HEAD-11443-1197898109-1378.18910-6-0 [...] rt.cpan.org>
Content-Disposition: inline
References: <RT-Ticket-18910 [...] rt.cpan.org> <rt-3.6.HEAD-11457-1197895404-1507.18910-6-0 [...] rt.cpan.org> <rt-3.6.HEAD-11443-1197898109-1378.18910-6-0 [...] rt.cpan.org>
X-Virus-Scanned: Debian amavisd-new at edgard.fdn.fr
Content-Type: text/plain; charset="utf-8"
X-RT-Original-Encoding: us-ascii
Received: from x1.develooper.com (x1.develooper.com [63.251.223.170]) by diesel.bestpractical.com (Postfix) with SMTP id E3CAF4D8119 for <bug-html-template [...] rt.cpan.org>; Mon, 17 Dec 2007 09:13:24 -0500 (EST)
Received: (qmail 13692 invoked from network); 17 Dec 2007 14:13:24 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 17 Dec 2007 14:13:24 -0000
Received: from solo.fdn.fr (HELO solo.fdn.fr) (80.67.169.19) by 16.mx.develooper.com (qpsmtpd/0.40-dev) with ESMTP; Mon, 17 Dec 2007 06:13:20 -0800
Received: by solo.fdn.fr (Postfix, from userid 10) id 25E68430441; Mon, 17 Dec 2007 15:13:06 +0100 (CET)
Received: from localhost (localhost [127.0.0.1]) by edgard.fdn.fr (Postfix) with ESMTP id B4332A5C4CB for <bug-HTML-Template [...] rt.cpan.org>; Mon, 17 Dec 2007 15:09:43 +0100 (CET)
Received: from edgard.fdn.fr ([127.0.0.1]) by localhost (edgard.fdn.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hfYMVf9Ku9g7 for <bug-HTML-Template [...] rt.cpan.org>; Mon, 17 Dec 2007 15:09:35 +0100 (CET)
Received: by edgard.fdn.fr (Postfix, from userid 1004) id B84E914A4037; Mon, 17 Dec 2007 15:09:35 +0100 (CET)
Delivered-To: cpan-bug+html-template [...] diesel.bestpractical.com
Subject: Re: [rt.cpan.org #18910] No way to deal with multi-bytes characters.
User-Agent: Mutt/1.5.11
Return-Path: <lunch [...] ifrance.com>
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-html-template [...] rt.cpan.org
Date: Mon, 17 Dec 2007 15:09:35 +0100
X-Spam-Level: *
Message-Id: <20071217140935.GA9945 [...] edgard.fdn.fr>
To: Jan Yenya Kasprzak via RT <bug-HTML-Template [...] rt.cpan.org>
From: Fred <lunch [...] ifrance.com>
X-RT-Original-Encoding: utf-8
RT-Message-ID: <rt-3.6.HEAD-11457-1197900811-1774.18910-0-0 [...] rt.cpan.org>
Content-Length: 32
Thank you for the patch ! Fred
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-12691-1267534166-640.18910-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 35
Ping? Is HTML::Template maintained?
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-12691-1267534166-640.18910-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <rt-3.8.HEAD-12691-1267534166-640.18910-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-2907-1277135757-1952.18910-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
From: allard [...] byte.nl
X-RT-Original-Encoding: utf-8
Content-Length: 333
Download (untitled) / with headers
text/plain 333b
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
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-18808-1302883897-532.18910-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 466
Download (untitled) / with headers
text/plain 466b
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)', );
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-18808-1302883897-532.18910-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <rt-3.8.HEAD-18808-1302883897-532.18910-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-22517-1312817509-1344.18910-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 450
Download (untitled) / with headers
text/plain 450b
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.
MIME-Version: 1.0
In-Reply-To: <rt-3.8.HEAD-22517-1312817509-1344.18910-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
References: <rt-3.8.HEAD-18808-1302883897-532.18910-0-0 [...] rt.cpan.org> <rt-3.8.HEAD-22517-1312817509-1344.18910-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-12231-1333104359-1329.18910-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 655
Download (untitled) / with headers
text/plain 655b
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)


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.