| 1 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package HTML::FormFu::Validator; | ||||||||||||||||||||||||||||
| 4 | 7 | $HTML::FormFu::Validator::VERSION = '2.09'; | |||||||||||||||||||||||||||
| 5 | # ABSTRACT: Validator Base Class | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 7 | extends 'HTML::FormFu::Processor'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use HTML::FormFu::Exception::Validator; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use Scalar::Util qw( reftype blessed ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 8 | ▶ | sub process { | ||||||||||||||||||||||||||
|
Subroutine
process: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 8 | my ( $self, $params ) = @_; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 8 | my $value = $self->get_nested_hash_value( $params, $self->nested_name ); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 8 | my @errors; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 8 | ▶ | if ( ( reftype($value) || '' ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
builtin::reftype($value) || ''
MC/DC100%1/1
builtin::reftype($value) || ''
builtin::reftype($value)
Truth table100%2/2
A
A= builtin::reftype($value)
| |||||||||||||||||||||||||||||
| 22 | 2 | push @errors, eval { $self->validate_values( $value, $params ) }; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 0 | push @errors, $self->return_error($@); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | else { | ||||||||||||||||||||||||||||
| 29 | 6 | my $ok = eval { $self->validate_value( $value, $params ) }; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 6 | ▶ | if ( $@ or !$ok ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$@ or not $ok
MC/DC50%1/2
$@ or not $ok
$@
not $ok
Truth table66%2/3
A or not(B)
A= $@B= not $ok
| |||||||||||||||||||||||||||||
| 32 | 1 | push @errors, $self->return_error($@); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 8 | return @errors; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 2 | ▶ | sub validate_values { | ||||||||||||||||||||||||||
|
Subroutine
validate_values: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | 2 | my ( $self, $values, $params ) = @_; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 2 | my @errors; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 2 | for my $value (@$values) { | |||||||||||||||||||||||||||
| 45 | 6 | my $ok = eval { $self->validate_value( $value, $params ) }; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 6 | ▶ | push @errors, $self->return_error($@) if !$ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | return @errors; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub validate_value { | ||||||||||||||||||||||||||
|
Subroutine
validate_value: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 0 | croak "validate() should be overridden"; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1 | ▶ | sub return_error { | ||||||||||||||||||||||||||
|
Subroutine
return_error: called CC=4 SCAR=18.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 58 | 1 | my ( $self, $err ) = @_; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 1 | ▶ | if ( !blessed $err || !$err->isa('HTML::FormFu::Exception::Validator') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($err) and $err->isa("HTML::FormFu::Exception::Validator")
MC/DC0%0/2
builtin::blessed($err) and $err->isa("HTML::FormFu::Exception::Validator")
builtin::blessed($err)
$err->isa("HTML::FormFu::Exception::Validator")
Truth table33%1/3
A and B
A= builtin::blessed($err)B= $err->isa("HTML::FormFu::Exception::Validator")
| |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | $err = HTML::FormFu::Exception::Validator->new( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | $err ? { message => $err } : () ); | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | return $err; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 7 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 7 | 1; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||