| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Syccess::Validator::Required; |
|
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GETTY'; |
|
3
|
|
|
|
|
|
|
# ABSTRACT: A validator to check for a required field |
|
4
|
|
|
|
|
|
|
$Syccess::Validator::Required::VERSION = '0.104'; |
|
5
|
2
|
|
|
2
|
|
2594
|
use Moo; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
with qw( |
|
8
|
|
|
|
|
|
|
Syccess::Validator |
|
9
|
|
|
|
|
|
|
); |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has message => ( |
|
12
|
|
|
|
|
|
|
is => 'lazy', |
|
13
|
|
|
|
|
|
|
); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _build_message { |
|
16
|
1
|
|
|
1
|
|
7
|
return '%s is required.'; |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub validate { |
|
20
|
6
|
|
|
6
|
0
|
8
|
my ( $self, %params ) = @_; |
|
21
|
6
|
|
|
|
|
12
|
my $name = $self->syccess_field->name; |
|
22
|
|
|
|
|
|
|
return $self->message if !exists($params{$name}) |
|
23
|
|
|
|
|
|
|
|| !defined($params{$name}) |
|
24
|
6
|
100
|
66
|
|
|
61
|
|| $params{$name} eq ''; |
|
|
|
|
66
|
|
|
|
|
|
25
|
4
|
|
|
|
|
10
|
return; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
1; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
__END__ |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=pod |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 NAME |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Syccess::Validator::Required - A validator to check for a required field |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 VERSION |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
version 0.104 |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Syccess->new( |
|
45
|
|
|
|
|
|
|
fields => [ |
|
46
|
|
|
|
|
|
|
foo => [ required => 1 ], |
|
47
|
|
|
|
|
|
|
bar => [ required => { |
|
48
|
|
|
|
|
|
|
message => 'You have 5 seconds to comply.' |
|
49
|
|
|
|
|
|
|
} ], |
|
50
|
|
|
|
|
|
|
], |
|
51
|
|
|
|
|
|
|
); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
This validator allows to check if a field is required. The default error |
|
56
|
|
|
|
|
|
|
message is B<'%s is required.'> and can be overriden via the L</message> |
|
57
|
|
|
|
|
|
|
parameter. |
|
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 |