| 1 | package Chloro::ResultSet; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 11 | our $VERSION = '0.07'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use Chloro::Error::Form; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use Chloro::Types qw( ArrayRef Bool HashRef ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 11 | ▶ | use List::AllUtils qw( any ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 11 | with 'Chloro::Role::ResultSet'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 11 | has _form_errors => ( | |||||||||||||||||||||||||||
| 19 | traits => ['Array'], | ||||||||||||||||||||||||||||
| 20 | isa => ArrayRef ['Chloro::Error::Form'], | ||||||||||||||||||||||||||||
| 21 | init_arg => 'form_errors', | ||||||||||||||||||||||||||||
| 22 | required => 1, | ||||||||||||||||||||||||||||
| 23 | handles => { | ||||||||||||||||||||||||||||
| 24 | form_errors => 'elements', | ||||||||||||||||||||||||||||
| 25 | add_form_error => 'push', | ||||||||||||||||||||||||||||
| 26 | _has_form_errors => 'count', | ||||||||||||||||||||||||||||
| 27 | }, | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 11 | has _params => ( | |||||||||||||||||||||||||||
| 31 | is => 'ro', | ||||||||||||||||||||||||||||
| 32 | isa => HashRef, | ||||||||||||||||||||||||||||
| 33 | init_arg => 'params', | ||||||||||||||||||||||||||||
| 34 | required => 1, | ||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 11 | has is_valid => ( | |||||||||||||||||||||||||||
| 38 | is => 'ro', | ||||||||||||||||||||||||||||
| 39 | isa => Bool, | ||||||||||||||||||||||||||||
| 40 | init_arg => undef, | ||||||||||||||||||||||||||||
| 41 | lazy => 1, | ||||||||||||||||||||||||||||
| 42 | builder => '_build_is_valid', | ||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 12 | ▶ | sub _build_is_valid { | ||||||||||||||||||||||||||
|
Subroutine
_build_is_valid: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 46 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 12 | ▶ | return 0 if $self->_has_form_errors(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 9 | ▶ | return 0 if any { !$_->is_valid() } $self->_result_values(); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 7 | return 1; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 11 | ▶ | sub results_as_hash { | ||||||||||||||||||||||||||
|
Subroutine
results_as_hash: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 11 | my $self = shift; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 11 | return $self->_results_hash(); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub secure_results_as_hash { | ||||||||||||||||||||||||||
|
Subroutine
secure_results_as_hash: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | return $self->_results_hash('skip secure'); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 11 | ▶ | sub _results_hash { | ||||||||||||||||||||||||||
|
Subroutine
_results_hash: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 68 | 11 | my $self = shift; | |||||||||||||||||||||||||||
| 69 | 11 | my $skip_secure = shift; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 11 | my %hash; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 11 | for my $result ( $self->_result_values() ) { | |||||||||||||||||||||||||||
| 74 | 23 | ▶ | if ( $result->can('group') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 6 | $hash{ $result->group()->name() }{ $result->key() } | |||||||||||||||||||||||||||
| 76 | = { $result->key_value_pairs($skip_secure) }; | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 6 | my $group = $result->group(); | |||||||||||||||||||||||||||
| 79 | 6 | my $rep_key = $group->repetition_key(); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 6 | ▶ | unless ( exists $hash{$rep_key} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 4 | my $rep_vals = $self->_params()->{$rep_key}; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | my @vals | ||||||||||||||||||||||||||||
| 85 | 7 | ▶ | = grep { $self->result_for( $group->name() . q{.} . $_ ) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 4 | ref $rep_vals ? @{$rep_vals} : $rep_vals; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 4 | $hash{$rep_key} = \@vals; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | else { | ||||||||||||||||||||||||||||
| 92 | 17 | ▶ | next if $skip_secure && $result->field()->is_secure(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$skip_secure and $result->field->is_secure
MC/DC0%0/2
$skip_secure and $result->field->is_secure
$skip_secure
$result->field->is_secure
Truth table33%1/3
A and B
A= $skip_secureB= $result->field->is_secure
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 17 | %hash = ( %hash, $result->key_value_pairs() ); | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 11 | return \%hash; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub secure_raw_params { | ||||||||||||||||||||||||||
|
Subroutine
secure_raw_params: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | my %hash = %{ $self->_params() }; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | for my $result ( $self->_result_values() ) { | |||||||||||||||||||||||||||
| 107 | 0 | ▶ | if ( $result->can('group') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | for my $field_result ( grep { $_->field()->is_secure() } | |||||||||||||||||||||||||||
| 109 | $result->_result_values() ) { | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | delete $hash{ $result->group()->prefix() . q{.} | |||||||||||||||||||||||||||
| 112 | . $field_result->field()->name() }; | ||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | else { | ||||||||||||||||||||||||||||
| 116 | 0 | ▶ | next unless $result->field()->is_secure(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | delete $hash{ $result->field()->name() }; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | return \%hash; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 2 | ▶ | sub field_errors { | ||||||||||||||||||||||||||
|
Subroutine
field_errors: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 2 | my %errors; | |||||||||||||||||||||||||||
| 129 | 2 | for my $result ( grep { !$_->is_valid() } $self->_result_values() ) { | |||||||||||||||||||||||||||
| 130 | 3 | ▶ | if ( $result->can('group') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 1 | for my $field_result ( grep { !$_->is_valid() } | |||||||||||||||||||||||||||
| 132 | $result->_result_values() ) { | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 2 | my $key = join q{.}, $result->prefix(), | |||||||||||||||||||||||||||
| 135 | $field_result->field()->name(); | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 2 | $errors{$key} = [ $field_result->errors() ]; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | else { | ||||||||||||||||||||||||||||
| 141 | 2 | $errors{ $result->field()->name() } = [ $result->errors() ]; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 2 | return %errors; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | ▶ | sub all_errors { | ||||||||||||||||||||||||||
|
Subroutine
all_errors: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 149 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | my %field_errors = $self->field_errors(); | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | return $self->form_errors(), map { @{$_} } values %field_errors; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 11 | __PACKAGE__->meta()->make_immutable(); | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 11 | 1; | |||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | # ABSTRACT: The set of results from processing a form submission | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | __END__ | ||||||||||||||||||||||||||||