| 1 | # ABSTRACT: DAO request role - `data` methods | ||||||||||||||||||||||||||||||||||||||||||
| 2 | package PONAPI::DAO::Request::Role::HasDataMethods; | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | sub _validate_data { | ||||||||||||||||||||||||||||||||||||||||||
| 7 | 87 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_data: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | # these are chained to avoid multiple errors on the same issue | ||||||||||||||||||||||||||||||||||||||||||
| 10 | 87 | ▶ | $self->check_data_has_type | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$self->check_data_has_type and $self->check_data_type_match and $self->check_data_attributes
$self->check_data_has_type and $self->check_data_type_match
MC/DC100%3/3
$self->check_data_has_type and $self->check_data_type_match and $self->check_data_attributes
$self->check_data_has_type
$self->check_data_type_match
$self->check_data_attributes
Truth table100%4/4
A and B and C
A= $self->check_data_has_typeB= $self->check_data_type_matchC= $self->check_data_attributes
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | and $self->check_data_type_match | ||||||||||||||||||||||||||||||||||||||||||
| 12 | and $self->check_data_attributes | ||||||||||||||||||||||||||||||||||||||||||
| 13 | and $self->check_data_relationships; | ||||||||||||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | sub check_data_has_type { | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 87 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_data_has_type: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 87 | for ( $self->_get_data_elements ) { | |||||||||||||||||||||||||||||||||||||||||
| 20 | 86 | ▶ | next if ref($_||'') ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$_ || ''
MC/DC100%1/1
$_ || ''
$_
Truth table100%2/2
A
A= $_
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | return $self->_bad_request( "request data has no `type` key" ) | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 85 | ▶ | if !exists $_->{'type'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 85 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | sub check_data_type_match { | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 44 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_data_type_match: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 44 | for ( $self->_get_data_elements ) { | |||||||||||||||||||||||||||||||||||||||||
| 33 | return $self->_bad_request( "conflict between the request type and the data type", 409 ) | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 44 | ▶ | unless $_->{'type'} eq $self->type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 41 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | sub check_data_attributes { | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 82 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_data_attributes: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 82 | my $type = $self->type; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 82 | for my $e ( $self->_get_data_elements ) { | |||||||||||||||||||||||||||||||||||||||||
| 45 | 81 | ▶ | next unless $e and exists $e->{attributes}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$e and exists $e->{"attributes"}
MC/DC100%2/2
$e and exists $e->{"attributes"}
$e
exists $e->{"attributes"}
Truth table100%3/3
A and B
A= $eB= exists $e->{"attributes"}
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 36 | ▶ | $self->repository->type_has_fields( $type, [ keys %{ $e->{'attributes'} } ] ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | or return $self->_bad_request( | ||||||||||||||||||||||||||||||||||||||||||
| 48 | "Type `$type` does not have at least one of the attributes in data" | ||||||||||||||||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 80 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | sub check_data_relationships { | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 80 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_data_relationships: called CC=10 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 80 | my $type = $self->type; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 80 | for my $e ( $self->_get_data_elements ) { | |||||||||||||||||||||||||||||||||||||||||
| 60 | 79 | ▶ | next unless $e and exists $e->{relationships}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$e and exists $e->{"relationships"}
MC/DC100%2/2
$e and exists $e->{"relationships"}
$e
exists $e->{"relationships"}
Truth table100%3/3
A and B
A= $eB= exists $e->{"relationships"}
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 12 | ▶ | if ( %{ $e->{relationships} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 12 | for my $rel_type ( keys %{ $e->{relationships} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 64 | 15 | ▶ | if ( !$self->repository->has_relationship( $type, $rel_type ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | return $self->_bad_request( | |||||||||||||||||||||||||||||||||||||||||
| 66 | "Types `$type` and `$rel_type` are not related", | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 404 | ||||||||||||||||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | ▶ | elsif ( !$self->repository->has_one_to_many_relationship( $type, $rel_type ) | |||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
not $self->repository->has_one_to_many_relationship($type, $rel_type) and ref $e->{"relationships"}{$rel_type} eq "ARRAY" and @{$e->{"relationships"}{$rel_type};} > 1
not $self->repository->has_one_to_many_relationship($type, $rel_type) and ref $e->{"relationships"}{$rel_type} eq "ARRAY"
MC/DC66%2/3
not $self->repository->has_one_to_many_relationship($type, $rel_type) and ref $e->{"relationships"}{$rel_type} eq "ARRAY" and @{$e->{"relationships"}{$rel_type};} > 1
not $self->repository->has_one_to_many_relationship($type, $rel_type)
ref $e->{"relationships"}{$rel_type} eq "ARRAY"
@{$e->{"relationships"}{$rel_type};} > 1
Truth table75%3/4
not(A) and B and C
A= not $self->repository->has_one_to_many_relationship($type, $rel_type)B= ref $e->{"relationships"}{$rel_type} eq "ARRAY"C= @{$e->{"relationships"}{$rel_type};} > 1
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | and ref $e->{relationships}{$rel_type} eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | and @{ $e->{relationships}{$rel_type} } > 1 | |||||||||||||||||||||||||||||||||||||||||
| 73 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | return $self->_bad_request( | |||||||||||||||||||||||||||||||||||||||||
| 75 | "Types `$type` and `$rel_type` are one-to-one, but got multiple values" | ||||||||||||||||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 77 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | sub _get_data_elements { | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 293 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_data_elements: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 293 | ▶ | return ( ref $self->data eq 'ARRAY' ? @{ $self->data } : $self->data ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 8 | ▶ | no Moose::Role; 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | PONAPI::DAO::Request::Role::HasDataMethods - DAO request role - `data` methods | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | version 0.003002 | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | Mickey Nasriachi <mickey@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | Stevan Little <stevan@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | Brian Fraser <hugmeir@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | This software is copyright (c) 2017 by Mickey Nasriachi, Stevan Little, Brian Fraser. | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 129 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | =cut | ||||||||||||||||||||||||||||||||||||||||||