| 1 | package Dancer2::Plugin::FormValidator::Validator::AlphaNum; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | with 'Dancer2::Plugin::FormValidator::Role::Validator'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | use constant { | ||||||||||||||||||||||||||||
| 13 | 2 | UNICODE => 'u', | |||||||||||||||||||||||||||
| 14 | ASCII => 'a', | ||||||||||||||||||||||||||||
| 15 | 2 | ▶ | }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | has encoding => ( | |||||||||||||||||||||||||||
| 18 | is => 'rw', | ||||||||||||||||||||||||||||
| 19 | default => ASCII, | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | sub message { | ||||||||||||||||||||||||||||
| 23 | 2 | ▶ | my $encoding = $_[0]->encoding; | ||||||||||||||||||||||||||
|
Subroutine
message: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | if ($encoding eq UNICODE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | return { | ||||||||||||||||||||||||||||
| 27 | 1 | en => '%s must contain only alphabetical symbols and/or numbers 0-9', | |||||||||||||||||||||||||||
| 28 | ru => '%s должно содержать только символы алфавита или/и цифры 0-9', | ||||||||||||||||||||||||||||
| 29 | de => '%s darf nur alphabetische Symbole und/oder Zahlen 0-9 enthalten', | ||||||||||||||||||||||||||||
| 30 | }; | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | return { | ||||||||||||||||||||||||||||
| 34 | 1 | en => '%s must contain only latin alphabetical symbols', | |||||||||||||||||||||||||||
| 35 | ru => '%s должно содержать только символы латинского алфавита', | ||||||||||||||||||||||||||||
| 36 | de => '%s darf nur lateinische Zeichen enthalten', | ||||||||||||||||||||||||||||
| 37 | }; | ||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub validate { | ||||||||||||||||||||||||||||
| 41 | 4 | ▶ | my ($self, $field, $input, $encoding) = @_; | ||||||||||||||||||||||||||
|
Subroutine
validate: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 4 | my $regex; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 4 | ▶ | if (defined $encoding and $encoding eq UNICODE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $encoding and $encoding eq "u"
MC/DC50%1/2
defined $encoding and $encoding eq "u"
defined $encoding
$encoding eq "u"
Truth table66%2/3
A and B
A= defined $encodingB= $encoding eq "u"
| |||||||||||||||||||||||||||||
| 46 | 2 | $regex = qr/^\w+$/; | |||||||||||||||||||||||||||
| 47 | 2 | $self->encoding(UNICODE); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | else { | ||||||||||||||||||||||||||||
| 50 | 2 | $regex = qr/^\w+$/a; | |||||||||||||||||||||||||||
| 51 | 2 | $self->encoding(ASCII); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 4 | ▶ | if ($self->_field_defined_and_non_empty($field, $input)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 4 | return $input->{$field} =~ $regex; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | return 1; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 2 | 1; | |||||||||||||||||||||||||||