| 1 | package HTML::Widget::Constraint::Number; | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | use base 'HTML::Widget::Constraint'; | ||
| 6 | use Scalar::Util qw( looks_like_number ); | ||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | HTML::Widget::Constraint::Number - Number Constraint | ||
| 11 | |||
| 12 | =head1 SYNOPSIS | ||
| 13 | |||
| 14 | my $c = $widget->constraint( 'Number', 'foo' ); | ||
| 15 | |||
| 16 | =head1 DESCRIPTION | ||
| 17 | |||
| 18 | Number Constraint. | ||
| 19 | |||
| 20 | =head1 METHODS | ||
| 21 | |||
| 22 | =head2 validate | ||
| 23 | |||
| 24 | =cut | ||
| 25 | |||
| 26 | sub validate { | ||
| 27 | my ( $self, $value ) = @_; | ||
| 28 | |||
| 29 | return 1 if !defined $value || $value eq ''; | ||
| 30 | |||
| 31 | return looks_like_number($value); | ||
| 32 | } | ||
| 33 | |||
| 34 | =head1 AUTHOR | ||
| 35 | |||
| 36 | Carl Franks C<cfranks@cpan.org> | ||
| 37 | |||
| 38 | =head1 LICENSE | ||
| 39 | |||
| 40 | This library is free software, you can redistribute it and/or modify it under | ||
| 41 | the same terms as Perl itself. | ||
| 42 | |||
| 43 | =cut | ||
| 44 | |||
| 45 | 1; |