r2528 - in packages: . libtemplate-multilingual-perl libtemplate-multilingual-perl/branches libtemplate-multilingual-perl/branches/upstream libtemplate-multilingual-perl/branches/upstream/current libtemplate-multilingual-perl/branches/upstream/current/lib libtemplate-multilingual-perl/branches/upstream/current/lib/Template libtemplate-multilingual-perl/branches/upstream/current/lib/Template/Multilingual libtemplate-multilingual-perl/branches/upstream/current/t

gregor herrmann gregoa-guest at costa.debian.org
Sun Apr 9 13:06:52 UTC 2006


Author: gregoa-guest
Date: 2006-04-09 13:06:51 +0000 (Sun, 09 Apr 2006)
New Revision: 2528

Added:
   packages/libtemplate-multilingual-perl/
   packages/libtemplate-multilingual-perl/branches/
   packages/libtemplate-multilingual-perl/branches/upstream/
   packages/libtemplate-multilingual-perl/branches/upstream/current/
   packages/libtemplate-multilingual-perl/branches/upstream/current/Build.PL
   packages/libtemplate-multilingual-perl/branches/upstream/current/Changes
   packages/libtemplate-multilingual-perl/branches/upstream/current/MANIFEST
   packages/libtemplate-multilingual-perl/branches/upstream/current/META.yml
   packages/libtemplate-multilingual-perl/branches/upstream/current/Makefile.PL
   packages/libtemplate-multilingual-perl/branches/upstream/current/README
   packages/libtemplate-multilingual-perl/branches/upstream/current/SIGNATURE
   packages/libtemplate-multilingual-perl/branches/upstream/current/lib/
   packages/libtemplate-multilingual-perl/branches/upstream/current/lib/Template/
   packages/libtemplate-multilingual-perl/branches/upstream/current/lib/Template/Multilingual.pm
   packages/libtemplate-multilingual-perl/branches/upstream/current/lib/Template/Multilingual/
   packages/libtemplate-multilingual-perl/branches/upstream/current/lib/Template/Multilingual/Parser.pm
   packages/libtemplate-multilingual-perl/branches/upstream/current/t/
   packages/libtemplate-multilingual-perl/branches/upstream/current/t/00-load.t
   packages/libtemplate-multilingual-perl/branches/upstream/current/t/basic.t
   packages/libtemplate-multilingual-perl/branches/upstream/current/t/pod.t
   packages/libtemplate-multilingual-perl/branches/upstream/current/t/podcover.t
   packages/libtemplate-multilingual-perl/branches/upstream/current/t/tags.t
   packages/libtemplate-multilingual-perl/tags/
Log:
[svn-inject] Installing original source of libtemplate-multilingual-perl

Added: packages/libtemplate-multilingual-perl/branches/upstream/current/Build.PL
===================================================================
--- packages/libtemplate-multilingual-perl/branches/upstream/current/Build.PL	2006-04-09 10:15:54 UTC (rev 2527)
+++ packages/libtemplate-multilingual-perl/branches/upstream/current/Build.PL	2006-04-09 13:06:51 UTC (rev 2528)
@@ -0,0 +1,18 @@
+use strict;
+use warnings;
+use Module::Build;
+
+my $builder = Module::Build->new(
+    module_name         => 'Template::Multilingual',
+    license             => 'perl',
+    dist_author         => 'Eric Cholet <cholet at logilune.com>',
+    dist_version_from   => 'lib/Template/Multilingual.pm',
+    requires => {
+        'Test::More' => 0,
+        'Template'   => 2,
+    },
+    add_to_cleanup      => [ 'Template-Multilingual-*' ],
+    sign                => 1,
+);
+
+$builder->create_build_script();

