| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # ABSTRACT: Between Directive for Validation Class Field Definitions | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | package Validation::Class::Directive::Between; | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 109 |  |  | 109 |  | 43574 | use strict; | 
|  | 109 |  |  |  |  | 215 |  | 
|  | 109 |  |  |  |  | 2615 |  | 
| 6 | 109 |  |  | 109 |  | 484 | use warnings; | 
|  | 109 |  |  |  |  | 197 |  | 
|  | 109 |  |  |  |  | 2397 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 109 |  |  | 109 |  | 483 | use base 'Validation::Class::Directive'; | 
|  | 109 |  |  |  |  | 199 |  | 
|  | 109 |  |  |  |  | 8455 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 109 |  |  | 109 |  | 632 | use Validation::Class::Util; | 
|  | 109 |  |  |  |  | 217 |  | 
|  | 109 |  |  |  |  | 544 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | our $VERSION = '7.900058'; # VERSION | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | has 'mixin'   => 1; | 
| 16 |  |  |  |  |  |  | has 'field'   => 1; | 
| 17 |  |  |  |  |  |  | has 'multi'   => 1; | 
| 18 |  |  |  |  |  |  | has 'message' => '%s must contain between %s characters'; | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | sub validate { | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 5 |  |  | 5 | 0 | 10 | my $self = shift; | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 5 |  |  |  |  | 11 | my ($proto, $field, $param) = @_; | 
| 25 |  |  |  |  |  |  |  | 
| 26 | 5 | 50 | 33 |  |  | 27 | if (defined $field->{between} && defined $param) { | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 5 |  |  |  |  | 10 | my $between = $field->{between}; | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 5 | 50 | 66 |  |  | 21 | if ( $field->{required} || $param ) { | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | my ( $min, $max ) | 
| 33 |  |  |  |  |  |  | = isa_arrayref($between) | 
| 34 | 3 |  |  |  |  | 29 | ? @{$between} > 1 | 
| 35 | 5 | 50 |  |  |  | 15 | ? @{$between} | 
|  | 0 | 100 |  |  |  | 0 |  | 
| 36 |  |  |  |  |  |  | : (split /(?:\s{1,})?\D{1,}(?:\s{1,})?/, $between->[0]) | 
| 37 |  |  |  |  |  |  | : (split /(?:\s{1,})?\D{1,}(?:\s{1,})?/, $between); | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 5 |  |  |  |  | 11 | $min = scalar($min); | 
| 40 | 5 |  |  |  |  | 9 | $max = scalar($max); | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 5 |  |  |  |  | 8 | my $value = length($param); | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 5 | 100 | 66 |  |  | 26 | unless ( $value >= $min && $value <= $max ) { | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 1 |  |  |  |  | 12 | $self->error(@_, "$min-$max"); | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 5 |  |  |  |  | 15 | return $self; | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | 1; | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | __END__ |