DBIx::Class::Validation - Validate all data before submitting to your database.
In your base DBIC package:
__PACKAGE__->load_components(qw/... Validation/);
And in your subclasses:
__PACKAGE__->validation( module => 'FormValidator::Simple', profile => { ... }, auto => 1, );
And then somewhere else:
eval{ $obj->validate() }; if( my $results = $EVAL_ERROR ){ ... }
Calls validation_module(), validation_profile(), and validation_auto() if the corresponding argument is defined.
__PACKAGE__->validation_module('Data::FormValidator');
Sets the validation module to use. Any module that supports a check() method just like Data::FormValidator's can be used here, such as FormValidator::Simple.
Defaults to FormValidator::Simple.
__PACKAGE__->validation_profile( { ... } );
Sets the profile that will be passed to the validation module.
__PACKAGE__->validation_auto( 1 );
This flag, when enabled, causes any updates or inserts of the class to call validate() before actually executing.
$obj->validate();
Validates all the data in the object against the pre-defined validation module and profile. If there is a problem then a hard error will be thrown. If you put the validation in an eval you can capture whatever the module's check() method returned.
__PACKAGE__->auto_validate( 0 );
Turns on and off auto-validation. This feature makes all UPDATEs and INSERTs call the validate() method before doing anything. The default is for auto-validation to be on.
Defaults to on.
Aran C. Deltac <bluefeet@cpan.org>
You may distribute this code under the same terms as Perl itself.
To install DBIx::Class, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Class
CPAN shell
perl -MCPAN -e shell install DBIx::Class
For more information on module installation, please visit the detailed CPAN module installation guide.