| 1 | package Catalyst::Utils::StructuredParameters; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Storable qw(dclone); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Catalyst::Utils; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Catalyst::Exception::MissingParameter; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Catalyst::Exception::InvalidArrayPointer; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Catalyst::Exception::InvalidArrayLength; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 2 | our $MAX_ARRAY_DEPTH = 1000; | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 2 | has context => (is=>'ro', required=>1); | |||||||||||||||||||||||||||||||
| 13 | 2 | has _namespace => (is=>'rw', required=>0, isa=>'ArrayRef', predicate=>'has_namespace', init_arg=>'namespace'); | |||||||||||||||||||||||||||||||
| 14 | 2 | has _flatten_array_value => (is=>'rw', required=>1, init_arg=>'flatten_array_value'); | |||||||||||||||||||||||||||||||
| 15 | 2 | has _current => (is=>'rw', required=>0, init_arg=>undef); | |||||||||||||||||||||||||||||||
| 16 | 2 | has _required => (is=>'rw', required=>0, init_arg=>undef); | |||||||||||||||||||||||||||||||
| 17 | 2 | has _src => (is=>'ro', required=>1, init_arg=>'src'); | |||||||||||||||||||||||||||||||
| 18 | 2 | has _max_array_depth => (is=>'ro', required=>1, init_arg=>'max_array_depth', default=>$MAX_ARRAY_DEPTH); | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | sub namespace { | ||||||||||||||||||||||||||||||
|
Subroutine
namespace: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 21 | 2 | my ($self, $arg) = @_; | |||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | $self->_namespace($arg) if defined($arg); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 23 | 2 | return $self; | |||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub flatten_array_value { | ||||||||||||||||||||||||||||||
|
Subroutine
flatten_array_value: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 27 | 0 | my ($self, $arg) = @_; | |||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | $self->_flatten_array_value($arg) if defined($arg); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 29 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 37 | ▶ | sub max_array_depth { | ||||||||||||||||||||||||||||||
|
Subroutine
max_array_depth: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 33 | 37 | my ($self, $arg) = @_; | |||||||||||||||||||||||||||||||
| 34 | 37 | ▶ | $self->_max_array_depth($arg) if defined($arg); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 35 | 37 | return $self; | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 13 | ▶ | sub permitted { | ||||||||||||||||||||||||||||||
|
Subroutine
permitted: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 39 | 13 | my ($self, @proto) = @_; | |||||||||||||||||||||||||||||||
| 40 | 13 | ▶ | my $namespace = $self->_namespace ||[]; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->_namespace || []
MC/DC100%1/1
$self->_namespace || []
$self->_namespace
Truth table100%2/2
A
A= $self->_namespace
| |||||||||||||||||||||||||||||||||
| 41 | 13 | $self->_required(0); | |||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 13 | ▶ | if(ref $proto[0]) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 44 | 7 | my $namespace_affix = shift @proto; | |||||||||||||||||||||||||||||||
| 45 | 7 | $namespace = [ @$namespace, @$namespace_affix ]; | |||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 13 | my $context = dclone($self->context); | |||||||||||||||||||||||||||||||
| 49 | 13 | my $parsed = $self->_parse($context, $namespace, [@proto]); | |||||||||||||||||||||||||||||||
| 50 | 13 | ▶ | my $current = $self->_current ||+{}; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->_current || {}
MC/DC100%1/1
$self->_current || {}
$self->_current
Truth table100%2/2
A
A= $self->_current
| |||||||||||||||||||||||||||||||||
| 51 | 13 | $current = Catalyst::Utils::merge_hashes($current, $parsed); | |||||||||||||||||||||||||||||||
| 52 | 13 | $self->_current($current); | |||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 13 | return $self; | |||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 4 | ▶ | sub required { | ||||||||||||||||||||||||||||||
|
Subroutine
required: called CC=4 SCAR=14.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 58 | 4 | my ($self, @proto) = @_; | |||||||||||||||||||||||||||||||
| 59 | 4 | ▶ | my $namespace = $self->_namespace ||[]; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_namespace || []
MC/DC0%0/1
$self->_namespace || []
$self->_namespace
Truth table50%1/2
A
A= $self->_namespace
| |||||||||||||||||||||||||||||||||
| 60 | 4 | $self->_required(1); | |||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 4 | ▶ | if(ref $proto[0]) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 63 | 0 | my $namespace_affix = shift @proto; | |||||||||||||||||||||||||||||||
| 64 | 0 | $namespace = [ @$namespace, @$namespace_affix ]; | |||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 4 | my $context = dclone($self->context); | |||||||||||||||||||||||||||||||
| 68 | 4 | my $parsed = $self->_parse($context, $namespace, [@proto]); | |||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | my $current = $self->_current ||+{}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_current || {}
MC/DC0%0/1
$self->_current || {}
$self->_current
Truth table50%1/2
A
A= $self->_current
| |||||||||||||||||||||||||||||||||
| 70 | 2 | $current = Catalyst::Utils::merge_hashes($current, $parsed); | |||||||||||||||||||||||||||||||
| 71 | 2 | $self->_current($current); | |||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 2 | return $self; | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | 9 | ▶ | sub to_hash { | ||||||||||||||||||||||||||||||
|
Subroutine
to_hash: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 77 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||
| 78 | 9 | ▶ | return %{ $self->_current || +{} }; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_current || {}
MC/DC0%0/1
$self->_current || {}
$self->_current
Truth table50%1/2
A
A= $self->_current
| |||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub keys { | ||||||||||||||||||||||||||||||
|
Subroutine
keys: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 82 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | return CORE::keys %{ $self->_current || +{} }; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_current || {}
MC/DC0%0/1
$self->_current || {}
$self->_current
Truth table0%0/2
A
A= $self->_current
| |||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | sub get { | ||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 87 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 88 | 1 | ▶ | return @{ $self->_current || +{} }{@_}; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_current || {}
MC/DC0%0/1
$self->_current || {}
$self->_current
Truth table50%1/2
A
A= $self->_current
| |||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | 32 | ▶ | sub _sorted { | ||||||||||||||||||||||||||||||
|
Subroutine
_sorted: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 92 | 32 | ▶ | return 1 if $a eq ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 93 | 29 | ▶ | return -1 if $b eq ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 94 | 21 | return $a <=> $b; | |||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | 121 | ▶ | sub _normalize_array_value { | ||||||||||||||||||||||||||||||
|
Subroutine
_normalize_array_value: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 98 | 121 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||
| 99 | 121 | ▶ | return $value unless $self->_flatten_array_value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 100 | 63 | ▶ | return ((ref($value)||'') eq 'ARRAY') ? $value->[-1] : $value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $value || ''
MC/DC100%1/1
ref $value || ''
ref $value
Truth table100%2/2
A
A= ref $value
| |||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | 17 | ▶ | sub _parse { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 104 | 17 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||
| 105 | 17 | ▶ | return $self->_src eq 'data' ? $self->_parse_data(@args) : $self->_parse_formlike(@args); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | 71 | ▶ | sub _parse_formlike { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_formlike: called CC=29 SCAR=33.9
| |||||||||||||||||||||||||||||||||
| 109 | 71 | my ($self, $context, $ns, $rules) = @_; | |||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | 71 | my $current = +{}; | |||||||||||||||||||||||||||||||
| 112 | 71 | ▶ | while(@{$rules}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 113 | 147 | my $rule = shift @{$rules}; | |||||||||||||||||||||||||||||||
| 114 | 147 | ▶ | if(ref($rule)||'' eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $rule or
MC/DC100%1/1
ref $rule or
ref $rule
Truth table100%2/2
A
A= ref $rule
| |||||||||||||||||||||||||||||||||
| 115 | 27 | my ($local_ns, $rules) = %$rule; | |||||||||||||||||||||||||||||||
| 116 | 27 | my $key = join('.', @$ns, $local_ns); | |||||||||||||||||||||||||||||||
| 117 | 27 | my %indexes = (); | |||||||||||||||||||||||||||||||
| 118 | 27 | foreach my $context_field (CORE::keys %$context) { | |||||||||||||||||||||||||||||||
| 119 | 717 | my ($i, $under) = ($context_field =~m/^\Q$key\E\[(\d*)\]\.?(.*)$/); | |||||||||||||||||||||||||||||||
| 120 | 717 | ▶ | next unless defined $i; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 121 | 72 | $indexes{$i} = $under; | |||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | 27 | my $found_array_depth = scalar CORE::keys %indexes; | |||||||||||||||||||||||||||||||
| 125 | 27 | ▶ | Catalyst::Exception::InvalidArrayLength->throw( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 126 | pointer=>$local_ns, | ||||||||||||||||||||||||||||||||
| 127 | max=>$self->max_array_depth, | ||||||||||||||||||||||||||||||||
| 128 | attempted=>$found_array_depth | ||||||||||||||||||||||||||||||||
| 129 | ) if $found_array_depth > $self->max_array_depth; | ||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | 27 | foreach my $index(sort _sorted CORE::keys %indexes) { | |||||||||||||||||||||||||||||||
| 132 | 36 | my $cloned_rules = dclone($rules); # each iteration in the loop needs its own copy of the rules; | |||||||||||||||||||||||||||||||
| 133 | 36 | ▶ | $cloned_rules = [''] unless @$cloned_rules; # to handle the bare array case | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 134 | 36 | my $old = $self->_flatten_array_value; | |||||||||||||||||||||||||||||||
| 135 | 36 | ▶ | $self->_flatten_array_value(0) if $index eq ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 136 | 36 | my $value = $self->_parse_formlike( $context, [@$ns, "${local_ns}[$index]"], $cloned_rules); | |||||||||||||||||||||||||||||||
| 137 | 36 | ▶ | if(($index eq '') && $old) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$index eq "" and $old
MC/DC50%1/2
$index eq "" and $old
$index eq ""
$old
Truth table66%2/3
A and B
A= $index eq ""B= $old
| |||||||||||||||||||||||||||||||||
| 138 | 6 | $self->_flatten_array_value($old); | |||||||||||||||||||||||||||||||
| 139 | 6 | ▶ | if( (ref($value)||'') eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
ref $value || ''
MC/DC0%0/1
ref $value || ''
ref $value
Truth table50%1/2
A
A= ref $value
| |||||||||||||||||||||||||||||||||
| 140 | 1 | push @{$current->{$local_ns}}, $_ for @$value; | |||||||||||||||||||||||||||||||
| 141 | ▶ | } elsif((ref($value)||'') eq 'HASH') { | |||||||||||||||||||||||||||||||
|
Condition50%1/2
ref $value || ''
MC/DC0%0/1
ref $value || ''
ref $value
Truth table50%1/2
A
A= ref $value
| |||||||||||||||||||||||||||||||||
| 142 | 5 | ▶ | if(ref $value->{$indexes{$index}}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 143 | 2 | my @values = map { +{ $indexes{$index} => $_ } } @{ $value->{$indexes{$index}} }; | |||||||||||||||||||||||||||||||
| 144 | 2 | push @{$current->{$local_ns}}, @values; | |||||||||||||||||||||||||||||||
| 145 | } else { | ||||||||||||||||||||||||||||||||
| 146 | 3 | push @{$current->{$local_ns}}, $value; | |||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||
| 149 | } else { | ||||||||||||||||||||||||||||||||
| 150 | ## I don't think these are missing params, just a row with invalid fields | ||||||||||||||||||||||||||||||||
| 151 | 30 | ▶ | next if( (ref($value)||'') eq 'HASH') && !%$value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
(ref $value || "") eq "HASH" and not %$value
ref $value || ''
MC/DC100%2/2
(ref $value || "") eq "HASH" and not %$value
ref $value
not %$value
Truth table100%3/3
A and not(B)
A= ref $valueB= not %$value
| |||||||||||||||||||||||||||||||||
| 152 | 29 | push @{$current->{$local_ns}}, $value; | |||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||
| 155 | } else { | ||||||||||||||||||||||||||||||||
| 156 | 120 | ▶ | if((ref($rules->[0])||'') eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $rules->[0] || ''
MC/DC100%1/1
ref $rules->[0] || ''
ref $rules->[0]
Truth table100%2/2
A
A= ref $rules->[0]
| |||||||||||||||||||||||||||||||||
| 157 | 20 | my $value = $self->_parse_formlike( $context, [@$ns, $rule], shift(@$rules) ); | |||||||||||||||||||||||||||||||
| 158 | 20 | ▶ | next unless %$value; # For 'permitted'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 159 | 13 | $current->{$rule} = $value; | |||||||||||||||||||||||||||||||
| 160 | } else { | ||||||||||||||||||||||||||||||||
| 161 | 100 | ▶ | if($rule eq '') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 162 | 15 | my $key = join('.', @$ns); | |||||||||||||||||||||||||||||||
| 163 | 15 | ▶ | unless(defined $context->{$key}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | $self->_required ? Catalyst::Exception::MissingParameter->throw(param=>$key) : next; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||
| 166 | 15 | $current = $self->_normalize_array_value($context->{$key}); | |||||||||||||||||||||||||||||||
| 167 | } else { | ||||||||||||||||||||||||||||||||
| 168 | 85 | my $key = join('.', @$ns, $rule); | |||||||||||||||||||||||||||||||
| 169 | 85 | ▶ | unless(defined $context->{$key}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 170 | 29 | ▶ | $self->_required ? Catalyst::Exception::MissingParameter->throw(param=>$key) : next; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||
| 172 | 56 | $current->{$rule} = $self->_normalize_array_value($context->{$key}); | |||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||
| 177 | 69 | return $current; | |||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||
| 180 | 38 | ▶ | sub _parse_data { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse_data: called CC=29 SCAR=35.3
| |||||||||||||||||||||||||||||||||
| 181 | 38 | my ($self, $context, $ns, $rules) = @_; | |||||||||||||||||||||||||||||||
| 182 | 38 | my $current = +{}; | |||||||||||||||||||||||||||||||
| 183 | 38 | ▶ | MAIN: while(@{$rules}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 184 | 98 | my $rule = shift @{$rules}; | |||||||||||||||||||||||||||||||
| 185 | 98 | ▶ | if(ref($rule)||'' eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $rule or
MC/DC100%1/1
ref $rule or
ref $rule
Truth table100%2/2
A
A= ref $rule
| |||||||||||||||||||||||||||||||||
| 186 | 20 | my ($local_ns, $rules) = %$rule; | |||||||||||||||||||||||||||||||
| 187 | 20 | my $value = $context; | |||||||||||||||||||||||||||||||
| 188 | 20 | foreach my $pointer (@$ns, $local_ns) { | |||||||||||||||||||||||||||||||
| 189 | 30 | ▶ | if(exists($value->{$pointer})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 190 | 20 | $value = $value->{$pointer}; | |||||||||||||||||||||||||||||||
| 191 | } else { | ||||||||||||||||||||||||||||||||
| 192 | 10 | ▶ | $self->_required ? Catalyst::Exception::MissingParameter->throw(param=>join('.', (@$ns, $local_ns))) : next MAIN; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||
| 196 | 10 | ▶ | Catalyst::Exception::InvalidArrayPointer->throw(pointer=>join('.', (@$ns, $local_ns))) unless (ref($value)||'') eq 'ARRAY'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $value || ''
MC/DC0%0/1
ref $value || ''
ref $value
Truth table50%1/2
A
A= ref $value
| |||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||
| 198 | 10 | my $found_array_depth = scalar @$value; | |||||||||||||||||||||||||||||||
| 199 | 10 | ▶ | Catalyst::Exception::InvalidArrayLength->throw( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 200 | pointer=>$local_ns, | ||||||||||||||||||||||||||||||||
| 201 | max=>$self->max_array_depth, | ||||||||||||||||||||||||||||||||
| 202 | attempted=>$found_array_depth | ||||||||||||||||||||||||||||||||
| 203 | ) if $found_array_depth > $self->max_array_depth; | ||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||
| 205 | 10 | my @gathered = (); | |||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||
| 207 | 10 | foreach my $item (@$value) { | |||||||||||||||||||||||||||||||
| 208 | 25 | my $cloned_rules = dclone($rules); # each iteration in the loop needs its own copy of the rules; | |||||||||||||||||||||||||||||||
| 209 | 25 | ▶ | $cloned_rules = [''] unless @$cloned_rules; # to handle the bare array case | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 210 | 25 | my $value = $self->_parse_data($item, [], $cloned_rules); | |||||||||||||||||||||||||||||||
| 211 | ## I don't think these are missing params, just a row with invalid fields | ||||||||||||||||||||||||||||||||
| 212 | 25 | ▶ | next if( (ref($value)||'') eq 'HASH') && !%$value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
(ref $value || "") eq "HASH" and not %$value
ref $value || ''
MC/DC100%2/2
(ref $value || "") eq "HASH" and not %$value
ref $value
not %$value
Truth table100%3/3
A and not(B)
A= ref $valueB= not %$value
| |||||||||||||||||||||||||||||||||
| 213 | 24 | push @gathered, $value; | |||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||
| 215 | 10 | $current->{$local_ns} = \@gathered; | |||||||||||||||||||||||||||||||
| 216 | } else { | ||||||||||||||||||||||||||||||||
| 217 | 78 | ▶ | if((ref($rules->[0])||'') eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $rules->[0] || ''
MC/DC100%1/1
ref $rules->[0] || ''
ref $rules->[0]
Truth table100%2/2
A
A= ref $rules->[0]
| |||||||||||||||||||||||||||||||||
| 218 | 11 | my $value = $self->_parse_data( $context, [@$ns, $rule], shift(@$rules) ); | |||||||||||||||||||||||||||||||
| 219 | 11 | ▶ | next unless %$value; # For 'permitted'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 220 | 6 | $current->{$rule} = $value; | |||||||||||||||||||||||||||||||
| 221 | } else { | ||||||||||||||||||||||||||||||||
| 222 | 67 | ▶ | if($rule eq '') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 223 | 14 | my $value = $context; | |||||||||||||||||||||||||||||||
| 224 | 14 | foreach my $pointer (@$ns) { | |||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | if(((ref($value)||'') eq 'HASH') && exists($value->{$pointer})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
(ref $value || "") eq "HASH" and exists $value->{$pointer}
ref $value || ''
MC/DC0%0/2
(ref $value || "") eq "HASH" and exists $value->{$pointer}
ref $value
exists $value->{$pointer}
Truth table0%0/3
A and B
A= ref $valueB= exists $value->{$pointer}
| |||||||||||||||||||||||||||||||||
| 226 | 0 | $value = $value->{$pointer}; | |||||||||||||||||||||||||||||||
| 227 | } else { | ||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | $self->_required ? Catalyst::Exception::MissingParameter->throw(param=>join('.', (@$ns, $rule))) : next MAIN; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||
| 231 | 14 | $current = $self->_normalize_array_value($value); | |||||||||||||||||||||||||||||||
| 232 | } else { | ||||||||||||||||||||||||||||||||
| 233 | 53 | my $value = $context; | |||||||||||||||||||||||||||||||
| 234 | 53 | foreach my $pointer (@$ns, $rule) { | |||||||||||||||||||||||||||||||
| 235 | 91 | ▶ | if(((ref($value)||'') eq 'HASH') && exists($value->{$pointer})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
(ref $value || "") eq "HASH" and exists $value->{$pointer}
ref $value || ''
MC/DC100%2/2
(ref $value || "") eq "HASH" and exists $value->{$pointer}
ref $value
exists $value->{$pointer}
Truth table100%3/3
A and B
A= ref $valueB= exists $value->{$pointer}
| |||||||||||||||||||||||||||||||||
| 236 | 74 | $value = $value->{$pointer}; | |||||||||||||||||||||||||||||||
| 237 | } else { | ||||||||||||||||||||||||||||||||
| 238 | 17 | ▶ | $self->_required ? Catalyst::Exception::MissingParameter->throw(param=>join('.', (@$ns, $rule))) : next MAIN; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||
| 241 | 36 | $current->{$rule} = $self->_normalize_array_value($value); | |||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||
| 246 | 38 | return $current; | |||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||
| 250 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||
| 252 | 2 | 1; | |||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||
| 254 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||
| 256 | Catalyst::Utils::StructuredParameters - Enforce structural rules on your body and data parameters | ||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||
| 258 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||
| 260 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||
| 262 | See L<Catalyst::TraitFor::Request::StructuredParameters> for usage. These are just utility classes | ||||||||||||||||||||||||||||||||
| 263 | and not likely useful for end user unless you are rolling your own parsing or something. All | ||||||||||||||||||||||||||||||||
| 264 | the publically useful docs are there. | ||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||
| 266 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||
| 268 | This role defines the following attributes: | ||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||
| 270 | TBD | ||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||
| 272 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||
| 274 | This role defines the following methods: | ||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||
| 276 | TBD | ||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||
| 278 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||
| 280 | See L<Catalyst::TraitFor::Request::StructuredParameters> | ||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||
| 282 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||
| 284 | L<Catalyst>, L<Catalyst::Request> | ||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||
| 286 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||
| 288 | See L<Catalyst::TraitFor::Request::StructuredParameters> | ||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||
| 290 | =cut | ||||||||||||||||||||||||||||||||