Template-Plugin-Comma-0.04/0040755000175000017500000000000010175313556015670 5ustar miyagawamiyagawaTemplate-Plugin-Comma-0.04/t/0040755000175000017500000000000010175313556016133 5ustar miyagawamiyagawaTemplate-Plugin-Comma-0.04/t/00_compile.t0100644000175000017500000000012307520166000020226 0ustar miyagawamiyagawause strict; use Test::More tests => 1; BEGIN { use_ok 'Template::Plugin::Comma' } Template-Plugin-Comma-0.04/t/01_comma.t0100644000175000017500000000252710175313363017713 0ustar miyagawamiyagawause strict; use Template::Test; test_expect(\*DATA, undef, { price => 10000 }); __END__ --test-- [% USE Comma -%] [% FILTER comma -%] 1000.00 [%- END %] --expect-- 1,000.00 --test-- [% USE Comma -%] [% price | comma %] --expect-- 10,000 --test-- [% USE Comma -%] [% FILTER comma -%] This item costs 1000 yen. [%- END %] --expect-- This item costs 1,000 yen. --test-- [% USE Comma -%] This item costs [% 123 | comma %] yen. --expect-- This item costs 123 yen. --test-- [% USE Comma -%] This item costs $[% 123.45 | comma %] USD. --expect-- This item costs $123.45 USD. --test-- [% USE Comma -%] This item costs $[% 123.4567 | comma %] USD. --expect-- This item costs $123.4567 USD. --test-- [% USE Comma -%] This item costs $[% 1234.56 | comma %] USD. --expect-- This item costs $1,234.56 USD. --test-- [% USE Comma -%] This item costs $[% 1234.5678 | comma %] USD. --expect-- This item costs $1,234.5678 USD. --test-- [% USE Comma %][% 123.45 | comma %] --expect-- 123.45 --test-- [% USE Comma %][% 1234.5678 | comma %] --expect-- 1,234.5678 --test-- [% USE Comma %][% 1234567.8901 | comma %] --expect-- 1,234,567.8901 --test-- [% USE Comma -%] [% FILTER comma -%] .31 .3141592 0.3141592 3.141592 314.1592 31415.92653 3141592653.58 314159265358 [%- END %] --expect-- .31 .3141592 0.3141592 3.141592 314.1592 31,415.92653 3,141,592,653.58 314,159,265,358 Template-Plugin-Comma-0.04/lib/0040755000175000017500000000000010175313556016436 5ustar miyagawamiyagawaTemplate-Plugin-Comma-0.04/lib/Template/0040755000175000017500000000000010175313556020211 5ustar miyagawamiyagawaTemplate-Plugin-Comma-0.04/lib/Template/Plugin/0040755000175000017500000000000010175313556021447 5ustar miyagawamiyagawaTemplate-Plugin-Comma-0.04/lib/Template/Plugin/Comma.pm0100644000175000017500000000257310175313435023041 0ustar miyagawamiyagawapackage Template::Plugin::Comma; use strict; use vars qw($VERSION); $VERSION = 0.04; require Template::Plugin; use base qw(Template::Plugin); use vars qw($FILTER_NAME); $FILTER_NAME = 'comma'; sub new { my($self, $context, @args) = @_; my $name = $args[0] || $FILTER_NAME; $context->define_filter($name, \&commify, 0); return $self; } sub commify { local $_ = shift; 1 while s/((?:\A|[^.0-9])[-+]?\d+)(\d{3})/$1,$2/s; return $_; } 1; __END__ =head1 NAME Template::Plugin::Comma - TT Plugin to commify numbers =head1 SYNOPSIS [% USE Comma %] [% FILTER comma -%] This item costs 10000 dollar. [%- END %] # Output: # This item costs 10,000 dollar. This item costs [% item.price | comma %] dollar. # Output: # This item costs 10,000 dollar. =head1 DESCRIPTION Template::Plugin::Comma is a plugin for TT, which allows you to commify your numbers in templates. This would be especially useful for prices. =head1 NOTE This module does nothing for I18N. If you want it, try Template::Plugin::Number::Format. =head1 AUTHOR Original idea by Yoshiki Kurihara Ekurihara@cpan.orgE TT plugin implemented by Tatsuhiko Miyagawa Emiyagawa@bulknews.netE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L