@@ -0,0 +1,26 @@
+Revision history for Template-Plugin-Autoformat
+
+2.76 - 5 Jan 2014
+ - tests patched to fix some locales (https://rt.cpan.org/Ticket/Display.html?id=99972)
+
+2.75 - 9 May 2014
+ - official release, no code change from 2.74_04
+
+2.74_04 - 7 May 2014
+ - tweek tests to reflect sprintf rounding differences on some machines
+
+2.74_03 - 6 May 2014
+ - port tests to Test::More to get better diagnostics from cpantesters
+
+2.74_02 - 2 May 2014
+ - attempt to address failing test 10 on some cpantesters
+
+2.74_01 - 1 May 2014
+ - Peter Karman took over maintenance.
+ - repo started at https://github.com/karpet/template-plugin-autoformat
+ - fixed failing tests, switching to standard initial-cap for plugin name
+ before: USE autoformat
+ after : USE Autoformat
+
+2.71 - 15 Dec 2008
+ - split out of core into its own distribution. No Changes file in this release or prior.
@@ -1,6 +1,9 @@
+Changes
lib/Template/Plugin/Autoformat.pm
Makefile.PL
MANIFEST This list of files
+META.yml Module meta-data (added by MakeMaker)
README
+t/001-autoformat.t
t/autoform.t
-META.yml Module meta-data (added by MakeMaker)
+META.json Module JSON meta-data (added by MakeMaker)
@@ -0,0 +1,54 @@
+{
+ "abstract" : "TT plugin for Text::Autoformat",
+ "author" : [
+ "Andy Wardley <abw@wardley.org>"
+ ],
+ "dynamic_config" : 1,
+ "generated_by" : "ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.140640",
+ "license" : [
+ "perl_5"
+ ],
+ "meta-spec" : {
+ "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
+ "version" : "2"
+ },
+ "name" : "Template-Plugin-Autoformat",
+ "no_index" : {
+ "directory" : [
+ "t",
+ "inc"
+ ]
+ },
+ "prereqs" : {
+ "build" : {
+ "requires" : {
+ "ExtUtils::MakeMaker" : "0"
+ }
+ },
+ "configure" : {
+ "requires" : {
+ "ExtUtils::MakeMaker" : "0"
+ }
+ },
+ "runtime" : {
+ "requires" : {
+ "Template" : "2.2",
+ "Text::Autoformat" : "1.13"
+ }
+ }
+ },
+ "release_status" : "stable",
+ "resources" : {
+ "bugtracker" : {
+ "web" : "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Template-Plugin-Autoformat"
+ },
+ "homepage" : "https://github.com/karpet/template-plugin-autoformat",
+ "license" : [
+ "http://dev.perl.org/licenses/"
+ ],
+ "repository" : {
+ "url" : "https://github.com/karpet/template-plugin-autoformat"
+ }
+ },
+ "version" : "2.76"
+}
@@ -1,21 +1,28 @@
---- #YAML:1.0
-name: Template-Plugin-Autoformat
-version: 2.71
-abstract: TT plugin for Text::Autoformat
+---
+abstract: 'TT plugin for Text::Autoformat'
author:
- - Andy Wardley <abw@wardley.org>
-license: perl
-distribution_type: module
+ - 'Andy Wardley <abw@wardley.org>'
+build_requires:
+ ExtUtils::MakeMaker: '0'
configure_requires:
- ExtUtils::MakeMaker: 0
-requires:
- Template: 2.2
- Text::Autoformat: 1.13
-no_index:
- directory:
- - t
- - inc
-generated_by: ExtUtils::MakeMaker version 6.46
+ ExtUtils::MakeMaker: '0'
+dynamic_config: 1
+generated_by: 'ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.140640'
+license: perl
meta-spec:
- url: http://module-build.sourceforge.net/META-spec-v1.4.html
- version: 1.4
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: '1.4'
+name: Template-Plugin-Autoformat
+no_index:
+ directory:
+ - t
+ - inc
+requires:
+ Template: '2.2'
+ Text::Autoformat: '1.13'
+resources:
+ bugtracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=Template-Plugin-Autoformat
+ homepage: https://github.com/karpet/template-plugin-autoformat
+ license: http://dev.perl.org/licenses/
+ repository: https://github.com/karpet/template-plugin-autoformat
+version: '2.76'
@@ -7,27 +7,39 @@ use ExtUtils::MakeMaker;
my %opts = (
'NAME' => 'Template-Plugin-Autoformat',
'VERSION_FROM' => 'lib/Template/Plugin/Autoformat.pm',
- 'PMLIBDIRS' => [ 'lib' ],
- 'PREREQ_PM' => {
+ 'PMLIBDIRS' => ['lib'],
+ 'PREREQ_PM' => {
'Template' => 2.20,
'Text::Autoformat' => 1.13,
},
- 'dist' => {
+ 'dist' => {
'COMPRESS' => 'gzip',
'SUFFIX' => 'gz',
},
- 'test' => {
- 'TESTS' => 't/autoform.t',
- },
+ 'clean' => { FILES => 'Template-Plugin-Autoformat-*tar.gz' },
);
-if ($ExtUtils::MakeMaker::VERSION >= 5.43) {
- $opts{ AUTHOR } = 'Andy Wardley <abw@wardley.org>';
- $opts{ ABSTRACT } = 'TT plugin for Text::Autoformat',
+if ( $ExtUtils::MakeMaker::VERSION >= 5.43 ) {
+ $opts{AUTHOR} = 'Andy Wardley <abw@wardley.org>';
+ $opts{ABSTRACT} = 'TT plugin for Text::Autoformat',;
+}
+
+if ( $ExtUtils::MakeMaker::VERSION ge '6.30_00' ) {
+ $opts{'LICENSE'} = 'perl';
}
-if ($ExtUtils::MakeMaker::VERSION ge '6.30_00') {
- $opts{'LICENSE' } = 'perl';
-}
+if ( $ExtUtils::MakeMaker::VERSION ge '6.44' ) {
+ $opts{'META_MERGE'} = {
+ resources => {
+ license => 'http://dev.perl.org/licenses/',
+ homepage =>
+ 'https://github.com/karpet/template-plugin-autoformat',
+ bugtracker =>
+ 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=Template-Plugin-Autoformat',
+ repository =>
+ 'https://github.com/karpet/template-plugin-autoformat',
+ },
+ };
+}
-WriteMakefile( %opts );
+WriteMakefile(%opts);
@@ -2,11 +2,11 @@ NAME
Template::Plugin::Autoformat - Interface to Text::Autoformat module
SYNOPSIS
- [% USE autoformat(options) %]
+ [% USE Autoformat(options) %]
- [% autoformat(text, more_text, ..., options) %]
+ [% Autoformat(text, more_text, ..., options) %]
- [% FILTER autoformat(options) %]
+ [% FILTER Autoformat(options) %]
a block of text
[% END %]
@@ -18,40 +18,40 @@ EXAMPLES
[% END %]
# pass options to constructor...
- [% USE autoformat(case => 'upper') %]
- [% autoformat(text) %]
+ [% USE Autoformat(case => 'upper') %]
+ [% Autoformat(text) %]
- # and/or pass options to the autoformat subroutine itself
- [% USE autoformat %]
- [% autoformat(text, case => 'upper') %]
+ # and/or pass options to the Autoformat subroutine itself
+ [% USE Autoformat %]
+ [% Autoformat(text, case => 'upper') %]
- # using the autoformat filter
- [% USE autoformat(left => 10, right => 30) %]
- [% FILTER autoformat %]
+ # using the Autoformat filter
+ [% USE Autoformat(left => 10, right => 30) %]
+ [% FILTER Autoformat %]
Be not afeard. The isle is full of noises, sounds and sweet
airs that give delight but hurt not.
[% END %]
# another filter example with configuration options
- [% USE autoformat %]
- [% FILTER autoformat(left => 20) %]
+ [% USE Autoformat %]
+ [% FILTER Autoformat(left => 20) %]
Be not afeard. The isle is full of noises, sounds and sweet
airs that give delight but hurt not.
[% END %]
# another FILTER example, defining a 'poetry' filter alias
- [% USE autoformat %]
- [% text FILTER poetry = autoformat(left => 20, right => 40) %]
+ [% USE Autoformat %]
+ [% text FILTER poetry = Autoformat(left => 20, right => 40) %]
# reuse the 'poetry' filter alias
[% text FILTER poetry %]
# shorthand form ('|' is an alias for 'FILTER')
- [% text | autoformat %]
+ [% text | Autoformat %]
# using forms
- [% USE autoformat(form => '>>>>.<<<', numeric => 'AllPlaces') %]
- [% autoformat(10, 20.32, 11.35) %]
+ [% USE Autoformat(form => '>>>>.<<<', numeric => 'AllPlaces') %]
+ [% Autoformat(10, 20.32, 11.35) %]
DESCRIPTION
This Template Toolkit plugin module is an interface to Damian Conway's
@@ -61,19 +61,19 @@ DESCRIPTION
Configuration options may be passed to the plugin constructor via the
"USE" directive.
- [% USE autoformat(right => 30) %]
+ [% USE Autoformat(right => 30) %]
- The autoformat subroutine can then be called, passing in text items
+ The Autoformat subroutine can then be called, passing in text items
which will be wrapped and formatted according to the current
configuration.
- [% autoformat('The cat sat on the mat') %]
+ [% Autoformat('The cat sat on the mat') %]
- Additional configuration items can be passed to the autoformat
+ Additional configuration items can be passed to the Autoformat
subroutine and will be merged with any existing configuration specified
via the constructor.
- [% autoformat(text, left => 20) %]
+ [% Autoformat(text, left => 20) %]
Configuration options are passed directly to the "Text::Autoformat"
plugin. At the time of writing, the basic configuration items are:
@@ -88,20 +88,20 @@ DESCRIPTION
The plugin also accepts a "form" item which can be used to define a
format string. When a form is defined, the plugin will call the
- underlying "form()" subroutine in preference to "autoformat()".
+ underlying "form()" subroutine in preference to "Autoformat()".
- [% USE autoformat(form => '>>>>.<<') %]
- [% autoformat(123.45, 666, 3.14) %]
+ [% USE Autoformat(form => '>>>>.<<') %]
+ [% Autoformat(123.45, 666, 3.14) %]
Additional configuration items relevant to forms can also be specified.
- [% USE autoformat(form => '>>>>.<<', numeric => 'AllPlaces') %]
- [% autoformat(123.45, 666, 3.14) %]
+ [% USE Autoformat(form => '>>>>.<<', numeric => 'AllPlaces') %]
+ [% Autoformat(123.45, 666, 3.14) %]
- These can also be passed directly to the autoformat subroutine.
+ These can also be passed directly to the Autoformat subroutine.
- [% USE autoformat %]
- [% autoformat( 123.45, 666, 3.14,
+ [% USE Autoformat %]
+ [% Autoformat( 123.45, 666, 3.14,
form => '>>>>.<<',
numeric => 'AllPlaces' )
%]
@@ -116,9 +116,8 @@ AUTHORS
clever stuff.
The module was moved out of the Template Toolkit core and into a
- separate distribution in December 2008. Andy Wardley is the current
- maintainer, but rarely uses the module these days. So if anyone else out
- there wants to take over ownership of it then please get in touch.
+ separate distribution in December 2008. Peter Karman is the current
+ maintainer.
COPYRIGHT
Copyright (C) 2000-2007 Robert McArthur & Andy Wardley. All Rights
@@ -14,7 +14,7 @@
# documentation
#
# COPYRIGHT
-# Copyright (C) 2000-2008 Robert McArthur, Andy Wardley.
+# Copyright (C) 2000-2008 Robert McArthur, Andy Wardley.
# All Rights Reserved.
#
# This module is free software; you can redistribute it and/or
@@ -29,38 +29,39 @@ use warnings;
use base 'Template::Plugin';
use Text::Autoformat;
-our $VERSION = 2.71;
+our $VERSION = '2.76';
sub new {
- my ($class, $context, $options) = @_;
+ my ( $class, $context, $options ) = @_;
my $filter_factory;
my $plugin;
if ($options) {
+
# create a closure to generate filters with additional options
$filter_factory = sub {
my $context = shift;
- my $filtopt = ref $_[-1] eq 'HASH' ? pop : { };
+ my $filtopt = ref $_[-1] eq 'HASH' ? pop : {};
@$filtopt{ keys %$options } = values %$options;
return sub {
- tt_autoformat(@_, $filtopt);
+ tt_autoformat( @_, $filtopt );
};
};
# and a closure to represent the plugin
$plugin = sub {
- my $plugopt = ref $_[-1] eq 'HASH' ? pop : { };
+ my $plugopt = ref $_[-1] eq 'HASH' ? pop : {};
@$plugopt{ keys %$options } = values %$options;
- tt_autoformat(@_, $plugopt);
+ tt_autoformat( @_, $plugopt );
};
}
else {
# simple filter factory closure (no legacy options from constructor)
$filter_factory = sub {
my $context = shift;
- my $filtopt = ref $_[-1] eq 'HASH' ? pop : { };
+ my $filtopt = ref $_[-1] eq 'HASH' ? pop : {};
return sub {
- tt_autoformat(@_, $filtopt);
+ tt_autoformat( @_, $filtopt );
};
};
@@ -69,15 +70,17 @@ sub new {
}
# now define the filter and return the plugin
- $context->define_filter('autoformat', [ $filter_factory => 1 ]);
+ $context->define_filter( 'Autoformat', [ $filter_factory => 1 ] );
return $plugin;
}
sub tt_autoformat {
- my $options = ref $_[-1] eq 'HASH' ? pop : { };
- my $form = $options->{ form };
- my $out = $form ? Text::Autoformat::form($options, $form, @_)
- : Text::Autoformat::autoformat(join('', @_), $options);
+ my $options = ref $_[-1] eq 'HASH' ? pop : {};
+ my $form = $options->{form};
+ my $out
+ = $form
+ ? Text::Autoformat::form( $options, $form, @_ )
+ : Text::Autoformat::autoformat( join( '', @_ ), $options );
return $out;
}
@@ -91,11 +94,11 @@ Template::Plugin::Autoformat - Interface to Text::Autoformat module
=head1 SYNOPSIS
- [% USE autoformat(options) %]
+ [% USE Autoformat(options) %]
- [% autoformat(text, more_text, ..., options) %]
+ [% Autoformat(text, more_text, ..., options) %]
- [% FILTER autoformat(options) %]
+ [% FILTER Autoformat(options) %]
a block of text
[% END %]
@@ -108,40 +111,40 @@ Template::Plugin::Autoformat - Interface to Text::Autoformat module
[% END %]
# pass options to constructor...
- [% USE autoformat(case => 'upper') %]
- [% autoformat(text) %]
+ [% USE Autoformat(case => 'upper') %]
+ [% Autoformat(text) %]
- # and/or pass options to the autoformat subroutine itself
- [% USE autoformat %]
- [% autoformat(text, case => 'upper') %]
+ # and/or pass options to the Autoformat subroutine itself
+ [% USE Autoformat %]
+ [% Autoformat(text, case => 'upper') %]
- # using the autoformat filter
- [% USE autoformat(left => 10, right => 30) %]
- [% FILTER autoformat %]
+ # using the Autoformat filter
+ [% USE Autoformat(left => 10, right => 30) %]
+ [% FILTER Autoformat %]
Be not afeard. The isle is full of noises, sounds and sweet
airs that give delight but hurt not.
[% END %]
# another filter example with configuration options
- [% USE autoformat %]
- [% FILTER autoformat(left => 20) %]
+ [% USE Autoformat %]
+ [% FILTER Autoformat(left => 20) %]
Be not afeard. The isle is full of noises, sounds and sweet
airs that give delight but hurt not.
[% END %]
# another FILTER example, defining a 'poetry' filter alias
- [% USE autoformat %]
- [% text FILTER poetry = autoformat(left => 20, right => 40) %]
+ [% USE Autoformat %]
+ [% text FILTER poetry = Autoformat(left => 20, right => 40) %]
# reuse the 'poetry' filter alias
[% text FILTER poetry %]
# shorthand form ('|' is an alias for 'FILTER')
- [% text | autoformat %]
+ [% text | Autoformat %]
# using forms
- [% USE autoformat(form => '>>>>.<<<', numeric => 'AllPlaces') %]
- [% autoformat(10, 20.32, 11.35) %]
+ [% USE Autoformat(form => '>>>>.<<<', numeric => 'AllPlaces') %]
+ [% Autoformat(10, 20.32, 11.35) %]
=head1 DESCRIPTION
@@ -149,21 +152,25 @@ This L<Template Toolkit|Template> plugin module is an interface to Damian
Conway's C<Text::Autoformat> Perl module which provides advanced text wrapping
and formatting.
+B<NOTE> as of version 2.75 the usage has changed to initial cap C<Autoformat>
+instead of the previous C<autoformat>. This brings it into alignment with
+standard plugin syntax.
+
Configuration options may be passed to the plugin constructor via the
C<USE> directive.
- [% USE autoformat(right => 30) %]
+ [% USE Autoformat(right => 30) %]
-The autoformat subroutine can then be called, passing in text items which
+The Autoformat subroutine can then be called, passing in text items which
will be wrapped and formatted according to the current configuration.
- [% autoformat('The cat sat on the mat') %]
+ [% Autoformat('The cat sat on the mat') %]
-Additional configuration items can be passed to the autoformat subroutine
+Additional configuration items can be passed to the Autoformat subroutine
and will be merged with any existing configuration specified via the
constructor.
- [% autoformat(text, left => 20) %]
+ [% Autoformat(text, left => 20) %]
Configuration options are passed directly to the C<Text::Autoformat> plugin.
At the time of writing, the basic configuration items are:
@@ -178,20 +185,20 @@ At the time of writing, the basic configuration items are:
The plugin also accepts a C<form> item which can be used to define a
format string. When a form is defined, the plugin will call the
-underlying C<form()> subroutine in preference to C<autoformat()>.
+underlying C<form()> subroutine in preference to C<Autoformat()>.
- [% USE autoformat(form => '>>>>.<<') %]
- [% autoformat(123.45, 666, 3.14) %]
+ [% USE Autoformat(form => '>>>>.<<') %]
+ [% Autoformat(123.45, 666, 3.14) %]
Additional configuration items relevant to forms can also be specified.
- [% USE autoformat(form => '>>>>.<<', numeric => 'AllPlaces') %]
- [% autoformat(123.45, 666, 3.14) %]
+ [% USE Autoformat(form => '>>>>.<<', numeric => 'AllPlaces') %]
+ [% Autoformat(123.45, 666, 3.14) %]
-These can also be passed directly to the autoformat subroutine.
+These can also be passed directly to the Autoformat subroutine.
- [% USE autoformat %]
- [% autoformat( 123.45, 666, 3.14,
+ [% USE Autoformat %]
+ [% Autoformat( 123.45, 666, 3.14,
form => '>>>>.<<',
numeric => 'AllPlaces' )
%]
@@ -207,9 +214,8 @@ Damian Conway wrote the L<Text::Autoformat> module which does all the clever
stuff.
The module was moved out of the L<Template Toolkit|Template> core and into
-a separate distribution in December 2008. Andy Wardley is the current
-maintainer, but rarely uses the module these days. So if anyone else out
-there wants to take over ownership of it then please get in touch.
+a separate distribution in December 2008. Peter Karman is the current
+maintainer.
=head1 COPYRIGHT
@@ -0,0 +1,255 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use lib qw( ../lib );
+use Template qw( :status );
+use Test::More tests => 23;
+use POSIX qw( localeconv );
+
+# for testing known bug with locales that don't use '.' as a decimal
+# separator - see TODO file.
+# POSIX::setlocale( &POSIX::LC_ALL, 'sv_SE' );
+POSIX::setlocale( &POSIX::LC_ALL, 'C' );
+
+my $loc = localeconv;
+my $dec = $loc->{decimal_point};
+
+warn "decimal==$dec";
+
+my $vars = { decimal => $dec, };
+my $opts = { POST_CHOMP => 1 };
+my ( $buf, $tmpl, $expected );
+
+ok( my $template = Template->new($opts), "Template->new" );
+
+###############################################################
+$tmpl = <<EOF;
+[% global.text = BLOCK %]
+This is some text which
+I would like to have formatted
+and I should ensure that it continues
+for a reasonable length
+[% END %]
+[% USE Autoformat(left => 3, right => 20) %]
+[% Autoformat(global.text) %]
+EOF
+
+$expected = <<EOF;
+ This is some text
+ which I would like
+ to have formatted
+ and I should
+ ensure that it
+ continues for a
+ reasonable length
+
+EOF
+
+ok( $template->process( \$tmpl, $vars, \$buf ), "process tmpl" );
+is( $buf, $expected, "got expected" );
+
+###############################################################
+$tmpl = <<EOF;
+[% USE Autoformat(left=5) %]
+[% Autoformat(global.text, right=30) %]
+EOF
+
+$expected = <<EOF;
+ This is some text which I
+ would like to have
+ formatted and I should
+ ensure that it continues
+ for a reasonable length
+
+EOF
+
+$buf = "";
+ok( $template->process( \$tmpl, $vars, \$buf ), "process tmpl" );
+is( $buf, $expected, "got expected" );
+
+###############################################################
+$tmpl = <<EOF;
+[% USE Autoformat %]
+[% Autoformat(global.text, 'more text', right=50) %]
+EOF
+
+$expected = <<EOF;
+This is some text which I would like to have
+formatted and I should ensure that it continues
+for a reasonable length more text
+
+EOF
+
+$buf = "";
+ok( $template->process( \$tmpl, $vars, \$buf ), "process tmpl" );
+is( $buf, $expected, "got expected" );
+
+###############################################################
+$tmpl = <<EOF;
+[% USE Autoformat(left=10) %]
+[% global.text | Autoformat %]
+EOF
+
+$expected = <<EOF;
+ This is some text which I would like to have formatted and I
+ should ensure that it continues for a reasonable length
+
+EOF
+
+$buf = "";
+ok( $template->process( \$tmpl, $vars, \$buf ), "process tmpl" );
+is( $buf, $expected, "got expected" );
+
+###############################################################
+$tmpl = <<EOF;
+[% USE Autoformat(left=5) %]
+[% global.text | Autoformat(right=30) %]
+EOF
+
+$expected = <<EOF;
+ This is some text which I
+ would like to have
+ formatted and I should
+ ensure that it continues
+ for a reasonable length
+
+EOF
+
+$buf = "";
+ok( $template->process( \$tmpl, $vars, \$buf ), "process tmpl" );
+is( $buf, $expected, "got expected" );
+
+###############################################################
+$tmpl = <<EOF;
+[% USE Autoformat %]
+[% FILTER Autoformat(right=>30, case => 'upper') -%]
+This is some more text. OK! There's no need to shout!
+> quoted stuff goes here
+> more quoted stuff
+> blah blah blah
+[% END %]
+EOF
+
+$expected = <<EOF;
+THIS IS SOME MORE TEXT. OK!
+THERE'S NO NEED TO SHOUT!
+> quoted stuff goes here
+> more quoted stuff
+> blah blah blah
+EOF
+
+$buf = "";
+ok( $template->process( \$tmpl, $vars, \$buf ), "process tmpl" );
+is( $buf, $expected, "got expected" );
+
+###############################################################
+$tmpl = <<EOF;
+[% USE Autoformat %]
+[% Autoformat(global.text, ' of time.') %]
+EOF
+
+$expected = <<EOF;
+This is some text which I would like to have formatted and I should
+ensure that it continues for a reasonable length of time.
+
+EOF
+
+$buf = "";
+ok( $template->process( \$tmpl, $vars, \$buf ), "process tmpl" );
+is( $buf, $expected, "got expected" );
+
+###############################################################
+$tmpl = <<EOF;
+[% USE Autoformat %]
+[% Autoformat(global.text, ' of time.', right=>30) %]
+EOF
+
+$expected = <<EOF;
+This is some text which I
+would like to have formatted
+and I should ensure that it
+continues for a reasonable
+length of time.
+
+EOF
+
+$buf = "";
+ok( $template->process( \$tmpl, $vars, \$buf ), "process tmpl" );
+is( $buf, $expected, "got expected" );
+
+###############################################################
+$tmpl = <<EOF;
+[% USE Autoformat %]
+[% FILTER poetry = Autoformat(left => 20, right => 40) %]
+ Be not afeard. The isle is full of noises, sounds and sweet
+ airs that give delight but hurt not.
+[% END %]
+[% FILTER poetry %]
+ I cried to dream again.
+[% END %]
+EOF
+
+$expected = <<EOF;
+ Be not afeard. The
+ isle is full of
+ noises, sounds and
+ sweet airs that give
+ delight but hurt not.
+
+ I cried to dream
+ again.
+
+EOF
+
+$buf = "";
+ok( $template->process( \$tmpl, $vars, \$buf ), "process tmpl" );
+is( $buf, $expected, "got expected" );
+
+###############################################################
+$tmpl = <<EOF;
+Item Description Cost
+===================================
+[% form = BLOCK %]
+<<<<<< [[[[[[[[[[[[[[[ >>>>[% decimal %]<<
+[% END -%]
+[% USE Autoformat(form => form) %]
+[% Autoformat('foo', 'The Foo Item', 123.545) %]
+[% Autoformat('bar', 'The Bar Item', 456.789) %]
+EOF
+
+# sprintf rounding is somewhat unpredictable per-machine,
+# so make our expectations align predictably.
+my $rounded = sprintf('%0.2f', '123.545');
+
+$expected = <<EOF;
+Item Description Cost
+===================================
+foo The Foo Item $rounded
+bar The Bar Item 456${dec}79
+EOF
+
+$buf = "";
+ok( $template->process( \$tmpl, $vars, \$buf ), "process tmpl" );
+is( $buf, $expected, "got expected" );
+
+###############################################################
+$tmpl = <<EOF;
+[% USE Autoformat(form => '>>>.<<', numeric => 'AllPlaces') %]
+[% Autoformat(n)
+ FOREACH n = [ 123, 34.54, 99 ] +%]
+[% Autoformat(987, 654.32) %]
+EOF
+
+$expected = <<EOF;
+123${dec}00
+ 34${dec}54
+ 99${dec}00
+
+987${dec}00
+654${dec}32
+EOF
+
+$buf = "";
+ok( $template->process( \$tmpl, $vars, \$buf ), "process tmpl" );
+is( $buf, $expected, "got expected" );
+
@@ -20,22 +20,26 @@ use Template qw( :status );
use Template::Test;
use POSIX qw( localeconv );
-$Template::Test::DEBUG = 0;
+$Template::Test::DEBUG = 1;
$Template::Test::PRESERVE = 1;
-# for testing known bug with locales that don't use '.' as a decimal
+# for testing known bug with locales that don't use '.' as a decimal
# separator - see TODO file.
# POSIX::setlocale( &POSIX::LC_ALL, 'sv_SE' );
+POSIX::setlocale( &POSIX::LC_ALL, 'C' );
my $loc = localeconv;
-my $dec = $loc->{ decimal_point };
+my $dec = $loc->{decimal_point};
-my $vars = {
- decimal => $dec,
-};
+warn "decimal==$dec";
-test_expect(\*DATA, { POST_CHOMP => 1 }, $vars);
-
+# sprintf rounding is somewhat unpredictable per-machine,
+# so make our expectations align predictably.
+my $rounded = sprintf('%0.2f', '123.545');
+
+my $vars = { decimal => $dec, rounded => $rounded };
+
+test_expect( \*DATA, { POST_CHOMP => 1 }, $vars );
#------------------------------------------------------------------------
# test input
@@ -61,8 +65,8 @@ for a reasonable length
reasonable length
-- test --
-[% USE autoformat(left=5) %]
-[% autoformat(global.text, right=30) %]
+[% USE Autoformat(left=5) %]
+[% Autoformat(global.text, right=30) %]
-- expect --
This is some text which I
would like to have
@@ -71,23 +75,23 @@ for a reasonable length
for a reasonable length
-- test --
-[% USE autoformat %]
-[% autoformat(global.text, 'more text', right=50) %]
+[% USE Autoformat %]
+[% Autoformat(global.text, 'more text', right=50) %]
-- expect --
This is some text which I would like to have
formatted and I should ensure that it continues
for a reasonable length more text
-- test --
-[% USE autoformat(left=10) %]
-[% global.text | autoformat %]
+[% USE Autoformat(left=10) %]
+[% global.text | Autoformat %]
-- expect --
This is some text which I would like to have formatted and I
should ensure that it continues for a reasonable length
-- test --
-[% USE autoformat(left=5) %]
-[% global.text | autoformat(right=30) %]
+[% USE Autoformat(left=5) %]
+[% global.text | Autoformat(right=30) %]
-- expect --
This is some text which I
would like to have
@@ -96,8 +100,8 @@ for a reasonable length more text
for a reasonable length
-- test --
-[% USE autoformat %]
-[% FILTER autoformat(right=>30, case => 'upper') -%]
+[% USE Autoformat %]
+[% FILTER Autoformat(right=>30, case => 'upper') -%]
This is some more text. OK! There's no need to shout!
> quoted stuff goes here
> more quoted stuff
@@ -111,15 +115,15 @@ THERE'S NO NEED TO SHOUT!
> blah blah blah
-- test --
-[% USE autoformat %]
-[% autoformat(global.text, ' of time.') %]
+[% USE Autoformat %]
+[% Autoformat(global.text, ' of time.') %]
-- expect --
This is some text which I would like to have formatted and I should
ensure that it continues for a reasonable length of time.
-- test --
-[% USE autoformat %]
-[% autoformat(global.text, ' of time.', right=>30) %]
+[% USE Autoformat %]
+[% Autoformat(global.text, ' of time.', right=>30) %]
-- expect --
This is some text which I
would like to have formatted
@@ -128,8 +132,8 @@ continues for a reasonable
length of time.
-- test --
-[% USE autoformat %]
-[% FILTER poetry = autoformat(left => 20, right => 40) %]
+[% USE Autoformat %]
+[% FILTER poetry = Autoformat(left => 20, right => 40) %]
Be not afeard. The isle is full of noises, sounds and sweet
airs that give delight but hurt not.
[% END %]
@@ -151,23 +155,24 @@ length of time.
Item Description Cost
===================================
[% form = BLOCK %]
-<<<<<< [[[[[[[[[[[[[[[ >>>>.<<
+<<<<<< [[[[[[[[[[[[[[[ >>>>[% decimal %]<<
[% END -%]
-[% USE autoformat(form => form) %]
-[% autoformat('foo', 'The Foo Item', 123.545) %]
-[% autoformat('bar', 'The Bar Item', 456.789) %]
+[% USE Autoformat(form => form) %]
+[% Autoformat('foo', 'The Foo Item', 123.545) %]
+[% Autoformat('bar', 'The Bar Item', 456.789) %]
-- expect --
-- process --
Item Description Cost
===================================
-foo The Foo Item 123[% decimal %]55
+foo The Foo Item [% rounded %]
+
bar The Bar Item 456[% decimal %]79
-- test --
-[% USE autoformat(form => '>>>.<<', numeric => 'AllPlaces') %]
-[% autoformat(n)
+[% USE Autoformat(form => '>>>.<<', numeric => 'AllPlaces') %]
+[% Autoformat(n)
FOREACH n = [ 123, 34.54, 99 ] +%]
-[% autoformat(987, 654.32) %]
+[% Autoformat(987, 654.32) %]
-- expect --
-- process --
123[% decimal %]00