r19759 - in /branches/upstream/libtemplate-provider-encoding-perl: ./ current/ current/lib/ current/lib/Template/ current/lib/Template/Plugin/ current/lib/Template/Provider/ current/lib/Template/Stash/ current/t/
eloy at users.alioth.debian.org
eloy at users.alioth.debian.org
Fri May 9 13:03:57 UTC 2008
Author: eloy
Date: Fri May 9 13:03:56 2008
New Revision: 19759
URL: http://svn.debian.org/wsvn/?sc=1&rev=19759
Log:
[svn-inject] Installing original source of libtemplate-provider-encoding-perl
Added:
branches/upstream/libtemplate-provider-encoding-perl/
branches/upstream/libtemplate-provider-encoding-perl/current/
branches/upstream/libtemplate-provider-encoding-perl/current/Changes
branches/upstream/libtemplate-provider-encoding-perl/current/MANIFEST
branches/upstream/libtemplate-provider-encoding-perl/current/META.yml
branches/upstream/libtemplate-provider-encoding-perl/current/Makefile.PL
branches/upstream/libtemplate-provider-encoding-perl/current/lib/
branches/upstream/libtemplate-provider-encoding-perl/current/lib/Template/
branches/upstream/libtemplate-provider-encoding-perl/current/lib/Template/Plugin/
branches/upstream/libtemplate-provider-encoding-perl/current/lib/Template/Plugin/encoding.pm
branches/upstream/libtemplate-provider-encoding-perl/current/lib/Template/Provider/
branches/upstream/libtemplate-provider-encoding-perl/current/lib/Template/Provider/Encoding.pm
branches/upstream/libtemplate-provider-encoding-perl/current/lib/Template/Stash/
branches/upstream/libtemplate-provider-encoding-perl/current/lib/Template/Stash/ForceUTF8.pm
branches/upstream/libtemplate-provider-encoding-perl/current/t/
branches/upstream/libtemplate-provider-encoding-perl/current/t/00_compile.t
branches/upstream/libtemplate-provider-encoding-perl/current/t/01_unicode.t
branches/upstream/libtemplate-provider-encoding-perl/current/t/02_obj.t
branches/upstream/libtemplate-provider-encoding-perl/current/t/euc-jp.tt
branches/upstream/libtemplate-provider-encoding-perl/current/t/utf-8-bom.tt
branches/upstream/libtemplate-provider-encoding-perl/current/t/utf-8-wo-encoding.tt
branches/upstream/libtemplate-provider-encoding-perl/current/t/utf-8.tt
Added: branches/upstream/libtemplate-provider-encoding-perl/current/Changes
URL: http://svn.debian.org/wsvn/branches/upstream/libtemplate-provider-encoding-perl/current/Changes?rev=19759&op=file
==============================================================================
--- branches/upstream/libtemplate-provider-encoding-perl/current/Changes (added)
+++ branches/upstream/libtemplate-provider-encoding-perl/current/Changes Fri May 9 13:03:56 2008
@@ -1,0 +1,38 @@
+Revision history for Perl extension Template::Provider::Encoding
+
+0.10 Tue Jul 31 23:53:58 PDT 2007
+ - Fixed warning issue. RT 27645
+
+0.09 Wed Apr 18 14:49:48 PDT 2007
+ - Added Encode.pm to prereq
+
+0.08 Tue Apr 17 13:52:41 PDT 2007
+ - Applied patch http://www.cpanforum.com/posts/2177 so the
+ default encoding other than 'utf-8' can be set
+ (Thanks to Nobuaki ITO)
+
+0.07 Sun Oct 22 21:41:03 JST 2006
+ - Added dependency for Template-Toolkit
+ (Thanks to Andreas Koenig)
+
+0.06 Sun Oct 22 21:11:38 JST 2006
+ - Skip obj.t test if Template::Stash::XS is not available
+
+0.05 2006-02-05T01:10:24Z
+ - Packaging bug caused test errors
+
+0.04 2006-01-26T18:50:22Z
+ - Do nothing when template is BOMed
+ (Thanks to Bill Moseley)
+
+0.03 2006-01-16T22:38:37Z
+ - Use $Template::Stash::Config as a base class to support
+ XS based object variable correctly
+
+0.02 Sat Jan 14 15:01:49 UTC 2006
+ - Added Template::Stash::ForceUTF8 and now this module works magically
+ (you can mix Unicode flagged and UTF-8 bytes in stash!)
+ - Now no_unicode mode is unnecessary since we have magical stash
+
+0.01 Tue Jan 10 14:39:56 2006
+ - original version
Added: branches/upstream/libtemplate-provider-encoding-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/branches/upstream/libtemplate-provider-encoding-perl/current/MANIFEST?rev=19759&op=file
==============================================================================
--- branches/upstream/libtemplate-provider-encoding-perl/current/MANIFEST (added)
+++ branches/upstream/libtemplate-provider-encoding-perl/current/MANIFEST Fri May 9 13:03:56 2008
@@ -1,0 +1,14 @@
+Changes
+lib/Template/Plugin/encoding.pm
+lib/Template/Provider/Encoding.pm
+lib/Template/Stash/ForceUTF8.pm
+Makefile.PL
+MANIFEST This list of files
+t/00_compile.t
+t/01_unicode.t
+t/02_obj.t
+t/euc-jp.tt
+t/utf-8-bom.tt
+t/utf-8-wo-encoding.tt
+t/utf-8.tt
+META.yml Module meta-data (added by MakeMaker)
Added: branches/upstream/libtemplate-provider-encoding-perl/current/META.yml
URL: http://svn.debian.org/wsvn/branches/upstream/libtemplate-provider-encoding-perl/current/META.yml?rev=19759&op=file
==============================================================================
--- branches/upstream/libtemplate-provider-encoding-perl/current/META.yml (added)
+++ branches/upstream/libtemplate-provider-encoding-perl/current/META.yml Fri May 9 13:03:56 2008
@@ -1,0 +1,13 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
+name: Template-Provider-Encoding
+version: 0.10
+version_from: lib/Template/Provider/Encoding.pm
+installdirs: site
+requires:
+ Encode: 1
+ Template: 2.1
+ Test::More: 0.32
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.30
Added: branches/upstream/libtemplate-provider-encoding-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/branches/upstream/libtemplate-provider-encoding-perl/current/Makefile.PL?rev=19759&op=file
==============================================================================
--- branches/upstream/libtemplate-provider-encoding-perl/current/Makefile.PL (added)
+++ branches/upstream/libtemplate-provider-encoding-perl/current/Makefile.PL Fri May 9 13:03:56 2008
@@ -1,0 +1,10 @@
+use ExtUtils::MakeMaker;
+WriteMakefile(
+ 'NAME' => 'Template::Provider::Encoding',
+ 'VERSION_FROM' => 'lib/Template/Provider/Encoding.pm', # finds $VERSION
+ 'PREREQ_PM' => {
+ Test::More => 0.32,
+ Template => 2.10,
+ Encode => 1.00,
+ },
+);
Added: branches/upstream/libtemplate-provider-encoding-perl/current/lib/Template/Plugin/encoding.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libtemplate-provider-encoding-perl/current/lib/Template/Plugin/encoding.pm?rev=19759&op=file
==============================================================================
--- branches/upstream/libtemplate-provider-encoding-perl/current/lib/Template/Plugin/encoding.pm (added)
+++ branches/upstream/libtemplate-provider-encoding-perl/current/lib/Template/Plugin/encoding.pm Fri May 9 13:03:56 2008
@@ -1,0 +1,45 @@
+package Template::Plugin::encoding;
+use base qw( Template::Plugin );
+
+our $VERSION = '0.02';
+
+sub new {
+ my $class = shift;
+ my $contetx = shift;
+ $_[0];
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Tempate::Plugin::encoding - Template plugin to specify encoding
+
+=head1 SYNOPSIS
+
+ [% USE encoding 'euc-jp' -%]
+ <?xml version="1.0" encoding="[% encoding %]"?>
+
+=head1 DESCRIPTION
+
+Template::Plugin::encoding is a Template plugin to declare the
+encoding of template files. This plugin doesn't actually do anything
+but Template::Provider::Encoding scans the usage of this module to
+find the encoding of templates. As a bonus, you can use C<encoding>
+variable in the template to specify file encoding, which might be
+useful for XML or HTML meta tag.
+
+=head1 AUTHOR
+
+Tatsuhiko Miyagawa E<lt>miyagawa at bulknews.netE<gt>
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=head1 SEE ALSO
+
+L<Template::Provider::Encoding>
+
+=cut
Added: branches/upstream/libtemplate-provider-encoding-perl/current/lib/Template/Provider/Encoding.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libtemplate-provider-encoding-perl/current/lib/Template/Provider/Encoding.pm?rev=19759&op=file
==============================================================================
--- branches/upstream/libtemplate-provider-encoding-perl/current/lib/Template/Provider/Encoding.pm (added)
+++ branches/upstream/libtemplate-provider-encoding-perl/current/lib/Template/Provider/Encoding.pm Fri May 9 13:03:56 2008
@@ -1,0 +1,118 @@
+package Template::Provider::Encoding;
+
+use strict;
+our $VERSION = '0.10';
+
+use base qw( Template::Provider );
+use Encode;
+
+sub _init {
+ my ($self, $params) = @_;
+
+ $self = $self->SUPER::_init($params);
+ $self->{DEFAULT_ENCODING} = $params->{DEFAULT_ENCODING} || 'utf8';
+ $self->{ENCODE_CHECK} = $params->{ENCODE_CHECK} || Encode::FB_DEFAULT;
+ return $self;
+}
+
+sub _load {
+ my $self = shift;
+ my($data, $error) = $self->SUPER::_load(@_);
+
+ return ($data, $error) unless defined $data;
+
+ unless (Encode::is_utf8($data->{text})) {
+ my $decoder = $self->detect_encoding($data);
+ $data->{text} = $decoder->decode($data->{text}, $self->{ENCODE_CHECK});
+ }
+
+ return ($data, $error);
+}
+
+sub detect_encoding {
+ my ($self, $data) = @_;
+
+ my $encoding = $data->{text} =~ /^\[% USE encoding '([\w\-]+)'/
+ ? $1 : $self->{DEFAULT_ENCODING};
+ return Encode::find_encoding($encoding);
+}
+
+1;
+__END__
+
+=head1 NAME
+
+Template::Provider::Encoding - Explicitly declare encodings of your templates
+
+=head1 SYNOPSIS
+
+ use Template::Provider::Encoding;
+ use Template::Stash::ForceUTF8;
+ use Template;
+
+ my $tt = Template->new(
+ LOAD_TEMPLATES => [ Template::Provider::Encoding->new ],
+ STASH => Template::Stash::ForceUTF8->new,
+ );
+
+ # Everything should be Unicode
+ # (but you can pass UTF-8 bytes as well, thanks to Template::Stash::ForceUTF8)
+ my $author = "\x{5bae}\x{5ddd}";
+
+ # this will emit Unicode flagged string to STDOUT. You might
+ # probably want to binmode(STDOUT, ":encoding($enccoding)")
+ # before process() call
+ $tt->process($template, { author => $author });
+
+ # in your templates
+ [% USE encoding 'utf-8' -%]
+ My name is [% author %]. { ... whatever UTF-8 bytes }
+
+=head1 DESCRIPTION
+
+Template::Provider::Encoding is a Template Provider subclass to decode
+template using its declaration. You have to declare encoding of the
+template in the head (1st line) of template using (fake) encoding TT
+plugin. Otherwise the template is handled as utf-8.
+
+ [% USE encoding 'utf-8' %]
+ Here comes utf-8 strings with [% variable %].
+
+=head1 DIFFERNCE WITH OTHER WAYS
+
+=head2 UNICODE option and BOM
+
+Recent TT allows C<UNICODE> option to Template::Provider and by adding
+it Provider scans BOM (byte-order mark) to detect UTF-8/UTF-16 encoded
+template files. This module does basically the same thing in a
+different way, but IMHO adding BOM to template files is a little
+painful especially for non-programmers.
+
+=head2 Template::Provider::Encode
+
+L<Template::Provider::Encode> provides a very similar way to detect
+Template file encodings and output the template into various
+encodings.
+
+This module doesn't touch output encoding of the template and instead
+it emits valid Unicode flagged string. I think the output encoding
+conversion should be done by other piece of code, especially in the
+framework.
+
+This module doesn't require you to specify encoding in the code, nor
+doesn't I<guess> encodings. Instead it forces you to put C<< [% USE
+encoding 'foo-bar' %] >> in the top of template files, which is
+explicit and, I think, is a good convention.
+
+=head1 AUTHOR
+
+Tatsuhiko Miyagawa E<lt>miyagawa at bulknews.netE<gt>
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=head1 SEE ALSO
+
+L<Template::Stash::ForceUTF8>, L<Template::Provider::Encode>
+
+=cut
Added: branches/upstream/libtemplate-provider-encoding-perl/current/lib/Template/Stash/ForceUTF8.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libtemplate-provider-encoding-perl/current/lib/Template/Stash/ForceUTF8.pm?rev=19759&op=file
==============================================================================
--- branches/upstream/libtemplate-provider-encoding-perl/current/lib/Template/Stash/ForceUTF8.pm (added)
+++ branches/upstream/libtemplate-provider-encoding-perl/current/lib/Template/Stash/ForceUTF8.pm Fri May 9 13:03:56 2008
@@ -1,0 +1,51 @@
+package Template::Stash::ForceUTF8;
+
+use strict;
+our $VERSION = '0.03';
+
+use Template::Config;
+use base ( $Template::Config::STASH );
+use Encode;
+
+sub get {
+ my $self = shift;
+ my $result = $self->SUPER::get(@_);
+ return $result if ref $result;
+
+ Encode::_utf8_on($result) unless Encode::is_utf8($result);
+ return $result;
+}
+
+1;
+__END__
+
+=head1 NAME
+
+Template::Stash::ForceUTF8 - Force UTF-8 (Unicode) flag on stash variables
+
+=head1 SYNOPSIS
+
+ use Template::Stash::ForceUTF8;
+ use Template;
+
+ my $tt = Template->new(
+ LOAD_TEMPLATES => [ Template::Provider::Encoding->new ],
+ STASH => Template::Stash::ForceUTF8->new,
+ );
+
+ my $vars;
+ $vars->{foo} = "\x{5bae}\x{5ddd}"; # Unicode flagged
+ $vars->{bar} = "\xe5\xae\xae\xe5\xb7\x9d"; # UTF-8 bytes
+
+ $tt->process($template, $vars); # this DWIMs
+
+=head1 DESCRIPTION
+
+Template::Stash::ForceUTF8 is a Template::Stash that forces Unicode
+flag on stash variables. Best used with L<Template::Provider::Encoding>.
+
+=head1 SEE ALSO
+
+L<Template::Provider::Encoding>
+
+=cut
Added: branches/upstream/libtemplate-provider-encoding-perl/current/t/00_compile.t
URL: http://svn.debian.org/wsvn/branches/upstream/libtemplate-provider-encoding-perl/current/t/00_compile.t?rev=19759&op=file
==============================================================================
--- branches/upstream/libtemplate-provider-encoding-perl/current/t/00_compile.t (added)
+++ branches/upstream/libtemplate-provider-encoding-perl/current/t/00_compile.t Fri May 9 13:03:56 2008
@@ -1,0 +1,4 @@
+use strict;
+use Test::More tests => 1;
+
+BEGIN { use_ok 'Template::Provider::Encoding' }
Added: branches/upstream/libtemplate-provider-encoding-perl/current/t/01_unicode.t
URL: http://svn.debian.org/wsvn/branches/upstream/libtemplate-provider-encoding-perl/current/t/01_unicode.t?rev=19759&op=file
==============================================================================
--- branches/upstream/libtemplate-provider-encoding-perl/current/t/01_unicode.t (added)
+++ branches/upstream/libtemplate-provider-encoding-perl/current/t/01_unicode.t Fri May 9 13:03:56 2008
@@ -1,0 +1,52 @@
+use strict;
+use Test::More 'no_plan';
+
+use Encode;
+use Template::Provider::Encoding;
+use Template::Stash::ForceUTF8;
+use Template;
+
+my @files = qw( euc-jp.tt utf-8.tt utf-8-wo-encoding.tt utf-8-bom.tt );
+
+my $author = "\x{5bae}\x{5ddd}"; # miyagawa
+my $place = "\x{6771}\x{4eac}"; # Tokyo
+my $author_utf8 = encode("utf-8", $author);
+my $place_utf8 = encode("utf-8", $place);
+
+for my $file (@files) {
+ my $tt = Template->new(
+ LOAD_TEMPLATES => [ Template::Provider::Encoding->new ],
+ );
+ my $vars;
+ $vars->{author} = $author; # Unicode string
+ $vars->{my} = { place => $place }; # Unicode string
+ $tt->process("t/$file", $vars, \my $out) or die $tt->error;
+
+ ok Encode::is_utf8($out), "$file output is utf-8 flagged";
+ like $out, qr/$author/, "$file includes author name correctly";
+ like $out, qr/$place/, "$file includes place correctly";
+ unless ($file =~ /(-wo-|-bom)/) {
+ my $encoding = ($file =~ /(.*)\.tt/)[0];
+ like $out, qr/encoding=$encoding/, "$file has encoding $encoding";
+ }
+}
+
+# test mixing Unicode flagged and UTF-8 bytes in the stash (Unicode flagged)
+for my $file (@files) {
+ my $tt = Template->new(
+ LOAD_TEMPLATES => [ Template::Provider::Encoding->new ],
+ STASH => Template::Stash::ForceUTF8->new,
+ );
+ my $vars;
+ $vars->{author} = $author; # unicode string
+ $vars->{my} = { place => $place_utf8 }; # utf-8
+ $tt->process("t/$file", $vars, \my $out) or die $tt->error;
+
+ ok Encode::is_utf8($out), "$file output is utf-8 flagged";
+ like $out, qr/$author/, "$file includes author name correctly";
+ like $out, qr/$place/, "$file includes place correctly";
+ unless ($file =~ /(-wo-|-bom)/) {
+ my $encoding = ($file =~ /(.*)\.tt/)[0];
+ like $out, qr/encoding=$encoding/, "$file has encoding $encoding";
+ }
+}
Added: branches/upstream/libtemplate-provider-encoding-perl/current/t/02_obj.t
URL: http://svn.debian.org/wsvn/branches/upstream/libtemplate-provider-encoding-perl/current/t/02_obj.t?rev=19759&op=file
==============================================================================
--- branches/upstream/libtemplate-provider-encoding-perl/current/t/02_obj.t (added)
+++ branches/upstream/libtemplate-provider-encoding-perl/current/t/02_obj.t Fri May 9 13:03:56 2008
@@ -1,0 +1,28 @@
+use strict;
+use Test::More;
+
+eval { require DateTime; 1 };
+if ($@) {
+ plan skip_all => 'require DateTime';
+}
+
+use Template;
+use Template::Stash::ForceUTF8;
+
+if ($Template::Config::STASH ne 'Template::Stash::XS') {
+ plan skip_all => 'require Template::Stash::XS';
+}
+
+plan tests => 1;
+
+my $tt = Template->new({
+ STASH => Template::Stash::ForceUTF8->new,
+});
+
+my $dt = DateTime->new(year => 2005, month => 9, day => 12);
+$tt->process(\<<EOF, { dt => $dt }, \my $out) or die $tt->error;
+[% dt.ymd %]
+EOF
+
+like $out, qr/2005-09-12/;
+
Added: branches/upstream/libtemplate-provider-encoding-perl/current/t/euc-jp.tt
URL: http://svn.debian.org/wsvn/branches/upstream/libtemplate-provider-encoding-perl/current/t/euc-jp.tt?rev=19759&op=file
==============================================================================
--- branches/upstream/libtemplate-provider-encoding-perl/current/t/euc-jp.tt (added)
+++ branches/upstream/libtemplate-provider-encoding-perl/current/t/euc-jp.tt Fri May 9 13:03:56 2008
@@ -1,0 +1,4 @@
+[% USE encoding 'euc-jp' -%]
+¤ï¤¿¤·¤Î̾Á°¤Ï [% author %] ¤Ç¤¹¡£
+¤ï¤¿¤·¤Ï [% my.place %] ¤Ë¤¹¤ó¤Ç¤¤¤Þ¤¹¡£
+encoding=[% encoding %]
Added: branches/upstream/libtemplate-provider-encoding-perl/current/t/utf-8-bom.tt
URL: http://svn.debian.org/wsvn/branches/upstream/libtemplate-provider-encoding-perl/current/t/utf-8-bom.tt?rev=19759&op=file
==============================================================================
--- branches/upstream/libtemplate-provider-encoding-perl/current/t/utf-8-bom.tt (added)
+++ branches/upstream/libtemplate-provider-encoding-perl/current/t/utf-8-bom.tt Fri May 9 13:03:56 2008
@@ -1,0 +1,3 @@
+ãããã®åå㯠[% author %] ã§ãã
+ããã㯠[% my.place %] ã«ããã§ãã¾ãã
+encoding=[% encoding %]
Added: branches/upstream/libtemplate-provider-encoding-perl/current/t/utf-8-wo-encoding.tt
URL: http://svn.debian.org/wsvn/branches/upstream/libtemplate-provider-encoding-perl/current/t/utf-8-wo-encoding.tt?rev=19759&op=file
==============================================================================
--- branches/upstream/libtemplate-provider-encoding-perl/current/t/utf-8-wo-encoding.tt (added)
+++ branches/upstream/libtemplate-provider-encoding-perl/current/t/utf-8-wo-encoding.tt Fri May 9 13:03:56 2008
@@ -1,0 +1,4 @@
+ãããã®åå㯠[% author %] ã§ãã
+ããã㯠[% my.place %] ã«ããã§ãã¾ãã
+
+
Added: branches/upstream/libtemplate-provider-encoding-perl/current/t/utf-8.tt
URL: http://svn.debian.org/wsvn/branches/upstream/libtemplate-provider-encoding-perl/current/t/utf-8.tt?rev=19759&op=file
==============================================================================
--- branches/upstream/libtemplate-provider-encoding-perl/current/t/utf-8.tt (added)
+++ branches/upstream/libtemplate-provider-encoding-perl/current/t/utf-8.tt Fri May 9 13:03:56 2008
@@ -1,0 +1,4 @@
+[% USE encoding 'utf-8' -%]
+ãããã®åå㯠[% author %] ã§ãã
+ããã㯠[% my.place %] ã«ããã§ãã¾ãã
+encoding=[% encoding %]
More information about the Pkg-perl-cvs-commits
mailing list