Syccess/Validator/Length.pm

filter: Statementstmt 95.1% 39 / 41 Branchbran 88.2% 30 / 34 Conditioncond 77.7% 14 / 18 MC/DCmcdc 63.6% 7 / 11 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 85.7% 96 / 112 CC 24 SCAR 20.1
CC
24
Cov
89%
validator
11.0
_build_message
6.0
_build_format
6.0
CRAP 7.4
« Syccess/Result.pm ↑ Summary Syccess/Validator/Call.pm »
1 package Syccess::Validator::Length;
2 2 our $AUTHORITY = 'cpan:GETTY';
3 # ABSTRACT: A validator to check the length of the value in chars
4 2 $Syccess::Validator::Length::VERSION = '0.104';
5 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 with qw(
9 Syccess::ValidatorSimple
10 );
11  
12 2 has min => (
13 is => 'ro',
14 predicate => 1,
15 );
16  
17 2 has max => (
18 is => 'ro',
19 predicate => 1,
20 );
21  
22 4 ▶sub BUILD {
Subroutine BUILD: called CC=4 SCAR=16.1
Pod undocumented
23 4 my ( $self ) = @_;
24 4 ▶ croak __PACKAGE__.' cant have arg (specific length) and min/max'
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_arg and $self->has_min || $self->has_max 0 4 4
Condition50%3/6
$self->has_arg and $self->has_min || $self->has_max
!ll&&!rl&&r
310
$self->has_min or $self->has_max
l!l&&r!l&&!r
001
MC/DC0%0/3
$self->has_arg and $self->has_min || $self->has_max
$self->has_arg $self->has_min $self->has_max
Truth table50%2/4
A and B or C
A= $self->has_argB= $self->has_minC= $self->has_max
ABCresult
0XX0
1000
11X1
1011
25 if $self->has_arg && ( $self->has_min || $self->has_max );
26 }
27  
28 2 has message => (
29 is => 'lazy',
30 );
31  
32 4 ▶sub _build_message {
Subroutine _build_message: called CC=6 SCAR=18.0
33 4 my ( $self ) = @_;
34 4 ▶ if ($self->has_arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_arg) { } 1 3 4
35 1 return [ $self->format, $self->arg ];
36 } else {
37 3 ▶ if ($self->has_min && $self->has_max) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->has_min and $self->has_max) { } 1 2 3
elsif ($self->has_min) { } 1 1 2
elsif ($self->has_max) { } 1 0 1
Condition100%3/3
$self->has_min and $self->has_max
!ll&&!rl&&r
111
MC/DC100%2/2
$self->has_min and $self->has_max
$self->has_min $self->has_max
Truth table100%3/3
A and B
A= $self->has_minB= $self->has_max
ABresult
0X0
100
111
38 1 return [ $self->format, $self->min, $self->max ];
39 } elsif ($self->has_min) {
40 1 return [ $self->format, $self->min ];
41 } elsif ($self->has_max) {
42 1 return [ $self->format, $self->max ];
43 }
44 }
45 0 croak __PACKAGE__.' needs an arg, min or max value';
46 }
47  
48 2 has format => (
49 is => 'lazy',
50 );
51  
52 4 ▶sub _build_format {
Subroutine _build_format: called CC=6 SCAR=18.0
53 4 my ( $self ) = @_;
54 4 ▶ if ($self->has_arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_arg) { } 1 3 4
55 1 return '%s must be exactly %s characters.';
56 } else {
57 3 ▶ if ($self->has_min && $self->has_max) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->has_min and $self->has_max) { } 1 2 3
elsif ($self->has_min) { } 1 1 2
elsif ($self->has_max) { } 1 0 1
Condition100%3/3
$self->has_min and $self->has_max
!ll&&!rl&&r
111
MC/DC100%2/2
$self->has_min and $self->has_max
$self->has_min $self->has_max
Truth table100%3/3
A and B
A= $self->has_minB= $self->has_max
ABresult
0X0
100
111
58 1 return '%s must be between %s and %s characters.';
59 } elsif ($self->has_min) {
60 1 return '%s must be at least %s characters.';
61 } elsif ($self->has_max) {
62 1 return '%s is not allowed to be more than %s characters.';
63 }
64 }
65 0 croak __PACKAGE__.' needs an arg, min or max value';
66 }
67  
68 10 ▶sub validator {
Subroutine validator: called CC=11 SCAR=24.0
Pod undocumented
69 10 my ( $self, $value ) = @_;
70 10 my $length = length($value);
71 10 ▶ if ($self->has_arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_arg) { } 3 7 10
72 3 ▶ return $self->message if $length != $self->arg;
Branch: 1 branch
BranchTrueFalseTotal
if $length != $self->arg 2 1 3
73 } else {
74 7 ▶ if ($self->has_min && $self->has_max) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->has_min and $self->has_max) { } 2 5 7
elsif ($self->has_min) { } 3 2 5
elsif ($self->has_max) { } 2 0 2
Condition100%3/3
$self->has_min and $self->has_max
!ll&&!rl&&r
232
MC/DC100%2/2
$self->has_min and $self->has_max
$self->has_min $self->has_max
Truth table100%3/3
A and B
A= $self->has_minB= $self->has_max
ABresult
0X0
100
111
75 2 ▶ return $self->message if $length < $self->min || $length > $self->max;
Branch: 1 branch
BranchTrueFalseTotal
if $length < $self->min or $length > $self->max 1 1 2
Condition66%2/3
$length < $self->min or $length > $self->max
l!l&&r!l&&!r
101
MC/DC50%1/2
$length < $self->min or $length > $self->max
$length < $self->min $length > $self->max
Truth table66%2/3
A or B
A= $length < $self->minB= $length > $self->max
ABresult
1X1
011
000
76 } elsif ($self->has_min) {
77 3 ▶ return $self->message if $length < $self->min;
Branch: 1 branch
BranchTrueFalseTotal
if $length < $self->min 2 1 3
78 } elsif ($self->has_max) {
79 2 ▶ return $self->message if $length > $self->max;
Branch: 1 branch
BranchTrueFalseTotal
if $length > $self->max 1 1 2
80 }
81 }
82 4 return;
83 }
84  
85 2 1;
86  
87 __END__
« Syccess/Result.pm ↑ Summary Syccess/Validator/Call.pm »