line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
787
|
use strict; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
189
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::FormFu::Deflator::FormatNumber; |
4
|
|
|
|
|
|
|
$HTML::FormFu::Deflator::FormatNumber::VERSION = '2.07'; |
5
|
|
|
|
|
|
|
# ABSTRACT: Format a number for a locale |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
20
|
use Moose; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
22
|
|
8
|
3
|
|
|
3
|
|
21425
|
use MooseX::Attribute::Chained; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
123
|
|
9
|
|
|
|
|
|
|
extends 'HTML::FormFu::Deflator'; |
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
665
|
use Number::Format; |
|
3
|
|
|
|
|
5069
|
|
|
3
|
|
|
|
|
198
|
|
12
|
3
|
|
|
3
|
|
47
|
use POSIX qw( setlocale LC_NUMERIC ); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
25
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has precision => ( |
15
|
|
|
|
|
|
|
is => 'rw', |
16
|
|
|
|
|
|
|
default => 2, |
17
|
|
|
|
|
|
|
lazy => 1, |
18
|
|
|
|
|
|
|
isa => 'Int', |
19
|
|
|
|
|
|
|
traits => ['Chained'], |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has trailing_zeroes => ( |
23
|
|
|
|
|
|
|
is => 'rw', |
24
|
|
|
|
|
|
|
default => 0, |
25
|
|
|
|
|
|
|
lazy => 1, |
26
|
|
|
|
|
|
|
isa => 'Int', |
27
|
|
|
|
|
|
|
traits => ['Chained'], |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub deflator { |
31
|
2
|
|
|
2
|
0
|
6
|
my ( $self, $value ) = @_; |
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
|
|
12
|
my $backup_locale = setlocale(LC_NUMERIC); |
34
|
|
|
|
|
|
|
|
35
|
2
|
50
|
|
|
|
15
|
if ( my $locale = $self->locale ) { |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# throwing errors from deflator() isn't supported |
38
|
|
|
|
|
|
|
# if unable to set locale, return the original value |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
0
|
setlocale( LC_NUMERIC, $locale ) |
41
|
|
|
|
|
|
|
or return $value; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
2
|
|
|
|
|
24
|
my $format = Number::Format->new; |
45
|
|
|
|
|
|
|
|
46
|
2
|
|
|
|
|
763
|
$value = $format->format_number( $value, $self->precision, |
47
|
|
|
|
|
|
|
$self->trailing_zeroes ); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# restore locale |
50
|
2
|
|
|
|
|
404
|
setlocale( LC_NUMERIC, $backup_locale ); |
51
|
|
|
|
|
|
|
|
52
|
2
|
|
|
|
|
29
|
return $value; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=pod |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=encoding UTF-8 |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 NAME |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
HTML::FormFu::Deflator::FormatNumber - Format a number for a locale |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 VERSION |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
version 2.07 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SYNOPSIS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
locale: de_DE |
76
|
|
|
|
|
|
|
elements: |
77
|
|
|
|
|
|
|
- type: Text |
78
|
|
|
|
|
|
|
name: number |
79
|
|
|
|
|
|
|
deflators: |
80
|
|
|
|
|
|
|
- type: FormatNumber |
81
|
|
|
|
|
|
|
precision: 4 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
- type: Text |
84
|
|
|
|
|
|
|
name: price |
85
|
|
|
|
|
|
|
deflators: |
86
|
|
|
|
|
|
|
- type: FormatNumber |
87
|
|
|
|
|
|
|
precision: 2 |
88
|
|
|
|
|
|
|
trailing_zeroes: 1 |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# "123456.22" will be rendered to "123.456,22" (german locale) |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 locale |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
If no locale is found, the server's locale will be used. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
This method is a special 'inherited accessor', which means it can be set on |
97
|
|
|
|
|
|
|
the form, a enclosing block element, the field, or this filter. |
98
|
|
|
|
|
|
|
When the value is read, if no value is defined it automatically traverses |
99
|
|
|
|
|
|
|
the element's hierarchy of parents, through any block elements and up to the |
100
|
|
|
|
|
|
|
form, searching for a defined value. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 AUTHOR |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Moritz Onken, C<onken at houseofdesign.de> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 SEE ALSO |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Is a sub-class of, and inherits methods from L<HTML::FormFu::Deflator> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
L<HTML::FormFu::Filter::FormatNumber> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
L<HTML::FormFu> |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Copyright 2008 Moritz Onken, all rights reserved. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
119
|
|
|
|
|
|
|
under the same terms as Perl itself. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 AUTHOR |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Carl Franks <cpan@fireartist.com> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Carl Franks. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
130
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |