line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plugin::Comma; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
107263
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
77
|
|
4
|
2
|
|
|
2
|
|
10
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
126
|
|
5
|
|
|
|
|
|
|
$VERSION = 0.04; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Template::Plugin; |
8
|
2
|
|
|
2
|
|
10
|
use base qw(Template::Plugin); |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
2449
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
13650
|
use vars qw($FILTER_NAME); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
478
|
|
11
|
|
|
|
|
|
|
$FILTER_NAME = 'comma'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
12
|
|
|
12
|
1
|
22986
|
my($self, $context, @args) = @_; |
15
|
12
|
|
33
|
|
|
56
|
my $name = $args[0] || $FILTER_NAME; |
16
|
12
|
|
|
|
|
36
|
$context->define_filter($name, \&commify, 0); |
17
|
12
|
|
|
|
|
211
|
return $self; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub commify { |
21
|
12
|
|
|
12
|
0
|
565
|
local $_ = shift; |
22
|
12
|
|
|
|
|
263
|
1 while s/((?:\A|[^.0-9])[-+]?\d+)(\d{3})/$1,$2/s; |
23
|
12
|
|
|
|
|
34
|
return $_; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
1; |
27
|
|
|
|
|
|
|
__END__ |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 NAME |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Template::Plugin::Comma - TT Plugin to commify numbers |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 SYNOPSIS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
[% USE Comma %] |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
[% FILTER comma -%] |
38
|
|
|
|
|
|
|
This item costs 10000 dollar. |
39
|
|
|
|
|
|
|
[%- END %] |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Output: |
42
|
|
|
|
|
|
|
# This item costs 10,000 dollar. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
This item costs [% item.price | comma %] dollar. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Output: |
47
|
|
|
|
|
|
|
# This item costs 10,000 dollar. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 DESCRIPTION |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Template::Plugin::Comma is a plugin for TT, which allows you to |
52
|
|
|
|
|
|
|
commify your numbers in templates. This would be especially useful for |
53
|
|
|
|
|
|
|
prices. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 NOTE |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This module does nothing for I18N. If you want it, try |
58
|
|
|
|
|
|
|
Template::Plugin::Number::Format. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 AUTHOR |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Original idea by Yoshiki Kurihara E<lt>kurihara@cpan.orgE<gt> |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
TT plugin implemented by Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt> |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
67
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SEE ALSO |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
L<Template>, C<Template::Plugin::Number::Format> |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |