| 1 | package Syccess::Result; | ||||||||||||||||||||||||||||||||
| 2 | 9 | our $AUTHORITY = 'cpan:GETTY'; | |||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: A validation process result | ||||||||||||||||||||||||||||||||
| 4 | 9 | $Syccess::Result::VERSION = '0.104'; | |||||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use Module::Runtime qw( use_module ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 9 | with qw( | |||||||||||||||||||||||||||||||
| 9 | MooX::Traits | ||||||||||||||||||||||||||||||||
| 10 | ); | ||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 9 | has syccess => ( | |||||||||||||||||||||||||||||||
| 13 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 14 | required => 1, | ||||||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 9 | has params => ( | |||||||||||||||||||||||||||||||
| 18 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 19 | required => 1, | ||||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 9 | has success => ( | |||||||||||||||||||||||||||||||
| 23 | is => 'lazy', | ||||||||||||||||||||||||||||||||
| 24 | init_arg => undef, | ||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 19 | ▶ | sub _build_success { | ||||||||||||||||||||||||||||||
|
Subroutine
_build_success: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 28 | 19 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||
| 29 | 19 | ▶ | return $self->error_count ? 0 : 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 9 | has error_count => ( | |||||||||||||||||||||||||||||||
| 33 | is => 'lazy', | ||||||||||||||||||||||||||||||||
| 34 | init_arg => undef, | ||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 19 | ▶ | sub _build_error_count { | ||||||||||||||||||||||||||||||
|
Subroutine
_build_error_count: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 38 | 19 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||
| 39 | 19 | return scalar @{$self->errors}; | |||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 9 | has errors => ( | |||||||||||||||||||||||||||||||
| 43 | is => 'lazy', | ||||||||||||||||||||||||||||||||
| 44 | init_arg => undef, | ||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | 39 | ▶ | around errors => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||
| 48 | 39 | my ( $orig, $self, @args ) = @_; | |||||||||||||||||||||||||||||||
| 49 | 39 | my @errors = @{$self->$orig()}; | |||||||||||||||||||||||||||||||
| 50 | 39 | ▶ | return [ @errors ] unless scalar @args > 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 51 | 9 | my @args_errors; | |||||||||||||||||||||||||||||||
| 52 | 9 | for my $error (@errors) { | |||||||||||||||||||||||||||||||
| 53 | 28 | for my $arg (@args) { | |||||||||||||||||||||||||||||||
| 54 | 28 | ▶ | push @args_errors, $error if $error->syccess_field->name eq $arg; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||
| 57 | 9 | return [ @args_errors ]; | |||||||||||||||||||||||||||||||
| 58 | 9 | }; | |||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 9 | has error_class => ( | |||||||||||||||||||||||||||||||
| 61 | is => 'lazy', | ||||||||||||||||||||||||||||||||
| 62 | init_arg => undef, | ||||||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 11 | ▶ | sub _build_error_class { | ||||||||||||||||||||||||||||||
|
Subroutine
_build_error_class: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 66 | 11 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||
| 67 | 11 | my $error_class = use_module($self->syccess->error_class); | |||||||||||||||||||||||||||||||
| 68 | 11 | ▶ | if ($self->syccess->has_error_traits) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 69 | 2 | $error_class = $error_class->with_traits(@{$self->syccess->error_traits}); | |||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||
| 71 | 11 | return $error_class; | |||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | 19 | ▶ | sub _build_errors { | ||||||||||||||||||||||||||||||
|
Subroutine
_build_errors: called CC=9 SCAR=29.1
| |||||||||||||||||||||||||||||||||
| 75 | 19 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||
| 76 | 19 | my %params = %{$self->params}; | |||||||||||||||||||||||||||||||
| 77 | 19 | my @fields = @{$self->syccess->fields}; | |||||||||||||||||||||||||||||||
| 78 | my %errors_args = $self->syccess->has_errors_args | ||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | ? (%{$self->syccess->errors_args}) : (); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 80 | 19 | my @errors; | |||||||||||||||||||||||||||||||
| 81 | 19 | for my $field (@fields) { | |||||||||||||||||||||||||||||||
| 82 | 43 | my @messages = $field->validate( %params ); | |||||||||||||||||||||||||||||||
| 83 | 43 | for my $message (@messages) { | |||||||||||||||||||||||||||||||
| 84 | 22 | my $ref = ref $message; | |||||||||||||||||||||||||||||||
| 85 | 22 | ▶ | if ($ref eq 'ARRAY' or !ref) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$ref eq "ARRAY" or not ref $_
MC/DC0%0/2
$ref eq "ARRAY" or not ref $_
$ref eq "ARRAY"
not ref $_
Truth table66%2/3
A or not(B)
A= $ref eq "ARRAY"B= not ref $_
| |||||||||||||||||||||||||||||||||
| 86 | 22 | push @errors, $self->error_class->new( | |||||||||||||||||||||||||||||||
| 87 | %errors_args, | ||||||||||||||||||||||||||||||||
| 88 | message => $message, | ||||||||||||||||||||||||||||||||
| 89 | syccess_field => $field, | ||||||||||||||||||||||||||||||||
| 90 | syccess_result => $self, | ||||||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||||||
| 92 | } elsif ($ref eq 'HASH') { | ||||||||||||||||||||||||||||||||
| 93 | 0 | my %error_args = %{$message}; | |||||||||||||||||||||||||||||||
| 94 | 0 | push @errors, $self->error_class->new( | |||||||||||||||||||||||||||||||
| 95 | %errors_args, | ||||||||||||||||||||||||||||||||
| 96 | %error_args, | ||||||||||||||||||||||||||||||||
| 97 | syccess_field => $field, | ||||||||||||||||||||||||||||||||
| 98 | syccess_result => $self, | ||||||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||||||
| 100 | } else { | ||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if (%errors_args && $message->can('errors_args')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
%errors_args and $message->can("errors_args")
MC/DC0%0/2
%errors_args and $message->can("errors_args")
%errors_args
$message->can("errors_args")
Truth table0%0/3
A and B
A= %errors_argsB= $message->can("errors_args")
| |||||||||||||||||||||||||||||||||
| 102 | 0 | $message->errors_args({ %errors_args }); | |||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||
| 104 | 0 | push @errors, $message; | |||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||
| 108 | 19 | return [ @errors ]; | |||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | 9 | 1; | |||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | __END__ | ||||||||||||||||||||||||||||||||