File Coverage

blib/lib/Syccess/Validator/In.pm
Criterion Covered Total %
statement 15 15 100.0
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 23 26 88.4


line stmt bran cond sub pod time code
1             package Syccess::Validator::In;
2             our $AUTHORITY = 'cpan:GETTY';
3             # ABSTRACT: A validator to check if a value is inside of a list of values
4             $Syccess::Validator::In::VERSION = '0.104';
5 3     3   3878 use Moo;
  3         5  
  3         14  
6 3     3   544 use Carp qw( croak );
  3         8  
  3         478  
7              
8             with qw(
9             Syccess::ValidatorSimple
10             );
11              
12             has message => (
13             is => 'lazy',
14             );
15              
16             sub BUILD {
17 3     3 0 1725 my ( $self ) = @_;
18 3 50       26 croak __PACKAGE__." arg must be ARRAY" unless ref $self->arg eq 'ARRAY';
19             }
20              
21             sub _build_message {
22 3     3   22 return 'This value for %s is not allowed.';
23             }
24              
25             sub validator {
26 5     5 0 4 my ( $self, $value ) = @_;
27 5         4 my @values = @{$self->arg};
  5         12  
28 5 100       6 return $self->message unless grep { $value eq $_ } @values;
  15         63  
29 2         6 return;
30             }
31              
32             1;
33              
34             __END__
35              
36             =pod
37              
38             =head1 NAME
39              
40             Syccess::Validator::In - A validator to check if a value is inside of a list of values
41              
42             =head1 VERSION
43              
44             version 0.104
45              
46             =head1 SYNOPSIS
47              
48             Syccess->new(
49             fields => [
50             foo => [ in => [qw( a b c )] ],
51             ],
52             );
53              
54             =head1 DESCRIPTION
55              
56             This validator allows to define a specific list of values which are valid. They
57             are given as ArrayRef.
58              
59             =head1 ATTRIBUTES
60              
61             =head2 message
62              
63             This contains the error message or the format for the error message
64             generation. See L<Syccess::Error/validator_message>.
65              
66             =encoding utf8
67              
68             =head1 SUPPORT
69              
70             IRC
71              
72             Join irc.perl.org and msg Getty
73              
74             Repository
75              
76             http://github.com/Getty/p5-syccess
77             Pull request and additional contributors are welcome
78              
79             Issue Tracker
80              
81             http://github.com/Getty/p5-syccess/issues
82              
83             =head1 AUTHOR
84              
85             Torsten Raudssus <torsten@raudss.us>
86              
87             =head1 COPYRIGHT AND LICENSE
88              
89             This software is copyright (c) 2017 by Torsten Raudssus.
90              
91             This is free software; you can redistribute it and/or modify it under
92             the same terms as the Perl 5 programming language system itself.
93              
94             =cut