FormValidator/Validator/AlphaNum.pm

filter: Statementstmt 97.1% 34 / 35 Branchbran 83.3% 5 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 89.2% 50 / 56 CC 5 SCAR 7.9
CC
5
Cov
93%
validate
4.1
message
2.0
BEGIN
1.0
CRAP 2.2
« FormValidator/Validator/Alpha.pm ↑ Summary FormValidator/Role/Validator.pm »
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
BranchTrueFalseTotal
if ($encoding eq "u") 1 1 2
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
BranchTrueFalseTotal
if (defined $encoding and $encoding eq 'u') { } 2 2 4
Condition66%2/3
defined $encoding and $encoding eq "u"
!ll&&!rl&&r
202
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($self->_field_defined_and_non_empty($field, $input)) 4 0 4
55 4 return $input->{$field} =~ $regex;
56 }
57  
58 0 return 1;
59 }
60  
61 2 1;
« FormValidator/Validator/Alpha.pm ↑ Summary FormValidator/Role/Validator.pm »