Added: packages/libtemplate-multilingual-perl/branches/upstream/current/Changes
===================================================================
--- packages/libtemplate-multilingual-perl/branches/upstream/current/Changes	2006-04-09 10:15:54 UTC (rev 2527)
+++ packages/libtemplate-multilingual-perl/branches/upstream/current/Changes	2006-04-09 13:06:51 UTC (rev 2528)
@@ -0,0 +1,28 @@
+Revision history for Template-Multilingual
+
+0.06    2005-10-31
+        add support for TAG_STYLE, START_TAG and END_TAG template options,
+          thanks to Birgit Kellner for pointing this out.
+        Template::Multilingual::Parser::sections() is now correctly
+          documented
+
+0.05    2005-06-17
+        more robust parsing; text within <t>...</t> but outside
+          any <lang>..</lang> is now ignored
+        add Test::Pod and Test::Pod::Coverage tests
+        improve Template::Multilingual::Parser documentation
+        
+0.04    2005-05-06
+        add GPG signature using Module::Signature
+
+0.03    2005-05-18
+        LANGUAGE_VAR option selects name of language template variable
+
+0.02    2005-04-11
+        Language codes are now matched by <\w+> (previously <[a-z]{2}>)
+        Improve test coverage
+        Fix/improve pod
+
+0.01    2005-04-10
+        First version, released on an unsuspecting world.
+

Added: packages/libtemplate-multilingual-perl/branches/upstream/current/MANIFEST
===================================================================
--- packages/libtemplate-multilingual-perl/branches/upstream/current/MANIFEST	2006-04-09 10:15:54 UTC (rev 2527)
+++ packages/libtemplate-multilingual-perl/branches/upstream/current/MANIFEST	2006-04-09 13:06:51 UTC (rev 2528)
@@ -0,0 +1,14 @@
+Build.PL
+Changes
+lib/Template/Multilingual.pm
+lib/Template/Multilingual/Parser.pm
+Makefile.PL
+MANIFEST			This list of files
+META.yml
+README
+t/00-load.t
+t/basic.t
+t/pod.t
+t/podcover.t
+t/tags.t
+SIGNATURE    Added here by Module::Build

Added: packages/libtemplate-multilingual-perl/branches/upstream/current/META.yml
===================================================================
--- packages/libtemplate-multilingual-perl/branches/upstream/current/META.yml	2006-04-09 10:15:54 UTC (rev 2527)
+++ packages/libtemplate-multilingual-perl/branches/upstream/current/META.yml	2006-04-09 13:06:51 UTC (rev 2528)
@@ -0,0 +1,18 @@
+---
+name: Template-Multilingual
+version: 0.06
+author:
+  - Eric Cholet <cholet at logilune.com>
+abstract: Multilingual templates for Template Toolkit
+license: perl
+requires:
+  Template: 2
+  Test::More: 0
+provides:
+  Template::Multilingual:
+    file: lib/Template/Multilingual.pm
+    version: 0.06
+  Template::Multilingual::Parser:
+    file: lib/Template/Multilingual/Parser.pm
+    version: 0.06
+generated_by: Module::Build version 0.2609

Added: packages/libtemplate-multilingual-perl/branches/upstream/current/Makefile.PL
===================================================================
--- packages/libtemplate-multilingual-perl/branches/upstream/current/Makefile.PL	2006-04-09 10:15:54 UTC (rev 2527)
+++ packages/libtemplate-multilingual-perl/branches/upstream/current/Makefile.PL	2006-04-09 13:06:51 UTC (rev 2528)
@@ -0,0 +1,18 @@
+use strict;
+use warnings;
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+    (MM->can('signature_target') ? (SIGN => 1) : ()),
+    NAME                => 'Template::Multilingual',
+    AUTHOR              => 'Eric Cholet <cholet at logilune.com>',
+    VERSION_FROM        => 'lib/Template/Multilingual.pm',
+    ABSTRACT_FROM       => 'lib/Template/Multilingual.pm',
+    PL_FILES            => {},
+    PREREQ_PM => {
+        'Test::More' => 0,
+        'Template'   => 2,
+    },
+    dist                => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+    clean               => { FILES => 'Template-Multilingual-*' },
+);

