| 1 | package HTML::FormHandler::Field::Integer; | ||
| 2 | # ABSTRACT: validate an integer value | ||
| 3 | 14 | $HTML::FormHandler::Field::Integer::VERSION = '0.410000'; | |
| 4 | 14 | ▶ | use HTML::FormHandler::Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 14 | extends 'HTML::FormHandler::Field::Text'; | |
| 6 | |||
| 7 | 14 | has '+size' => ( default => 8 ); | |
| 8 | 14 | has '+html5_type_attr' => ( default => 'number' ); | |
| 9 | |||
| 10 | 14 | our $class_messages = { | |
| 11 | 'integer_needed' => 'Value must be an integer', | ||
| 12 | }; | ||
| 13 | |||
| 14 | sub get_class_messages { | ||
| 15 | 23 | ▶ | my $self = shift; |
|
Subroutine
get_class_messages: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 16 | return { | ||
| 17 | 23 | %{ $self->next::method }, | |
| 18 | %$class_messages, | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | |||
| 23 | apply( | ||
| 24 | [ | ||
| 25 | { | ||
| 26 | transform => sub { | ||
| 27 | 59 | ▶ | my $value = shift; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 28 | 59 | $value =~ s/^\+//; | |
| 29 | 59 | return $value; | |
| 30 | } | ||
| 31 | }, | ||
| 32 | { | ||
| 33 | 59 | ▶ | check => sub { $_[0] =~ /^-?[0-9]+$/ }, |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 34 | message => sub { | ||
| 35 | 6 | ▶ | my ( $value, $field ) = @_; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 36 | 6 | return $field->get_message('integer_needed'); | |
| 37 | }, | ||
| 38 | } | ||
| 39 | 14 | ] | |
| 40 | ); | ||
| 41 | |||
| 42 | |||
| 43 | 14 | __PACKAGE__->meta->make_immutable; | |
| 44 | 14 | ▶ | use namespace::autoclean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 45 | 14 | 1; | |
| 46 | |||
| 47 | __END__ | ||
| 48 | |||
| 49 | =pod | ||
| 50 | |||
| 51 | =encoding UTF-8 | ||
| 52 | |||
| 53 | =head1 NAME | ||
| 54 | |||
| 55 | HTML::FormHandler::Field::Integer - validate an integer value | ||
| 56 | |||
| 57 | =head1 VERSION | ||
| 58 | |||
| 59 | version 0.410000 | ||
| 60 | |||
| 61 | =head1 DESCRIPTION | ||
| 62 | |||
| 63 | This accepts a positive or negative integer. Negative integers may | ||
| 64 | be prefixed with a dash. By default a max of eight digits are accepted. | ||
| 65 | Widget type is 'text'. | ||
| 66 | |||
| 67 | If form has 'is_html5' flag active it will render <input type="number" ... /> | ||
| 68 | instead of type="text" | ||
| 69 | |||
| 70 | The 'range_start' and 'range_end' attributes may be used to limit valid numbers. | ||
| 71 | |||
| 72 | =head1 AUTHOR | ||
| 73 | |||
| 74 | FormHandler Contributors - see HTML::FormHandler | ||
| 75 | |||
| 76 | =head1 COPYRIGHT AND LICENSE | ||
| 77 | |||
| 78 | This software is copyright (c) 2017 by Gerda Shank. | ||
| 79 | |||
| 80 | This is free software; you can redistribute it and/or modify it under | ||
| 81 | the same terms as the Perl 5 programming language system itself. | ||
| 82 | |||
| 83 | =cut | ||