| 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
Condition50%3/6
$self->has_arg and $self->has_min || $self->has_max
$self->has_min or $self->has_max
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | return [ $self->format, $self->arg ]; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | ▶ | if ($self->has_min && $self->has_max) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$self->has_min and $self->has_max
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | return '%s must be exactly %s characters.'; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | ▶ | if ($self->has_min && $self->has_max) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$self->has_min and $self->has_max
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 3 | ▶ | return $self->message if $length != $self->arg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 7 | ▶ | if ($self->has_min && $self->has_max) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$self->has_min and $self->has_max
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
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | ▶ | return $self->message if $length < $self->min || $length > $self->max; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$length < $self->min or $length > $self->max
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
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | } elsif ($self->has_min) { | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 3 | ▶ | return $self->message if $length < $self->min; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | } elsif ($self->has_max) { | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | ▶ | return $self->message if $length > $self->max; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | __END__ | ||||||||||||||||||||||||||||||||||||||||||