line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Syccess::Validator::Regex; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
2
|
|
|
2
|
|
2843
|
$Syccess::Validator::Regex::AUTHORITY = 'cpan:GETTY'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: A validator to check with a regex |
6
|
|
|
|
|
|
|
$Syccess::Validator::Regex::VERSION = '0.103'; |
7
|
2
|
|
|
2
|
|
12
|
use Moo; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
9
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
with qw( |
10
|
|
|
|
|
|
|
Syccess::ValidatorSimple |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has message => ( |
14
|
|
|
|
|
|
|
is => 'lazy', |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _build_message { |
18
|
1
|
|
|
1
|
|
344
|
return 'Your value for %s is not valid.'; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub validator { |
22
|
4
|
|
|
4
|
0
|
5
|
my ( $self, $value ) = @_; |
23
|
4
|
|
|
|
|
9
|
my $regex = $self->arg; |
24
|
4
|
100
|
|
|
|
111
|
my $r = ref $regex eq 'Regexp' ? $regex : qr{$regex}; |
25
|
4
|
100
|
|
|
|
58
|
return $self->message unless $value =~ m/$r/; |
26
|
2
|
|
|
|
|
11
|
return; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
1; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
__END__ |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=pod |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 NAME |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Syccess::Validator::Regex - A validator to check with a regex |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 VERSION |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
version 0.103 |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 SYNOPSIS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Syccess->new( |
46
|
|
|
|
|
|
|
fields => [ |
47
|
|
|
|
|
|
|
foo => [ regex => qr/^\w+$/ ], |
48
|
|
|
|
|
|
|
bar => [ regex => { |
49
|
|
|
|
|
|
|
arg => '^[a-z]+$', # will be converted to regexp |
50
|
|
|
|
|
|
|
message => 'We only allow lowercase letters on this field.', |
51
|
|
|
|
|
|
|
} ], |
52
|
|
|
|
|
|
|
], |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 DESCRIPTION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This validator allows checking against a regular expression. The regular |
58
|
|
|
|
|
|
|
expression can be given as Regex or plain scalar, which will be converted |
59
|
|
|
|
|
|
|
to a Regex. |
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 |