Added: packages/libtemplate-multilingual-perl/branches/upstream/current/README
===================================================================
--- packages/libtemplate-multilingual-perl/branches/upstream/current/README	2006-04-09 10:15:54 UTC (rev 2527)
+++ packages/libtemplate-multilingual-perl/branches/upstream/current/README	2006-04-09 13:06:51 UTC (rev 2528)
@@ -0,0 +1,54 @@
+$Id: README,v 1.1 2005/04/10 16:56:51 eric Exp $
+
+--------
+Abstract
+--------
+
+This subclass of Template Toolkit supports multilingual templates: templates that
+contain text in several languages.
+
+    <t>
+      <en>Hello!</en>
+      <fr>Bonjour !</fr>
+    </t>
+
+Then specify the language to use when processing a template:
+
+    use Template::Multilingual;
+
+    my $template = Template::Multilingual->new();
+    $template->language('en');
+    $template->process('example.ttml');
+
+------------
+Requirements
+------------
+
+This module requires Template Toolkit.
+
+------------
+Installation
+------------
+
+To install this module, run the following commands:
+
+    perl Makefile.PL
+    make
+    make test
+    make install
+
+
+Alternatively, to install with Module::Build, you can use the following commands:
+
+    perl Build.PL
+    ./Build
+    ./Build test
+    ./Build install
+
+
+COPYRIGHT AND LICENCE
+
+Copyright (C) 2005 Eric Cholet
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.

Added: packages/libtemplate-multilingual-perl/branches/upstream/current/SIGNATURE
===================================================================
--- packages/libtemplate-multilingual-perl/branches/upstream/current/SIGNATURE	2006-04-09 10:15:54 UTC (rev 2527)
+++ packages/libtemplate-multilingual-perl/branches/upstream/current/SIGNATURE	2006-04-09 13:06:51 UTC (rev 2528)
@@ -0,0 +1,36 @@
+This file contains message digests of all files listed in MANIFEST,
+signed via the Module::Signature module, version 0.50.
+
+To verify the content in this distribution, first make sure you have
+Module::Signature installed, then type:
+
+    % cpansign -v
+
+It will check each file's integrity, as well as the signature's
+validity.  If "==> Signature verified OK! <==" is not displayed,
+the distribution may already have been compromised, and you should
+not run its Makefile.PL or Build.PL.
+
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA1
+
+SHA1 13ee0423140a5c3afc61ea6cd41af158bc13c473 Build.PL
+SHA1 69df887f6c802a0344bd174eb82f083003ad2efb Changes
+SHA1 11cd2b1b8714099d99dbb34d32d1214ab80a9322 MANIFEST
+SHA1 06b849480e1c2eb72f33e6da606d26f24d523a43 META.yml
+SHA1 af99d3fcf0fd2ec5eeb23dffcbe7fae2eb044afa Makefile.PL
+SHA1 141c6a1befd18d4f5dbbb24696a231153d09efc6 README
+SHA1 d2f93e77caced184d852afea494f0edaaa62193d lib/Template/Multilingual.pm
+SHA1 dc92a60773ab7006f3306aee453a0d3865f9731c lib/Template/Multilingual/Parser.pm
+SHA1 7538b82ddcfa40917b509e02f244a04ac86f6a84 t/00-load.t
+SHA1 6457ef7762f7a59f229d7a68494f2d2fe3c862bc t/basic.t
+SHA1 0190346d7072d458c8a10a45c19f86db641dcc48 t/pod.t
+SHA1 6da39b48ce64b584e4c3274bff96fc76ff484820 t/podcover.t
+SHA1 80809fbda18eb2f875ca27bd8474b3360c1af861 t/tags.t
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.2.4 (Darwin)
+
+iD8DBQFDZiQAVZHiwGZkwHgRAnqZAJ9q6iss66gyMOJGR0Y2G3LeAPOvHACeJ45T
+4PEo0CdBqKjqltZoyV5tBHk=
+=h1dz
+-----END PGP SIGNATURE-----

