| 1 | package Syccess::Validator::In; | ||||||||||
| 2 | 3 | our $AUTHORITY = 'cpan:GETTY'; | |||||||||
| 3 | # ABSTRACT: A validator to check if a value is inside of a list of values | ||||||||||
| 4 | 3 | $Syccess::Validator::In::VERSION = '0.104'; | |||||||||
| 5 | 3 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use Carp qw( croak ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 3 | with qw( | |||||||||
| 9 | Syccess::ValidatorSimple | ||||||||||
| 10 | ); | ||||||||||
| 11 | |||||||||||
| 12 | 3 | has message => ( | |||||||||
| 13 | is => 'lazy', | ||||||||||
| 14 | ); | ||||||||||
| 15 | |||||||||||
| 16 | 3 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||
| 17 | 3 | my ( $self ) = @_; | |||||||||
| 18 | 3 | ▶ | croak __PACKAGE__." arg must be ARRAY" unless ref $self->arg eq 'ARRAY'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | 3 | ▶ | sub _build_message { | ||||||||
|
Subroutine
_build_message: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 3 | return 'This value for %s is not allowed.'; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 5 | ▶ | sub validator { | ||||||||
|
Subroutine
validator: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 26 | 5 | my ( $self, $value ) = @_; | |||||||||
| 27 | 5 | my @values = @{$self->arg}; | |||||||||
| 28 | 5 | ▶ | return $self->message unless grep { $value eq $_ } @values; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 2 | return; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 3 | 1; | |||||||||
| 33 | |||||||||||
| 34 | __END__ | ||||||||||