| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # ABSTRACT: Validation Directive for Validation Class Field Definitions | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | package Validation::Class::Directive::Validation; | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 109 |  |  | 109 |  | 44087 | use strict; | 
|  | 109 |  |  |  |  | 225 |  | 
|  | 109 |  |  |  |  | 2699 |  | 
| 6 | 109 |  |  | 109 |  | 481 | use warnings; | 
|  | 109 |  |  |  |  | 218 |  | 
|  | 109 |  |  |  |  | 2343 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 109 |  |  | 109 |  | 482 | use base 'Validation::Class::Directive'; | 
|  | 109 |  |  |  |  | 193 |  | 
|  | 109 |  |  |  |  | 8710 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 109 |  |  | 109 |  | 697 | use Validation::Class::Util; | 
|  | 109 |  |  |  |  | 222 |  | 
|  | 109 |  |  |  |  | 566 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | our $VERSION = '7.900058'; # VERSION | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | has 'mixin'        => 0; | 
| 16 |  |  |  |  |  |  | has 'field'        => 1; | 
| 17 |  |  |  |  |  |  | has 'multi'        => 0; | 
| 18 |  |  |  |  |  |  | has 'message'      => '%s could not be validated'; | 
| 19 |  |  |  |  |  |  | # ensure most core directives execute before this one | 
| 20 |  |  |  |  |  |  | has 'dependencies' => sub {{ | 
| 21 |  |  |  |  |  |  | normalization => [], | 
| 22 |  |  |  |  |  |  | validation    => [qw( | 
| 23 |  |  |  |  |  |  | alias | 
| 24 |  |  |  |  |  |  | between | 
| 25 |  |  |  |  |  |  | default | 
| 26 |  |  |  |  |  |  | depends_on | 
| 27 |  |  |  |  |  |  | error | 
| 28 |  |  |  |  |  |  | errors | 
| 29 |  |  |  |  |  |  | filtering | 
| 30 |  |  |  |  |  |  | filters | 
| 31 |  |  |  |  |  |  | label | 
| 32 |  |  |  |  |  |  | length | 
| 33 |  |  |  |  |  |  | matches | 
| 34 |  |  |  |  |  |  | max_alpha | 
| 35 |  |  |  |  |  |  | max_digits | 
| 36 |  |  |  |  |  |  | max_length | 
| 37 |  |  |  |  |  |  | max_sum | 
| 38 |  |  |  |  |  |  | min_alpha | 
| 39 |  |  |  |  |  |  | min_digits | 
| 40 |  |  |  |  |  |  | min_length | 
| 41 |  |  |  |  |  |  | min_sum | 
| 42 |  |  |  |  |  |  | mixin | 
| 43 |  |  |  |  |  |  | mixin_field | 
| 44 |  |  |  |  |  |  | multiples | 
| 45 |  |  |  |  |  |  | name | 
| 46 |  |  |  |  |  |  | options | 
| 47 |  |  |  |  |  |  | pattern | 
| 48 |  |  |  |  |  |  | readonly | 
| 49 |  |  |  |  |  |  | required | 
| 50 |  |  |  |  |  |  | toggle | 
| 51 |  |  |  |  |  |  | value | 
| 52 |  |  |  |  |  |  | )] | 
| 53 |  |  |  |  |  |  | }}; | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | sub validate { | 
| 56 |  |  |  |  |  |  |  | 
| 57 | 15 |  |  | 15 | 0 | 29 | my $self = shift; | 
| 58 |  |  |  |  |  |  |  | 
| 59 | 15 |  |  |  |  | 37 | my ($proto, $field, $param) = @_; | 
| 60 |  |  |  |  |  |  |  | 
| 61 | 15 | 100 | 66 |  |  | 82 | if (defined $field->{validation} && defined $param) { | 
| 62 |  |  |  |  |  |  |  | 
| 63 | 12 |  |  |  |  | 32 | my $context = $proto->stash->{'validation.context'}; | 
| 64 |  |  |  |  |  |  |  | 
| 65 | 12 |  |  |  |  | 46 | my $count  = ($proto->errors->count+$field->errors->count); | 
| 66 | 12 | 100 |  |  |  | 32 | my $failed = !$field->validation->($context,$field,$proto->params)?1:0; | 
| 67 | 12 | 50 |  |  |  | 84 | my $errors = ($proto->errors->count+$field->errors->count)>$count ?1:0; | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | # error handling; did the validation routine pass or fail? | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | # validation passed with no errors | 
| 72 | 12 | 100 | 66 |  |  | 71 | if (!$failed && !$errors) { | 
|  |  | 50 | 33 |  |  |  |  | 
|  |  | 0 | 0 |  |  |  |  | 
|  |  | 0 | 0 |  |  |  |  | 
| 73 |  |  |  |  |  |  | # noop | 
| 74 |  |  |  |  |  |  | } | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | # validation failed with no errors | 
| 77 |  |  |  |  |  |  | elsif ($failed && !$errors) { | 
| 78 | 2 |  |  |  |  | 29 | $self->error(@_); | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | # validation passed with errors | 
| 82 |  |  |  |  |  |  | elsif (!$failed && $errors) { | 
| 83 |  |  |  |  |  |  | # noop -- but acknowledge errors have been set | 
| 84 |  |  |  |  |  |  | } | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | # validation failed with errors | 
| 87 |  |  |  |  |  |  | elsif ($failed && $errors) { | 
| 88 |  |  |  |  |  |  | # assume errors have been set from inside the validation routine | 
| 89 |  |  |  |  |  |  | } | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | } | 
| 92 |  |  |  |  |  |  |  | 
| 93 | 15 |  |  |  |  | 46 | return $self; | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | } | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | 1; | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | __END__ |