| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::Template::Compiled::Plugin::NumberFormat; |
|
2
|
2
|
|
|
2
|
|
49373
|
use strict; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
602
|
|
|
3
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
63
|
|
|
4
|
2
|
|
|
2
|
|
12
|
use base 'Class::Accessor::Fast'; |
|
|
2
|
|
|
|
|
7
|
|
|
|
2
|
|
|
|
|
1874
|
|
|
5
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/ formatter /); |
|
6
|
2
|
|
|
2
|
|
9718
|
use Number::Format (); |
|
|
2
|
|
|
|
|
45091
|
|
|
|
2
|
|
|
|
|
70
|
|
|
7
|
2
|
|
|
2
|
|
2993
|
use HTML::Template::Compiled; |
|
|
2
|
|
|
|
|
176654
|
|
|
|
2
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
|
|
HTML::Template::Compiled->register(__PACKAGE__); |
|
9
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub register { |
|
12
|
2
|
|
|
2
|
1
|
21
|
my ($class) = @_; |
|
13
|
|
|
|
|
|
|
my %plugs = ( |
|
14
|
|
|
|
|
|
|
escape => { |
|
15
|
|
|
|
|
|
|
# |
|
16
|
|
|
|
|
|
|
FORMAT_NUMBER => { |
|
17
|
|
|
|
|
|
|
code => \&format_number, |
|
18
|
|
|
|
|
|
|
arguments => [qw/ var self /], |
|
19
|
|
|
|
|
|
|
}, |
|
20
|
|
|
|
|
|
|
FORMAT_BYTES => { |
|
21
|
|
|
|
|
|
|
code => \&format_bytes, |
|
22
|
|
|
|
|
|
|
arguments => [qw/ var self /], |
|
23
|
|
|
|
|
|
|
}, |
|
24
|
|
|
|
|
|
|
FORMAT_PRICE => { |
|
25
|
|
|
|
|
|
|
code => \&format_price, |
|
26
|
|
|
|
|
|
|
arguments => [qw/ var self /], |
|
27
|
|
|
|
|
|
|
}, |
|
28
|
|
|
|
|
|
|
}, |
|
29
|
|
|
|
|
|
|
tagnames => { |
|
30
|
|
|
|
|
|
|
HTML::Template::Compiled::Token::OPENING_TAG() => { |
|
31
|
2
|
|
|
6
|
|
41
|
FORMAT_NUMBER => [sub { exists $_[1]->{NAME} }, qw/ TYPE PRECISION TRAILING_ZEROES /], |
|
|
6
|
|
|
|
|
84995
|
|
|
32
|
|
|
|
|
|
|
}, |
|
33
|
|
|
|
|
|
|
}, |
|
34
|
|
|
|
|
|
|
compile => { |
|
35
|
|
|
|
|
|
|
FORMAT_NUMBER => { |
|
36
|
|
|
|
|
|
|
open => \&_compile_format_number,, |
|
37
|
|
|
|
|
|
|
}, |
|
38
|
|
|
|
|
|
|
}, |
|
39
|
|
|
|
|
|
|
); |
|
40
|
2
|
|
|
|
|
9
|
return \%plugs; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub format_number { |
|
44
|
2
|
|
|
2
|
1
|
38122
|
my ($var, $self) = @_; |
|
45
|
2
|
|
|
|
|
33
|
$self->formatter->format_number($var); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub format_bytes { |
|
49
|
6
|
|
|
6
|
1
|
1017
|
my ($var, $self) = @_; |
|
50
|
6
|
|
|
|
|
16
|
$self->formatter->format_bytes($var); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub format_price { |
|
54
|
2
|
|
|
2
|
1
|
1410
|
my ($var, $self) = @_; |
|
55
|
2
|
|
|
|
|
9
|
$self->formatter->format_price($var); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _compile_format_number { |
|
59
|
6
|
|
|
6
|
|
4045
|
my ($htc, $token, $args) = @_; |
|
60
|
6
|
|
|
|
|
15
|
my $OUT = $args->{out}; |
|
61
|
6
|
|
|
|
|
16
|
my $attr = $token->get_attributes; |
|
62
|
6
|
|
|
|
|
25
|
my $var = $attr->{NAME}; |
|
63
|
6
|
|
|
|
|
22
|
$var = $htc->var2expression($var); |
|
64
|
6
|
|
100
|
|
|
1030
|
my $type = $attr->{TYPE} || 'number'; |
|
65
|
6
|
|
|
|
|
10
|
my $method = 'format_number'; |
|
66
|
6
|
|
|
|
|
7
|
my @args; |
|
67
|
6
|
|
|
|
|
10
|
my $precision = $attr->{PRECISION}; |
|
68
|
6
|
100
|
|
|
|
30
|
if (lc $type eq 'number') { |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
3
|
$method = 'format_number'; |
|
70
|
2
|
|
|
|
|
5
|
my $trailing_zeroes = $attr->{TRAILING_ZEROES}; |
|
71
|
2
|
|
|
|
|
6
|
for ($precision, $trailing_zeroes) { |
|
72
|
4
|
|
|
|
|
8
|
_sanitize($_); |
|
73
|
4
|
|
|
|
|
8
|
push @args, $_; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
elsif (lc $type eq 'price') { |
|
77
|
2
|
|
|
|
|
4
|
for ($precision) { |
|
78
|
2
|
|
|
|
|
5
|
_sanitize($_); |
|
79
|
2
|
|
|
|
|
5
|
push @args, $_; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
2
|
|
|
|
|
4
|
$method = 'format_price'; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
elsif (lc $type eq 'bytes') { |
|
84
|
2
|
|
|
|
|
3
|
$method = 'format_bytes'; |
|
85
|
2
|
|
|
|
|
5
|
for ($precision) { |
|
86
|
2
|
|
|
|
|
5
|
_sanitize($_); |
|
87
|
2
|
|
|
|
|
6
|
push @args, ("'precision'" => $_); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
} |
|
90
|
6
|
|
|
|
|
10
|
local $" = ','; |
|
91
|
6
|
|
|
|
|
19
|
my $expression = <<"EOM"; |
|
92
|
|
|
|
|
|
|
$OUT \$t->get_plugin('HTML::Template::Compiled::Plugin::NumberFormat')->formatter->$method($var, @args); |
|
93
|
|
|
|
|
|
|
EOM |
|
94
|
6
|
|
|
|
|
42
|
return $expression; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
sub _sanitize { |
|
97
|
8
|
100
|
66
|
8
|
|
36
|
if (defined $_[0] and length $_[0]) { |
|
98
|
6
|
|
|
|
|
10
|
$_[0] =~ tr/0-9//cd; |
|
99
|
6
|
|
50
|
|
|
19
|
$_[0] ||= 0; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
else { |
|
102
|
2
|
|
|
|
|
6
|
$_[0] = 'undef'; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $version_pod = <<'=cut'; |
|
108
|
|
|
|
|
|
|
=pod |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 NAME |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
HTML::Template::Compiled::Plugin::Nuber::Format - Number::Format plugin for HTML::Template::Compiled |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 VERSION |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
$VERSION = "0.02" |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub __test_version { |
|
122
|
1
|
|
|
1
|
|
45
|
my $v = __PACKAGE__->VERSION; |
|
123
|
1
|
|
|
|
|
21
|
my ($v_test) = $version_pod =~ m/VERSION\s*=\s*"(.+)"/m; |
|
124
|
2
|
|
|
2
|
|
1451
|
no warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
124
|
|
|
125
|
1
|
50
|
|
|
|
14
|
return $v eq $v_test ? 1 : 0; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
__END__ |