NAME

Valiant::Validator::Boolean - Verify that a value is either true or false

SYNOPSIS

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',
  ]
};

DESCRIPTION

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.

ATTRIBUTES

This validator supports the following attributes:

state

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.

is_not_true

The error message / tag used when the value is not true

is_not_false

The error message / tag used when the value is not false

SHORTCUT FORM

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, ... );

Which is the same as:

validates attribute => (
  boolean => {
    state => 0,
  }
);

GLOBAL PARAMETERS

This validator supports all the standard shared parameters: if, unless, message, strict, allow_undef, allow_blank.

SEE ALSO

Valiant, Valiant::Validator, Valiant::Validator::Each.

AUTHOR

See Valiant

COPYRIGHT & LICENSE

See Valiant