| 1 | package Syccess::Validator::Regex; | ||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:GETTY'; | |||||||||
| 3 | # ABSTRACT: A validator to check with a regex | ||||||||||
| 4 | 2 | $Syccess::Validator::Regex::VERSION = '0.104'; | |||||||||
| 5 | 2 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | with qw( | |||||||||
| 8 | Syccess::ValidatorSimple | ||||||||||
| 9 | ); | ||||||||||
| 10 | |||||||||||
| 11 | 2 | has message => ( | |||||||||
| 12 | is => 'lazy', | ||||||||||
| 13 | ); | ||||||||||
| 14 | |||||||||||
| 15 | 1 | ▶ | sub _build_message { | ||||||||
|
Subroutine
_build_message: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 1 | return 'Your value for %s is not valid.'; | |||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | 4 | ▶ | sub validator { | ||||||||
|
Subroutine
validator: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 20 | 4 | my ( $self, $value ) = @_; | |||||||||
| 21 | 4 | my $regex = $self->arg; | |||||||||
| 22 | 4 | ▶ | my $r = ref $regex eq 'Regexp' ? $regex : qr{$regex}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 4 | ▶ | return $self->message unless $value =~ m/$r/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 2 | return; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 2 | 1; | |||||||||
| 28 | |||||||||||
| 29 | __END__ | ||||||||||