File: Number.pm

package info (click to toggle)
libhtml-formfu-perl 2.01000-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,116 kB
  • ctags: 828
  • sloc: perl: 12,478; makefile: 7; sql: 5
file content (88 lines) | stat: -rw-r--r-- 1,831 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package HTML::FormFu::Element::Number;
$HTML::FormFu::Element::Number::VERSION = '2.01';
use Moose;

extends 'HTML::FormFu::Element::Text';

after BUILD => sub {
    my $self = shift;

    $self->deflator('FormatNumber');
    $self->filter('FormatNumber');

    return;
};

sub precision {
    my $self = shift;

    return $self->get_deflator( { type => 'FormatNumber' } )->precision(@_);
}

sub trailing_zeroes {
    my $self = shift;

    return $self->get_deflator( { type => 'FormatNumber' } )
        ->trailing_zeroes(@_);
}

__PACKAGE__->meta->make_immutable;

1;

__END__

=head1 NAME

HTML::FormFu::Element::Number - Number element with formatting

=head1 SYNOPSIS

  ---
  elements:
    - type: Number
      locale: de_DE
      precision: 2
      trailing_zeroes: 1


=head1 DESCRIPTION

This element formats numbers according to the current locale. You can set this
locale either by setting C<< $form->locale >> or by setting the element's
locale. If none of them is set the element uses the system's locale.

=head1 METHODS

=head2 locale

Set the locale for this element. The format of the number is chosen according
to this locale.

=head2 precision

Set the precision for the number. Defaults to C<2>.

=head2 trailing_zeroes

If this is set to C<1> the number has trailing zeroes. Defaults to C<0>. 

=head2 CHANGED BEHAVIOUR AS OF VERSION 0.09011

Previous to version 0.09011, this element generated an input field with
C<type="number"> attribute which was not valid xhtml.
Neither was the formatted numbers valid html5 - which expects the value to
be a floating-point number.
This element now generates a C<type="text"> attribute.

=head1 SEE ALSO

L<HTML::FormFu::Deflator::FormatNumber>

L<HTML::FormFu::Filter::FormatNumber>

L<HTML::FormFu/locale>

=head1 AUTHOR

Moritz Onken C< onken at houseofdesign.de >