X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FValidation.pm;h=4592a89adf213ebdb35f1fd717512a965a74d98f;hb=d9328e45389dad24f0130bd4f0fc19b4ba54800b;hp=a3b71716b72e73f6c7b0584f20ee61fceafba47c;hpb=54540863adce71e931685a37d33e37650e5feb5e;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Validation.pm b/lib/DBIx/Class/Validation.pm index a3b7171..4592a89 100644 --- a/lib/DBIx/Class/Validation.pm +++ b/lib/DBIx/Class/Validation.pm @@ -4,7 +4,6 @@ use strict; use warnings; use base qw( DBIx::Class ); -use Carp qw( croak ); use English qw( -no_match_vars ); #local $^W = 0; # Silence C:D:I redefined sub errors. @@ -21,8 +20,8 @@ sub validation_module { my $module = shift; eval("use $module"); - croak("Unable to load the validation module '$module' because $EVAL_ERROR") if ($EVAL_ERROR); - croak("The '$module' module does not support the check method") if (!$module->can('check')); + $class->throw_exception("Unable to load the validation module '$module' because $EVAL_ERROR") if ($EVAL_ERROR); + $class->throw_exception("The '$module' module does not support the check method") if (!$module->can('check')); $class->_validation_module_accessor( $module ); } @@ -43,7 +42,7 @@ sub validate { my $profile = $self->validation_profile(); my $result = $module->check( \%data => $profile ); return $result if ($result->success()); - croak( $result ); + $self->throw_exception( $result ); } sub insert { @@ -96,14 +95,14 @@ And then somewhere else: auto => 1, ); -Calls validation_module(), validation_profile(), and validation_auto() if the corresponding +Calls validation_module(), validation_profile(), and validation_auto() if the corresponding argument is defined. =head2 validation_module __PACKAGE__->validation_module('Data::FormValidator'); -Sets the validation module to use. Any module that supports a check() method just like +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. @@ -120,24 +119,24 @@ 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 +This flag, when enabled, causes any updates or inserts of the class to call validate() before actually executing. =head2 validate $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 +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. =head2 auto_validate __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 +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.