line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plugin::Komma; |
2
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
215349
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
145
|
|
6
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
122
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
21
|
use base 'Template::Plugin'; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
3433
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# taken from Math::Round |
12
|
|
|
|
|
|
|
my $half = 0.50000000000008; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
30
|
|
|
30
|
1
|
62994
|
my ($self, $context) = @_; |
17
|
|
|
|
|
|
|
|
18
|
30
|
|
|
|
|
118
|
$context->define_filter('komma', \&komma, ''); |
19
|
30
|
|
|
|
|
624
|
$context->define_filter('komma0', \&komma0, ''); |
20
|
30
|
|
|
|
|
427
|
$context->define_filter('komma2', \&komma2, ''); |
21
|
|
|
|
|
|
|
|
22
|
30
|
|
|
|
|
402
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub komma { |
26
|
6
|
|
|
6
|
0
|
270
|
my $number = shift; |
27
|
|
|
|
|
|
|
|
28
|
6
|
50
|
|
|
|
17
|
return undef unless defined $number; |
29
|
6
|
100
|
|
|
|
14
|
return '' if $number eq ''; |
30
|
|
|
|
|
|
|
|
31
|
5
|
|
|
|
|
17
|
return _komma($number+0); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _komma { |
35
|
27
|
|
|
27
|
|
33
|
my $number = shift; |
36
|
27
|
|
|
|
|
92
|
my @number = split(/\./, $number); |
37
|
27
|
|
|
|
|
37
|
my $ready = ''; |
38
|
|
|
|
|
|
|
|
39
|
27
|
|
|
|
|
116
|
while ($number[0] =~ /([+-]*\d+)(\d{3})$/) { |
40
|
12
|
|
|
|
|
25
|
$number[0] = $1; |
41
|
12
|
|
|
|
|
55
|
$ready = '.'.$2.$ready; |
42
|
|
|
|
|
|
|
} |
43
|
27
|
|
|
|
|
44
|
$ready = $number[0].$ready; |
44
|
|
|
|
|
|
|
|
45
|
27
|
100
|
|
|
|
57
|
if ($number[1]) { |
46
|
13
|
|
|
|
|
24
|
$ready .= ",$number[1]"; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
27
|
|
|
|
|
102
|
return $ready; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub komma0 { |
53
|
12
|
|
|
12
|
0
|
641
|
my $number = shift; |
54
|
|
|
|
|
|
|
|
55
|
12
|
50
|
|
|
|
30
|
return undef unless defined $number; |
56
|
12
|
100
|
|
|
|
34
|
return '' if $number eq ''; |
57
|
|
|
|
|
|
|
|
58
|
11
|
100
|
|
|
|
42
|
my $round = ($number < 0) ? -$half : $half; |
59
|
11
|
|
|
|
|
37
|
return _komma(int($number + $round)); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub komma2 { |
63
|
12
|
|
|
12
|
0
|
582
|
my $number = shift; |
64
|
|
|
|
|
|
|
|
65
|
12
|
50
|
|
|
|
31
|
return undef unless defined $number; |
66
|
12
|
100
|
|
|
|
24
|
return '' if $number eq ''; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# round two digits after the dot |
69
|
11
|
100
|
|
|
|
34
|
my $round = ($number < 0) ? -$half : $half; |
70
|
11
|
|
|
|
|
22
|
$number = int($number * 100 + $round); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# eventually fill with zeros |
73
|
11
|
|
|
|
|
35
|
while (length $number < 3) { |
74
|
2
|
|
|
|
|
6
|
$number = "0".$number; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# insert dot |
78
|
11
|
|
|
|
|
67
|
$number =~ s/(\d\d)$/\.$1/; |
79
|
|
|
|
|
|
|
|
80
|
11
|
|
|
|
|
23
|
return _komma($number); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
__END__ |