Added: packages/libtemplate-multilingual-perl/branches/upstream/current/lib/Template/Multilingual/Parser.pm
===================================================================
--- packages/libtemplate-multilingual-perl/branches/upstream/current/lib/Template/Multilingual/Parser.pm	2006-04-09 10:15:54 UTC (rev 2527)
+++ packages/libtemplate-multilingual-perl/branches/upstream/current/lib/Template/Multilingual/Parser.pm	2006-04-09 13:06:51 UTC (rev 2528)
@@ -0,0 +1,199 @@
+package Template::Multilingual::Parser;
+
+use strict;
+use base qw(Template::Parser);
+
+our $VERSION = '0.06';
+
+sub new
+{
+    my ($class, $options) = @_;
+    my $self = $class->SUPER::new($options);
+    $self->{_sections} = [];
+    $self->{_langvar} = $options->{LANGUAGE_VAR} || 'language';
+
+    my $style = $self->{ STYLE }->[-1];
+    @$self{ qw(_start _end) } = @$style{ qw( START_TAG END_TAG  ) };
+    for (qw( _start _end )) {
+        $self->{$_} =~ s/\\([^\\])/$1/g;
+    }
+
+    return $self;
+}
+
+sub parse
+{
+    my ($self, $text) = @_;
+
+    # isolate multilingual sections
+    $self->_tokenize($text);
+
+    # replace multilingual sections with TT directives
+    $text = '';
+    for my $section (@{$self->{_sections}}) {
+        if ($section->{nolang}) {
+            $text .= $section->{nolang};
+        }
+        elsif (my $t = $section->{lang}) {
+            $text .= "$self->{_start} SWITCH $self->{_langvar} $self->{_end}";
+            for my $lang (keys %$t) {
+                $text .= "$self->{_start} CASE '$lang' $self->{_end}" . $t->{$lang};
+            }
+            $text .= "$self->{_start} END $self->{_end}";
+        }
+    }
+    return $self->SUPER::parse ($text);
+}
+
+sub _tokenize
+{
+    my ($self, $text) = @_;
+
+    # extract all sections from the text
+    $self->{_sections} = [];
+    my @tokens = split m!<t>(.*?)</t>!s, $text;
+    my $i = 0;
+    for my $t (@tokens) {
+        if ($i) {             # <t>...</t> multilingual section
+            my %section;
+            while ($t =~ m!<(\w+)>(.*?)</\1>!gs) {
+                $section{$1} = $2;
+            }
+            push @{$self->{_sections}}, { lang => \%section }
+                if %section;
+        }
+        else {                # bare text
+            push @{$self->{_sections}}, { nolang => $t } if $t;
+        }
+        $i = 1 - $i;
+    }
+}
+sub sections { $_[0]->{_sections} }
+
+=head1 NAME
+
+Template::Multilingual::Parser - Multilingual template parser
+
+=head1 SYNOPSIS
+
+    use Template;
+    use Template::Multilingual::Parser;
+  
+    my $parser = Template::Multilingual::Parser->new();
+    my $template = Template->new(PARSER => $parser);
+    $template->process('example.ttml', { language => 'en'});
+
+=head1 DESCRIPTION
+
+This subclass of Template Toolkit's C<Template::Parser> parses multilingual
+templates: templates that contain text in several languages.
+
+    <t>
+      <en>Hello!</en>
+      <fr>Bonjour !</fr>
+    </t>
+
+Use this module directly if you have subclassed C<Template>, otherwise you
+may find it easier to use C<Template::Multilingual>.
+
+Language codes can be any string that matches C<\w+>, but we suggest
+sticking to ISO-639 which provides 2-letter codes for common languages
+and 3-letter codes for many others.
+
+=head1 METHODS
+
+=head2 new(\%params)
+
+The new() constructor creates and returns a reference to a new
+parser object. A reference to a hash may be supplied as a
+parameter to provide configuration values.
+
+Parser objects are typically provided as the C<PARSER> option
+to the C<Template> constructor.
+
+Configuration values are all valid C<Template::Parser> superclass
+options, and one specific to this class:
+
+=over
+
+=item LANGUAGE_VAR
+
+The LANGUAGE_VAR option can be used to set the name of the template
+variable which contains the current language. Defaults to
+I<language>.
+
+  my $parser = Template::Multilingual::Parser->new({
+     LANGUAGE_VAR => 'global.language',
+  });
+
+You will need to set this variable with the current language value
+at request time, usually in your C<Template> subclass' C<process()>
+method.
+
+=back
+
+=head2 parse($text)
+
+parse() is called by the Template Toolkit. It parses multilingual
+sections from the input text and translates them to Template Toolkit
+directives. The result is then passed to the C<Template::Parser> superclass.
+
+=head2 sections
+
+Returns a reference to an array of tokenized sections. Each section is a
+reference to hash with either a C<nolang> key or a C<lang> key.
+
+A C<nolang> key denotes text outside of any multilingual sections. The value
+is the text itself.
+
+A C<lang> key denotes text inside a multilingual section. The value is a
+reference to a hash, whose keys are language codes and values the corresponding
+text. For example, the following multilingual template:
+
+  foo <t><fr>bonjour</fr><en>Hello</en></t> bar
+
+will parse to the following sections:
+
+  [ { nolang => 'foo ' },
+    {   lang => { fr => 'bonjour', en => 'hello' } },
+    { nolang => ' bar' },
+  ]
+
+=head1 BUGS
+
+Multilingual text sections cannot be used inside TT directives.
+The following is illegal and will trigger a TT syntax error:
+
+    [% title = "<t><fr>Bonjour</fr><en>Hello</en></t>" %]
+
+Use this instead:
+
+    [% title = BLOCK %]<t><fr>Bonjour</fr><en>Hello</en></t>[% END %]
+
+
+The TAG_STYLE, START_TAG and END_TAG directives are supported, but the
+TAGS directive is not.
+
+Please report any bugs or feature requests to
+C<bug-template-multilingual at rt.cpan.org>, or through the web interface at
+L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Template-Multilingual>.
+I will be notified, and then you'll automatically be notified of progress on
+your bug as I make changes.
+
+=head1 SEE ALSO
+
+L<Template::Multilingual>
+
+ISO 639-2 Codes for the Representation of Names of Languages:
+http://www.loc.gov/standards/iso639-2/langcodes.html
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2005 Eric Cholet, All Rights Reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+1; # End of Template::Multilingual::Parser

