NAME

Valiant::Proxy::Object - Wrap any object into a validatable result object.

SYNOPSIS

my $proxy = Valiant::Proxy::Object->new(
  validations => [
    [ name => length => [2,15] ],
    [ age => numericality => 'positive_integer' ],
  ],
);

my $result = $proxy->validate($user_object);
$result->invalid; # true when $user_object breaks the rules

DESCRIPTION

Create a validation object for a given class or role. Useful when you need (or prefer) to build up a validation ruleset in code rather than via the annotations-like approach given in Valiant::Validations. Can also be useful to add validations to a class that isn't Moo/se and can't use Valiant::Validations or is outside your control (such as a third party library). Lastly you may need to build validation sets based on existing metadata, such as via database introspection or from a file containing validation instructions.

This uses AUTOLOAD to delegate method calls to the underlying object. Calling a method that the underlying object does not provide throws a Valiant::Util::Exception::MissingMethod rather than silently returning undef.

Please note that the code used to create the validation object is not speed optimized so I recommend you not use this approach in 'hot' code paths. Its probably best if you can create all these during your application startup once (for long lived applications). Maybe not ideal for 'fire and forget' scripts like cron jobs or CGI.

You probably won't use this directly, although you can.

SEE ALSO

This does the interface defined by Valiant::Proxy so see the docs on that.

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

AUTHOR

See Valiant

COPYRIGHT & LICENSE

See Valiant