Valiant::Validator::Boolean - Verify that a value is either true or false
package Local::Test::Boolean; use Moo; use Valiant::Validations; has active => (is=>'ro'); validates active => ( boolean => { state => 1, # valid values are 1 (must be true) or 0 (must be false) } ); my $object = Local::Test::Boolean->new(active=>0); $object->validate; warn $object->errors->_dump; $VAR1 = { 'active' => [ 'Active must be true', ] };
Checks a value to see if it is true or false based on Perl's notion of truthiness. This will not limit the value. For example values of 1, 'one' and [1,2,3] are considered true while values of 0, undef are false.
This validator supports the following attributes:
The required boolean value of the given value for the validator to pass. Allowed values are 1 (which requires true) and 0 (which requires false).
Value may also be a coderef.
The error message / tag used when the value is not true
The error message / tag used when the value is not false
This validator supports the follow shortcut forms:
validates attribute => ( boolean => 1, ... );
Which is the same as:
validates attribute => ( boolean => { state => 1, } );
The negation of this also works
validates attribute => ( boolean => 0, ... );
validates attribute => ( boolean => { state => 0, } );
This validator supports all the standard shared parameters: if, unless, message, strict, allow_undef, allow_blank.
if
unless
message
strict
allow_undef
allow_blank
Valiant, Valiant::Validator, Valiant::Validator::Each.
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.