PONAPI/DAO/Request/Role/HasDataMethods.pm

filter: Statementstmt 100% 41 / 41 Branchbran 95.4% 21 / 22 Conditioncond 95.0% 19 / 20 MC/DCmcdc 90.9% 10 / 11 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 4 totaltotal 93.4% 99 / 106 CC 24 SCAR 17.7
CC
24
Cov
98%
check_data_relationships
10.0
check_data_has_type
5.0
check_data_attributes
5.0
CRAP 5.8
« Test/PONAPI/Repository/MockDB.pm ↑ Summary Test/PONAPI/Repository/MockDB/Table.pm »
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
BranchTrueFalseTotal
$self->check_data_has_type and $self->check_data_type_match and $self->check_data_attributes and $self->check_data_relationships 80 7 87
Condition100%6/6
$self->check_data_has_type and $self->check_data_type_match and $self->check_data_attributes
!ll&&!rl&&r
5280
$self->check_data_has_type and $self->check_data_type_match
!ll&&!rl&&r
2382
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
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if ref($_ || "") ne "HASH" 1 85 86
Condition100%2/2
$_ || ''
l!l
851
MC/DC100%1/1
$_ || ''
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
21  
22 return $self->_bad_request( "request data has no `type` key" )
23 85 ▶ if !exists $_->{'type'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $_->{"type"} 2 83 85
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
BranchTrueFalseTotal
unless $_->{"type"} eq $self->type 3 41 44
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
BranchTrueFalseTotal
unless $e and exists $e->{"attributes"} 45 36 81
Condition100%3/3
$e and exists $e->{"attributes"}
!ll&&!rl&&r
14436
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"}
ABresult
0X0
100
111
46 36 ▶ $self->repository->type_has_fields( $type, [ keys %{ $e->{'attributes'} } ] )
Branch: 1 branch
BranchTrueFalseTotal
$self->repository->type_has_fields($type, [keys %{$$e{"attributes"};}]) or return $self->_bad_request("Type `$type` does not have at least one of the attributes in data") 2 34 36
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
BranchTrueFalseTotal
unless $e and exists $e->{"relationships"} 67 12 79
Condition100%3/3
$e and exists $e->{"relationships"}
!ll&&!rl&&r
16612
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"}
ABresult
0X0
100
111
61  
62 12 ▶ if ( %{ $e->{relationships} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$e->{"relationships"};}) 12 0 12
63 12 for my $rel_type ( keys %{ $e->{relationships} } ) {
64 15 ▶ if ( !$self->repository->has_relationship( $type, $rel_type ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->repository->has_relationship($type, $rel_type)) { } 2 13 15
elsif (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) { } 1 24 25
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
!ll&&!rl&&r
1201
not $self->repository->has_one_to_many_relationship($type, $rel_type) and ref $e->{"relationships"}{$rel_type} eq "ARRAY"
!ll&&!rl&&r
571
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
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
ref $self->data eq 'ARRAY' ? : 115 178 293
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
« Test/PONAPI/Repository/MockDB.pm ↑ Summary Test/PONAPI/Repository/MockDB/Table.pm »