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