File Coverage

blib/lib/HTML/FormFu/Element/Number.pm
Criterion Covered Total %
statement 6 10 60.0
branch n/a
condition n/a
subroutine 2 4 50.0
pod 2 2 100.0
total 10 16 62.5


line stmt bran cond sub pod time code
1 2     2   864 use strict;
  2         5  
  2         112  
2              
3             package HTML::FormFu::Element::Number;
4             $HTML::FormFu::Element::Number::VERSION = '2.07';
5             # ABSTRACT: Number element with formatting
6              
7 2     2   12 use Moose;
  2         4  
  2         14  
8              
9             extends 'HTML::FormFu::Element::Text';
10              
11             after BUILD => sub {
12             my $self = shift;
13              
14             $self->deflator('FormatNumber');
15             $self->filter('FormatNumber');
16              
17             return;
18             };
19              
20             sub precision {
21 0     0 1   my $self = shift;
22              
23 0           return $self->get_deflator( { type => 'FormatNumber' } )->precision(@_);
24             }
25              
26             sub trailing_zeroes {
27 0     0 1   my $self = shift;
28              
29 0           return $self->get_deflator( { type => 'FormatNumber' } )
30             ->trailing_zeroes(@_);
31             }
32              
33             __PACKAGE__->meta->make_immutable;
34              
35             1;
36              
37             __END__
38              
39             =pod
40              
41             =encoding UTF-8
42              
43             =head1 NAME
44              
45             HTML::FormFu::Element::Number - Number element with formatting
46              
47             =head1 VERSION
48              
49             version 2.07
50              
51             =head1 SYNOPSIS
52              
53             ---
54             elements:
55             - type: Number
56             locale: de_DE
57             precision: 2
58             trailing_zeroes: 1
59              
60             =head1 DESCRIPTION
61              
62             This element formats numbers according to the current locale. You can set this
63             locale either by setting C<< $form->locale >> or by setting the element's
64             locale. If none of them is set the element uses the system's locale.
65              
66             =head1 METHODS
67              
68             =head2 locale
69              
70             Set the locale for this element. The format of the number is chosen according
71             to this locale.
72              
73             =head2 precision
74              
75             Set the precision for the number. Defaults to C<2>.
76              
77             =head2 trailing_zeroes
78              
79             If this is set to C<1> the number has trailing zeroes. Defaults to C<0>.
80              
81             =head2 CHANGED BEHAVIOUR AS OF VERSION 0.09011
82              
83             Previous to version 0.09011, this element generated an input field with
84             C<type="number"> attribute which was not valid xhtml.
85             Neither was the formatted numbers valid html5 - which expects the value to
86             be a floating-point number.
87             This element now generates a C<type="text"> attribute.
88              
89             =head1 SEE ALSO
90              
91             L<HTML::FormFu::Deflator::FormatNumber>
92              
93             L<HTML::FormFu::Filter::FormatNumber>
94              
95             L<HTML::FormFu/locale>
96              
97             =head1 AUTHOR
98              
99             Moritz Onken C< onken at houseofdesign.de >
100              
101             =head1 AUTHOR
102              
103             Carl Franks <cpan@fireartist.com>
104              
105             =head1 COPYRIGHT AND LICENSE
106              
107             This software is copyright (c) 2018 by Carl Franks.
108              
109             This is free software; you can redistribute it and/or modify it under
110             the same terms as the Perl 5 programming language system itself.
111              
112             =cut