FormValidator/Validator/Alpha.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/Same.pm ↑ Summary FormValidator/Validator/AlphaNum.pm »
1 package Dancer2::Plugin::FormValidator::Validator::Alpha;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 with 'Dancer2::Plugin::FormValidator::Role::Validator';
11  
12 use constant {
13 4 UNICODE => 'u',
14 ASCII => 'a',
15 4 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 4 has encoding => (
18 is => 'rw',
19 default => ASCII,
20 );
21  
22 sub message {
23 3 ▶ my $encoding = $_[0]->encoding;
Subroutine message: called CC=2 SCAR=6.9
Pod undocumented
24  
25 3 ▶ if ($encoding eq UNICODE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($encoding eq "u") 1 2 3
26 return {
27 1 en => '%s must contain only alphabetical symbols',
28 ru => '%s должно содержать только символы алфавита',
29 de => '%s darf nur alphabetische Zeichen enthalten',
30 };
31 }
32  
33 return {
34 2 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 6 ▶ my ($self, $field, $input, $encoding) = @_;
Subroutine validate: called CC=4 SCAR=14.1
Pod undocumented
42  
43 6 my $regex;
44  
45 6 ▶ if (defined $encoding and $encoding eq UNICODE) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $encoding and $encoding eq 'u') { } 3 3 6
Condition66%2/3
defined $encoding and $encoding eq "u"
!ll&&!rl&&r
303
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 3 $regex = qr/^[[:alpha:]]+$/;
47 3 $self->encoding(UNICODE);
48 }
49 else {
50 3 $regex = qr/^[[:alpha:]]+$/a;
51 3 $self->encoding(ASCII);
52 }
53  
54 6 ▶ if ($self->_field_defined_and_non_empty($field, $input)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_field_defined_and_non_empty($field, $input)) 6 0 6
55 6 return $input->{$field} =~ $regex;
56 }
57  
58 0 return 1;
59 }
60  
61 4 1;
« FormValidator/Validator/Same.pm ↑ Summary FormValidator/Validator/AlphaNum.pm »