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