Added: packages/libtemplate-multilingual-perl/branches/upstream/current/lib/Template/Multilingual.pm
===================================================================
--- packages/libtemplate-multilingual-perl/branches/upstream/current/lib/Template/Multilingual.pm	2006-04-09 10:15:54 UTC (rev 2527)
+++ packages/libtemplate-multilingual-perl/branches/upstream/current/lib/Template/Multilingual.pm	2006-04-09 13:06:51 UTC (rev 2528)
@@ -0,0 +1,146 @@
+package Template::Multilingual;
+
+use strict;
+use base qw(Template);
+use Template::Multilingual::Parser;
+
+our $VERSION = '0.06';
+
+sub _init
+{
+    my ($self, $options) = @_;
+
+    $self->{LANGUAGE_VAR} = $options->{LANGUAGE_VAR};
+    $options->{LANGUAGE_VAR} ||= 'language';
+    $options->{PARSER} = Template::Multilingual::Parser->new($options);
+    $self->{PARSER} = $options->{PARSER};
+    $self->SUPER::_init($options)
+}
+sub language
+{
+    my $self = shift;
+    @_ ? $self->{language} = shift
+       : $self->{language};
+}
+sub process
+{
+    my ($self, $filename, $vars, @args) = @_;
+    unless ($self->{LANGUAGE_VAR}) {
+        $vars ||= {};
+        $vars->{language} = $self->{language}
+    }
+    $self->SUPER::process($filename, $vars, @args);
+}
+
+=head1 NAME
+
+Template::Multilingual - Multilingual templates for Template Toolkit
+
+=head1 SYNOPSIS
+
+This subclass of Template Toolkit's C<Template> class supports multilingual
+templates: templates that contain text in several languages.
+
+    <t>
+      <en>Hello!</en>
+      <fr>Bonjour !</fr>
+    </t>
+
+Specify the language to use when processing a template:
+
+    use Template::Multilingual;
+
+    my $template = Template::Multilingual->new();
+    $template->language('en');
+    $template->process('example.ttml');
+
+You can also provide the name of the template variable that will
+hold the language:
+
+    my $template = Template::Multilingual->new(LANGUAGE_VAR => 'foo');
+    $template->process('example.ttml', { foo => 'en' });
+
+=head1 METHODS
+
+=head2 new(\%params)
+
+The new() constructor creates and returns a reference to a new
+template object. A reference to a hash may be supplied as a
+parameter to provide configuration values.
+
+Configuration values are all valid C<Template> superclass options,
+and one specific to this class:
+
+=over
+
+=item LANGUAGE_VAR
+
+The LANGUAGE_VAR option can be used to set the name of the template
+variable which contains the current language.
+
+  my $parser = Template::Multilingual::Parser->new({
+     LANGUAGE_VAR => 'global.language',
+  });
+
+If this option is set, you code is responsible for setting the
+variable's value to the current language when processing the
+template. Calling C<language()> will have no effect.
+
+If this option is not set, it defaults to I<language>.
+
+=back
+
+=head2 language($lcode)
+
+Specify the language to be used when processing the template. Any string that
+matches C<\w+> is fine, but we suggest sticking to ISO-639 which provides
+2-letter codes for common languages and 3-letter codes for many others.
+
+=head2 process
+
+Used exactly as the original Template Toolkit C<process> method.
+Be sure to call C<language> before calling C<process>.
+
+=head1 AUTHOR
+
+Eric Cholet, C<< <cholet at logilune.com> >>
+
+=head1 BUGS
+
+Multilingual text sections cannot be used inside TT directives.
+The following is illegal and will trigger a TT syntax error:
+
+    [% title = "<t><fr>Bonjour</fr><en>Hello</en></t>" %]
+
+Use this instead:
+
+    [% title = BLOCK %]<t><fr>Bonjour</fr><en>Hello</en></t>[% END %]
+
+
+The TAG_STYLE, START_TAG and END_TAG directives are supported, but the
+TAGS directive is not.
+
+Please report any bugs or feature requests to
+C<bug-template-multilingual at rt.cpan.org>, or through the web interface at
+L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Template-Multilingual>.
+I will be notified, and then you'll automatically be notified of progress on
+your bug as I make changes.
+
+=head1 SEE ALSO
+
+If you are already using your own C<Template> subclass, you may find it
+easier to use L<Template::Multilingual::Parser> instead.
+
+ISO 639-2 Codes for the Representation of Names of Languages:
+http://www.loc.gov/standards/iso639-2/langcodes.html
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2005 Eric Cholet, All Rights Reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+1; # End of Template::Multilingual

Added: packages/libtemplate-multilingual-perl/branches/upstream/current/t/00-load.t
===================================================================
--- packages/libtemplate-multilingual-perl/branches/upstream/current/t/00-load.t	2006-04-09 10:15:54 UTC (rev 2527)
+++ packages/libtemplate-multilingual-perl/branches/upstream/current/t/00-load.t	2006-04-09 13:06:51 UTC (rev 2528)
@@ -0,0 +1,5 @@
+use Test::More tests => 1;
+
+BEGIN {
+use_ok( 'Template::Multilingual' );
+}

Added: packages/libtemplate-multilingual-perl/branches/upstream/current/t/basic.t
===================================================================
--- packages/libtemplate-multilingual-perl/branches/upstream/current/t/basic.t	2006-04-09 10:15:54 UTC (rev 2527)
+++ packages/libtemplate-multilingual-perl/branches/upstream/current/t/basic.t	2006-04-09 13:06:51 UTC (rev 2528)
@@ -0,0 +1,90 @@
+#!perl -w
+
+use strict;
+
+my @templates = (
+    { in  => '',
+      out => '',
+      sections => [ ],
+    },
+    { in  => 'foo',
+      out => 'foo',
+      sections => [ { nolang => 'foo' } ],
+    },
+    { in  => '<t></t>',
+      out => '',
+      sections => [ ],
+    },
+    {
+      in  => '<t><fr>foo</fr></t>',
+      out => 'foo',
+      sections => [ { lang => { fr => 'foo' } } ],
+    },
+    {
+      in  => '<t><en>foo</en></t>',
+      out => '',
+      sections => [ { lang => { en => 'foo' } } ],
+    },
+    {
+      in  => "<t><fr>foo</fr>\n<en>bar</en></t>",
+      out => "foo",
+      sections => [ { lang => { fr => 'foo', en => 'bar' } } ],
+    },
+    {
+      lang =>'en',
+      in  => '<t><fr>foo</fr></t>',
+      out => '',
+      sections => [ { lang => { fr => 'foo' } } ],
+    },
+    {
+      lang => 'en',
+      in  => '<t><en>foo</en></t>',
+      out => 'foo',
+      sections => [ { lang => { en => 'foo' } } ],
+    },
+    {
+      lang => 'eng',
+      in  => "<t><fra>foo</fra>\n<eng>bar</eng></t>",
+      out => 'bar',
+      sections => [ { lang => { fra => 'foo', eng => 'bar' } } ],
+    },
+    { # sections
+      in  => "A<t><fr>foo</fr></t>B<t><en>bar</en></t>C",
+      out => 'AfooBC',
+      sections => [ { nolang => 'A' },
+                    {   lang => { fr => 'foo' } },
+                    { nolang => 'B' },
+                    {   lang => { en => 'bar' } },
+                    { nolang => 'C' },
+                  ],
+    },
+);
+use Test::More;
+plan tests => 3 + 7 * @templates;
+
+require_ok('Template::Multilingual');
+my $template = Template::Multilingual->new;
+ok($template);
+
+for my $t (@templates) {
+    my $lang = $t->{lang} || 'fr';
+    $template->language($lang);
+    is($template->language, $lang, "get/set language");
+    my $output;
+    ok($template->process(\$t->{in}, {}, \$output), 'process');
+    is($output, $t->{out}, 'output');
+    is_deeply($template->{PARSER}->sections, $t->{sections}, 'sections');
+}
+
+$template = Template::Multilingual->new(LANGUAGE_VAR => 'global.language');
+ok($template);
+
+for my $t (@templates) {
+    my $lang = $t->{lang} || 'fr';
+    my $output;
+    ok($template->process(\$t->{in}, { global => { language => $lang }}, \$output), 'process');
+    is($output, $t->{out}, 'output');
+    is_deeply($template->{PARSER}->sections, $t->{sections}, 'sections');
+}
+
+__END__

