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
|
|
6211
|
use Moose::Role; |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
91
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub _validate_data { |
7
|
87
|
|
|
87
|
|
171
|
my $self = shift; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# these are chained to avoid multiple errors on the same issue |
10
|
87
|
100
|
100
|
|
|
290
|
$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
|
135
|
my $self = shift; |
18
|
|
|
|
|
|
|
|
19
|
87
|
|
|
|
|
290
|
for ( $self->_get_data_elements ) { |
20
|
86
|
100
|
100
|
|
|
404
|
next if ref($_||'') ne 'HASH'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
return $self->_bad_request( "request data has no `type` key" ) |
23
|
85
|
100
|
|
|
|
300
|
if !exists $_->{'type'}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
85
|
|
|
|
|
540
|
return 1; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub check_data_type_match { |
30
|
44
|
|
|
44
|
0
|
75
|
my $self = shift; |
31
|
|
|
|
|
|
|
|
32
|
44
|
|
|
|
|
133
|
for ( $self->_get_data_elements ) { |
33
|
|
|
|
|
|
|
return $self->_bad_request( "conflict between the request type and the data type", 409 ) |
34
|
44
|
100
|
|
|
|
1649
|
unless $_->{'type'} eq $self->type; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
41
|
|
|
|
|
273
|
return 1; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub check_data_attributes { |
41
|
82
|
|
|
82
|
0
|
208
|
my $self = shift; |
42
|
82
|
|
|
|
|
2983
|
my $type = $self->type; |
43
|
|
|
|
|
|
|
|
44
|
82
|
|
|
|
|
231
|
for my $e ( $self->_get_data_elements ) { |
45
|
81
|
100
|
66
|
|
|
405
|
next unless $e and exists $e->{attributes}; |
46
|
36
|
100
|
|
|
|
1372
|
$self->repository->type_has_fields( $type, [ keys %{ $e->{'attributes'} } ] ) |
|
36
|
|
|
|
|
265
|
|
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
|
|
|
|
|
577
|
return 1; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub check_data_relationships { |
56
|
80
|
|
|
80
|
0
|
123
|
my $self = shift; |
57
|
80
|
|
|
|
|
2808
|
my $type = $self->type; |
58
|
|
|
|
|
|
|
|
59
|
80
|
|
|
|
|
245
|
for my $e ( $self->_get_data_elements ) { |
60
|
79
|
100
|
66
|
|
|
388
|
next unless $e and exists $e->{relationships}; |
61
|
|
|
|
|
|
|
|
62
|
12
|
50
|
|
|
|
21
|
if ( %{ $e->{relationships} } ) { |
|
12
|
|
|
|
|
48
|
|
63
|
12
|
|
|
|
|
21
|
for my $rel_type ( keys %{ $e->{relationships} } ) { |
|
12
|
|
|
|
|
46
|
|
64
|
15
|
100
|
100
|
|
|
570
|
if ( !$self->repository->has_relationship( $type, $rel_type ) ) { |
|
|
100
|
66
|
|
|
|
|
65
|
2
|
|
|
|
|
15
|
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
|
|
|
|
|
6
|
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
|
|
|
|
|
3191
|
return 1; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _get_data_elements { |
86
|
293
|
|
|
293
|
|
407
|
my $self = shift; |
87
|
293
|
100
|
|
|
|
11892
|
return ( ref $self->data eq 'ARRAY' ? @{ $self->data } : $self->data ); |
|
115
|
|
|
|
|
4568
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
8
|
|
|
8
|
|
50841
|
no Moose::Role; 1; |
|
8
|
|
|
|
|
23
|
|
|
8
|
|
|
|
|
50
|
|
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.002006 |
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) 2016 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 |