Valiant::Filter::Numberize - Force into number context
package Local::Test::User; use Moo; use Valiant::Filters; has 'age' => (is=>'ro', required=>1); filters age => ( numberize => 1, ); my $user = Local::Test::User->new(age=>'25'); print $user->age; # 25 my $not_a_number = Local::Test::User(age=>'aaaabbbccc'); print $not_a_number; # 0
This is a very simple filter that takes no paramters and just forces a value into number context. Please note that this mean strings with letters and other non number values will almost always end up as 0 without returning any validation errors. If you want to notice and handle this as a validation then you might want to check Valiant::Validator::Numericality instead,
Valiant, Valiant::Filter, Valiant::Validator::Filter.
See Valiant
To install Valiant, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Valiant
CPAN shell
perl -MCPAN -e shell install Valiant
For more information on module installation, please visit the detailed CPAN module installation guide.