Added: packages/libtemplate-multilingual-perl/branches/upstream/current/t/pod.t
===================================================================
--- packages/libtemplate-multilingual-perl/branches/upstream/current/t/pod.t	2006-04-09 10:15:54 UTC (rev 2527)
+++ packages/libtemplate-multilingual-perl/branches/upstream/current/t/pod.t	2006-04-09 13:06:51 UTC (rev 2528)
@@ -0,0 +1,6 @@
+#!perl -T
+
+use Test::More;
+eval "use Test::Pod 1.14";
+plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
+all_pod_files_ok();

Added: packages/libtemplate-multilingual-perl/branches/upstream/current/t/podcover.t
===================================================================
--- packages/libtemplate-multilingual-perl/branches/upstream/current/t/podcover.t	2006-04-09 10:15:54 UTC (rev 2527)
+++ packages/libtemplate-multilingual-perl/branches/upstream/current/t/podcover.t	2006-04-09 13:06:51 UTC (rev 2528)
@@ -0,0 +1,6 @@
+#!perl -T
+
+use Test::More;
+eval "use Test::Pod::Coverage 1.04";
+plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@;
+all_pod_coverage_ok();

Added: packages/libtemplate-multilingual-perl/branches/upstream/current/t/tags.t
===================================================================
--- packages/libtemplate-multilingual-perl/branches/upstream/current/t/tags.t	2006-04-09 10:15:54 UTC (rev 2527)
+++ packages/libtemplate-multilingual-perl/branches/upstream/current/t/tags.t	2006-04-09 13:06:51 UTC (rev 2528)
@@ -0,0 +1,34 @@
+#!perl -w
+
+use strict;
+
+my %test = (
+    in  => '<t><fr>foo</fr></t>',
+    out => 'foo',
+    sections => [ { lang => { fr => 'foo' } } ],
+);
+use Test::More tests => 9;
+
+require_ok('Template::Multilingual');
+my $template = Template::Multilingual->new(
+  TAG_STYLE => 'star',
+);
+ok($template);
+
+$template->language('fr');
+my $output;
+ok($template->process(\$test{in}, {}, \$output), 'process');
+is($output, $test{out}, 'output');
+is_deeply($template->{PARSER}->sections, $test{sections}, 'sections');
+
+
+$template = Template::Multilingual->new(
+    START_TAG => quotemeta('<+'),
+    END_TAG   => quotemeta('+>'),
+);
+ok($template);
+ok($template->process(\$test{in}, {}, \$output), 'process');
+is($output, $test{out}, 'output');
+is_deeply($template->{PARSER}->sections, $test{sections}, 'sections');
+
+__END__




More information about the Pkg-perl-cvs-commits mailing list