Profile of lib/PONAPI/DAO/Request/Role/HasDataMethods.pm

← Index
NYTProf Performance Profile «line view»
For script/ponapi
Run on Wed Feb 10 15:51:26 2016
Reported on Thu Feb 11 09:43:11 2016

Filename | /home/mickey/git_tree/PONAPI/Server/lib/PONAPI/DAO/Request/Role/HasDataMethods.pm
Statements | Executed 5 statements in 444µs

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 19µs | 7.42ms | PONAPI::DAO::Request::Role::HasDataMethods::::BEGIN@4PONAPI::DAO::Request::Role::HasDataMethods::BEGIN@4
1 | 1 | 1 | 10µs | 86µs | PONAPI::DAO::Request::Role::HasDataMethods::::BEGIN@90PONAPI::DAO::Request::Role::HasDataMethods::BEGIN@90
0 | 0 | 0 | 0s | 0s | PONAPI::DAO::Request::Role::HasDataMethods::::_get_data_elementsPONAPI::DAO::Request::Role::HasDataMethods::_get_data_elements
0 | 0 | 0 | 0s | 0s | PONAPI::DAO::Request::Role::HasDataMethods::::_validate_dataPONAPI::DAO::Request::Role::HasDataMethods::_validate_data
0 | 0 | 0 | 0s | 0s | PONAPI::DAO::Request::Role::HasDataMethods::::check_data_attributesPONAPI::DAO::Request::Role::HasDataMethods::check_data_attributes
0 | 0 | 0 | 0s | 0s | PONAPI::DAO::Request::Role::HasDataMethods::::check_data_has_typePONAPI::DAO::Request::Role::HasDataMethods::check_data_has_type
0 | 0 | 0 | 0s | 0s | PONAPI::DAO::Request::Role::HasDataMethods::::check_data_relationshipsPONAPI::DAO::Request::Role::HasDataMethods::check_data_relationships
0 | 0 | 0 | 0s | 0s | PONAPI::DAO::Request::Role::HasDataMethods::::check_data_type_matchPONAPI::DAO::Request::Role::HasDataMethods::check_data_type_match

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | # ABSTRACT: DAO request role - `data` methods
2 |  |  |  |  | package PONAPI::DAO::Request::Role::HasDataMethods;
3 |  |  |  |  |
4 | 2 | 411µs | 2 | 14.8ms | # spent 7.42ms (19µs+7.40) within PONAPI::DAO::Request::Role::HasDataMethods::BEGIN@4 which was called: # once (19µs+7.40ms) by Module::Runtime::require_module at line 4 use Moose::Role; # spent 7.42ms making 1 call to PONAPI::DAO::Request::Role::HasDataMethods::BEGIN@4 # spent 7.40ms making 1 call to Moose::Role::import
5 |  |  |  |  |
6 |  |  |  |  | sub _validate_data {
7 |  |  |  |  | my $self = shift;
8 |  |  |  |  |
9 |  |  |  |  | # these are chained to avoid multiple errors on the same issue
10 |  |  |  |  | $self->check_data_has_type
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 |  |  |  |  | my $self = shift;
18 |  |  |  |  |
19 |  |  |  |  | for ( $self->_get_data_elements ) {
20 |  |  |  |  | next if ref($_||'') ne 'HASH';
21 |  |  |  |  |
22 |  |  |  |  | return $self->_bad_request( "request data has no `type` key" )
23 |  |  |  |  | if !exists $_->{'type'};
24 |  |  |  |  | }
25 |  |  |  |  |
26 |  |  |  |  | return 1;
27 |  |  |  |  | }
28 |  |  |  |  |
29 |  |  |  |  | sub check_data_type_match {
30 |  |  |  |  | my $self = shift;
31 |  |  |  |  |
32 |  |  |  |  | for ( $self->_get_data_elements ) {
33 |  |  |  |  | return $self->_bad_request( "conflict between the request type and the data type", 409 )
34 |  |  |  |  | unless $_->{'type'} eq $self->type;
35 |  |  |  |  | }
36 |  |  |  |  |
37 |  |  |  |  | return 1;
38 |  |  |  |  | }
39 |  |  |  |  |
40 |  |  |  |  | sub check_data_attributes {
41 |  |  |  |  | my $self = shift;
42 |  |  |  |  | my $type = $self->type;
43 |  |  |  |  |
44 |  |  |  |  | for my $e ( $self->_get_data_elements ) {
45 |  |  |  |  | next unless $e and exists $e->{attributes};
46 |  |  |  |  | $self->repository->type_has_fields( $type, [ keys %{ $e->{'attributes'} } ] )
47 |  |  |  |  | or return $self->_bad_request(
48 |  |  |  |  | "Type `$type` does not have at least one of the attributes in data"
49 |  |  |  |  | );
50 |  |  |  |  | }
51 |  |  |  |  |
52 |  |  |  |  | return 1;
53 |  |  |  |  | }
54 |  |  |  |  |
55 |  |  |  |  | sub check_data_relationships {
56 |  |  |  |  | my $self = shift;
57 |  |  |  |  | my $type = $self->type;
58 |  |  |  |  |
59 |  |  |  |  | for my $e ( $self->_get_data_elements ) {
60 |  |  |  |  | next unless $e and exists $e->{relationships};
61 |  |  |  |  |
62 |  |  |  |  | if ( %{ $e->{relationships} } ) {
63 |  |  |  |  | for my $rel_type ( keys %{ $e->{relationships} } ) {
64 |  |  |  |  | if ( !$self->repository->has_relationship( $type, $rel_type ) ) {
65 |  |  |  |  | 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 |  |  |  |  | and @{ $e->{relationships}{$rel_type} } > 1
73 |  |  |  |  | ) {
74 |  |  |  |  | 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 |  |  |  |  | return 1;
83 |  |  |  |  | }
84 |  |  |  |  |
85 |  |  |  |  | sub _get_data_elements {
86 |  |  |  |  | my $self = shift;
87 |  |  |  |  | return ( ref $self->data eq 'ARRAY' ? @{ $self->data } : $self->data );
88 |  |  |  |  | }
89 |  |  |  |  |
90 | 3 | 33µs | 2 | 162µs | # spent 86µs (10+76) within PONAPI::DAO::Request::Role::HasDataMethods::BEGIN@90 which was called: # once (10µs+76µs) by Module::Runtime::require_module at line 90 no Moose::Role; 1; # spent 86µs making 1 call to PONAPI::DAO::Request::Role::HasDataMethods::BEGIN@90 # spent 76µs making 1 call to Moose::Role::unimport
91 |  |  |  |  |
92 |  |  |  |  | __END__