Valiant::Validator::Check - Validate using a 'check' method


    package Local::Test::Check;

    use Moo;
    use Valiant::Validations;
    use Types::Standard 'Int';

    has retiree_age => (is=>'ro');

    validates retiree_age => (
      check => {
        constraint => Int->where('$_ >= 65')
    my $object = Local::Test::Check->new(retiree_age=>40);

    warn $object->errors->_dump;

    $VAR1 = {
      'retiree_age' => [
        'Retiree age is invalid'


Let's you use an object that does check as the validation method. Basically this exists to let you use or reuse a lot of existing type constraint validation libraries on CPAN such as Type::Tiny. You might already be making heavy use of these in your code (or you might just be very familiar with them) so it it might make sense to you to just reuse them rather than learn a bunch of the custom validators that are packaged with Valiant.

You might also prefer the 'spellchecking' safety of something like Type::Tiny which uses imported methods and will result in a compile time error if you mistype the constraint name. Its also possible some of the XS versions of Type::Tiny are faster then the built in validators that ship with Valiant

Please note this validator is also a available as a shortcut which is built into the validates method itself:

    validates retiree_age => (
      Int->where('$_ >= 65'), +{
        message => 'A retiree must be at least 65 years old,

This built in shortcut just wraps this validator under the hood. I saw no reason to not expose it publically but its less typing to just use the short method.


This validator supports the following attributes


Takes an object or arrayref of objects that can provide a check method which given the value to be checked will return true if the value is valid and false otherwise.

Supports coderef for dynamically providing a constraint.


Either a translation tag or a string message for the error given when the validation fails. Defaults to "_t('check')".


This validator supports the follow shortcut forms:

    validates attribute => ( check => Int->where('$_ >= 65'), ... );

Which is the same as:

    validates attribute => (
      check => {
        constraint => Int->where('$_ >= 65'),


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


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


See Valiant


See Valiant