| 1 | package Validator::Lazy::Role::Check::IsIn; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | Validator::Lazy::Role::Check::IsIn | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 VERSION | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | Version 0.03 | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | use Validator::Lazy; | ||||||||||||||||||||||||||||
| 17 | my $v = Validator::Lazy->new( { isin => { IsIn => [ your list of allowed values ] } } ); | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | my $ok = $v->check( isin => 'your value' ); | ||||||||||||||||||||||||||||
| 20 | say Dumper $v->errors; # [ { code => 'ISIN_ERROR', field => 'isin', data => { required => [ your list of allowed values ] } } ] | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | An internal Role for Validator::Lazy, part of Validator::Lazy package. | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | Provides "IsIn" type for Validator::Lazy config. | ||||||||||||||||||||||||||||
| 28 | Allows to check value's existance in list from config. | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head1 METHODS | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =head2 C<check> | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | Called from inside if Validator::Lazy->check process | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | Temporary overrides internal Validator::Lazy::check method like this: | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | $validator->check( $value, $param ); | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | $param - list of allowed for field values. | ||||||||||||||||||||||||||||
| 42 | $value - your value to check | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =head1 SUPPORT AND DOCUMENTATION | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | After installing, you can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | perldoc Validator::Lazy | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | You can also look for information at: | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | RT, CPAN's request tracker (report bugs here) | ||||||||||||||||||||||||||||
| 54 | http://rt.cpan.org/NoAuth/Bugs.html?Dist=Validator-Lazy | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | AnnoCPAN, Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 57 | http://annocpan.org/dist/Validator-Lazy | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | CPAN Ratings | ||||||||||||||||||||||||||||
| 60 | http://cpanratings.perl.org/d/Validator-Lazy | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Search CPAN | ||||||||||||||||||||||||||||
| 63 | http://search.cpan.org/dist/Validator-Lazy/ | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | ANTONC <antonc@cpan.org> | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 73 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||||||||||||||||||||
| 74 | copy of the full license at: | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =cut | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 3 | ▶ | use v5.14.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 81 | 3 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 82 | 3 | ▶ | use Modern::Perl; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 83 | 3 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 6 | ▶ | sub check { | ||||||||||||||||||||||||||
|
Subroutine
check: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 6 | my ( $self, $value, $param ) = @_; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 6 | ▶ | return $value unless $value && $param; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$value and $param
MC/DC50%1/2
$value and $param
$value
$param
Truth table66%2/3
A and B
A= $valueB= $param
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 4 | ▶ | $param = [ $param ] unless ref $param; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 4 | my @set = @$param; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 4 | ▶ | unless ( grep /^$value$/sm, @set ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 2 | $self->add_error( { required => \@set } ); | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 2 | return $value; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 2 | return $value; | |||||||||||||||||||||||||||
| 100 | }; | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 3 | 1; | |||||||||||||||||||||||||||