|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # ABSTRACT: DAO request role - `data` methods  | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package PONAPI::DAO::Request::Role::HasDataMethods;  | 
| 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
4
 | 
8
 | 
 
 | 
 
 | 
  
8
  
 | 
 
 | 
4214
 | 
 use Moose::Role;  | 
| 
 
 | 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
25
 | 
    | 
| 
 
 | 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
55
 | 
    | 
| 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub _validate_data {  | 
| 
7
 | 
87
 | 
 
 | 
 
 | 
  
87
  
 | 
 
 | 
194
 | 
     my $self = shift;  | 
| 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # these are chained to avoid multiple errors on the same issue  | 
| 
10
 | 
87
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
308
 | 
     $self->check_data_has_type  | 
| 
 
 | 
 
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
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
 | 
 
 | 
 
 | 
  
87
  
 | 
  
0
  
 | 
198
 | 
     my $self = shift;  | 
| 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
19
 | 
87
 | 
 
 | 
 
 | 
 
 | 
 
 | 
243
 | 
     for ( $self->_get_data_elements ) {  | 
| 
20
 | 
86
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
398
 | 
         next if ref($_||'') ne 'HASH';  | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         return $self->_bad_request( "request data has no `type` key" )  | 
| 
23
 | 
85
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
283
 | 
             if !exists $_->{'type'};  | 
| 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
25
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
26
 | 
85
 | 
 
 | 
 
 | 
 
 | 
 
 | 
428
 | 
     return 1;  | 
| 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
29
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub check_data_type_match {  | 
| 
30
 | 
44
 | 
 
 | 
 
 | 
  
44
  
 | 
  
0
  
 | 
90
 | 
     my $self = shift;  | 
| 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
32
 | 
44
 | 
 
 | 
 
 | 
 
 | 
 
 | 
101
 | 
     for ( $self->_get_data_elements ) {  | 
| 
33
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         return $self->_bad_request( "conflict between the request type and the data type", 409 )  | 
| 
34
 | 
44
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
1152
 | 
             unless $_->{'type'} eq $self->type;  | 
| 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
37
 | 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
230
 | 
     return 1;  | 
| 
38
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
40
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub check_data_attributes {  | 
| 
41
 | 
82
 | 
 
 | 
 
 | 
  
82
  
 | 
  
0
  
 | 
160
 | 
     my $self = shift;  | 
| 
42
 | 
82
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2134
 | 
     my $type = $self->type;  | 
| 
43
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
44
 | 
82
 | 
 
 | 
 
 | 
 
 | 
 
 | 
270
 | 
     for my $e ( $self->_get_data_elements ) {  | 
| 
45
 | 
81
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
473
 | 
         next unless $e and exists $e->{attributes};  | 
| 
46
 | 
36
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
995
 | 
         $self->repository->type_has_fields( $type, [ keys %{ $e->{'attributes'} } ] )  | 
| 
 
 | 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
264
 | 
    | 
| 
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
 | 
 
 | 
 
 | 
 
 | 
 
 | 
421
 | 
     return 1;  | 
| 
53
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
54
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
55
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub check_data_relationships {  | 
| 
56
 | 
80
 | 
 
 | 
 
 | 
  
80
  
 | 
  
0
  
 | 
195
 | 
     my $self = shift;  | 
| 
57
 | 
80
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2198
 | 
     my $type = $self->type;  | 
| 
58
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
59
 | 
80
 | 
 
 | 
 
 | 
 
 | 
 
 | 
299
 | 
     for my $e ( $self->_get_data_elements ) {  | 
| 
60
 | 
79
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
463
 | 
         next unless $e and exists $e->{relationships};  | 
| 
61
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
62
 | 
12
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
26
 | 
         if ( %{ $e->{relationships} } ) {  | 
| 
 
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
36
 | 
    | 
| 
63
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
30
 | 
             for my $rel_type ( keys %{ $e->{relationships} } ) {  | 
| 
 
 | 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
54
 | 
    | 
| 
64
 | 
15
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
416
 | 
                 if ( !$self->repository->has_relationship( $type, $rel_type ) ) {  | 
| 
 
 | 
 
 | 
  
100
  
 | 
  
 66
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
65
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
12
 | 
                     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 )  | 
| 
71
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                         and ref $e->{relationships}{$rel_type} eq 'ARRAY'  | 
| 
72
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
7
 | 
                         and @{ $e->{relationships}{$rel_type} } > 1  | 
| 
73
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     ) {  | 
| 
74
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
                     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
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2510
 | 
     return 1;  | 
| 
83
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
84
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
85
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub _get_data_elements {  | 
| 
86
 | 
293
 | 
 
 | 
 
 | 
  
293
  
 | 
 
 | 
443
 | 
     my $self = shift;  | 
| 
87
 | 
293
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
9475
 | 
     return ( ref $self->data eq 'ARRAY' ? @{ $self->data } : $self->data );  | 
| 
 
 | 
115
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3620
 | 
    | 
| 
88
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
89
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
90
 | 
8
 | 
 
 | 
 
 | 
  
8
  
 | 
 
 | 
44607
 | 
 no Moose::Role; 1;  | 
| 
 
 | 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
62
 | 
    | 
| 
 
 | 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
64
 | 
    | 
| 
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.003003  | 
| 
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) 2019 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  |