Filename | /home/mickey/git_tree/PONAPI/Server/lib/PONAPI/Builder/Resource.pm |
Statements | Executed 17602241 statements in 37.0s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
607534 | 4 | 2 | 41.7s | 125s | build | PONAPI::Builder::Resource::
823661 | 2 | 2 | 8.27s | 25.4s | add_attribute | PONAPI::Builder::Resource::
172883 | 1 | 1 | 5.52s | 60.9s | add_relationship | PONAPI::Builder::Resource::
270247 | 2 | 1 | 5.41s | 60.4s | add_self_link | PONAPI::Builder::Resource::
86592 | 1 | 1 | 2.12s | 11.2s | add_attributes | PONAPI::Builder::Resource::
270247 | 1 | 1 | 509ms | 509ms | __ANON__[lib/PONAPI/Builder/Resource.pm:38] | PONAPI::Builder::Resource::
270247 | 1 | 1 | 452ms | 452ms | __ANON__[lib/PONAPI/Builder/Resource.pm:21] | PONAPI::Builder::Resource::
1 | 1 | 1 | 627µs | 370ms | BEGIN@6 | PONAPI::Builder::Resource::
1 | 1 | 1 | 15µs | 7.08ms | BEGIN@4 | PONAPI::Builder::Resource::
1 | 1 | 1 | 12µs | 96µs | BEGIN@131 | PONAPI::Builder::Resource::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # ABSTRACT: document builder - resource | ||||
2 | package PONAPI::Builder::Resource; | ||||
3 | |||||
4 | 2 | 47µs | 2 | 14.1ms | # spent 7.08ms (15µs+7.06) within PONAPI::Builder::Resource::BEGIN@4 which was called:
# once (15µs+7.06ms) by PONAPI::Builder::Document::BEGIN@6 at line 4 # spent 7.08ms making 1 call to PONAPI::Builder::Resource::BEGIN@4
# spent 7.06ms making 1 call to Moose::import |
5 | |||||
6 | 2 | 625µs | 1 | 370ms | # spent 370ms (627µs+369) within PONAPI::Builder::Resource::BEGIN@6 which was called:
# once (627µs+369ms) by PONAPI::Builder::Document::BEGIN@6 at line 6 # spent 370ms making 1 call to PONAPI::Builder::Resource::BEGIN@6 |
7 | |||||
8 | 1 | 3µs | 1 | 11.3ms | with 'PONAPI::Builder', # spent 11.3ms making 1 call to Moose::with |
9 | 'PONAPI::Builder::Role::HasLinksBuilder', | ||||
10 | 'PONAPI::Builder::Role::HasMeta'; | ||||
11 | |||||
12 | 1 | 2µs | 1 | 1.38ms | has id => ( is => 'ro', isa => 'Str', required => 1 ); # spent 1.38ms making 1 call to Moose::has |
13 | 1 | 2µs | 1 | 1.21ms | has type => ( is => 'ro', isa => 'Str', required => 1 ); # spent 1.21ms making 1 call to Moose::has |
14 | |||||
15 | has _attributes => ( | ||||
16 | init_arg => undef, | ||||
17 | traits => [ 'Hash' ], | ||||
18 | is => 'ro', | ||||
19 | isa => 'HashRef', | ||||
20 | lazy => 1, | ||||
21 | 270247 | 1.50s | # spent 452ms within PONAPI::Builder::Resource::__ANON__[lib/PONAPI/Builder/Resource.pm:21] which was called 270247 times, avg 2µs/call:
# 270247 times (452ms+0s) by PONAPI::Builder::Resource::_add_attribute at line 24 of (eval 45)[Eval/Closure.pm:144], avg 2µs/call | ||
22 | 1 | 9µs | 1 | 13.4ms | handles => { # spent 13.4ms making 1 call to Moose::has |
23 | 'has_attributes' => 'count', | ||||
24 | 'has_attribute_for' => 'exists', | ||||
25 | # private ... | ||||
26 | '_add_attribute' => 'set', | ||||
27 | '_get_attribute' => 'get', | ||||
28 | '_keys_attributes' => 'keys', | ||||
29 | } | ||||
30 | ); | ||||
31 | |||||
32 | has _relationships => ( | ||||
33 | init_arg => undef, | ||||
34 | traits => [ 'Hash' ], | ||||
35 | is => 'ro', | ||||
36 | isa => 'HashRef[ PONAPI::Builder::Relationship ]', | ||||
37 | lazy => 1, | ||||
38 | 270247 | 1.58s | # spent 509ms within PONAPI::Builder::Resource::__ANON__[lib/PONAPI/Builder/Resource.pm:38] which was called 270247 times, avg 2µs/call:
# 270247 times (509ms+0s) by PONAPI::Builder::Resource::has_relationship_for at line 20 of (eval 45)[Eval/Closure.pm:144], avg 2µs/call | ||
39 | 1 | 10µs | 1 | 21.1ms | handles => { # spent 21.1ms making 1 call to Moose::has |
40 | 'has_relationships' => 'count', | ||||
41 | 'has_relationship_for' => 'exists', | ||||
42 | # private ... | ||||
43 | '_add_relationship' => 'set', | ||||
44 | '_get_relationship' => 'get', | ||||
45 | '_keys_relationships' => 'keys', | ||||
46 | } | ||||
47 | ); | ||||
48 | |||||
49 | # spent 25.4s (8.27+17.1) within PONAPI::Builder::Resource::add_attribute which was called 823661 times, avg 31µs/call:
# 468303 times (4.90s+11.3s) by Test::PONAPI::Repository::MockDB::_add_resources at line 564 of lib/Test/PONAPI/Repository/MockDB.pm, avg 35µs/call
# 355358 times (3.36s+5.76s) by PONAPI::Builder::Resource::add_attributes at line 63, avg 26µs/call | ||||
50 | 823661 | 388ms | my ( $self, $key, $value ) = @_; | ||
51 | |||||
52 | 823661 | 904ms | 823661 | 7.44s | $self->raise_error( 400, # spent 7.44s making 823661 calls to PONAPI::Builder::Resource::has_relationship_for, avg 9µs/call |
53 | title => 'Attribute key conflict, a relation already exists for key: ' . $key | ||||
54 | ) if $self->has_relationship_for( $key ); | ||||
55 | |||||
56 | 823661 | 1.09s | 823661 | 9.64s | $self->_add_attribute( $key, $value ); # spent 9.64s making 823661 calls to PONAPI::Builder::Resource::_add_attribute, avg 12µs/call |
57 | |||||
58 | 823661 | 3.16s | return $self; | ||
59 | } | ||||
60 | |||||
61 | # spent 11.2s (2.12+9.12) within PONAPI::Builder::Resource::add_attributes which was called 86592 times, avg 130µs/call:
# 86592 times (2.12s+9.12s) by Test::PONAPI::Repository::MockDB::_add_included at line 686 of lib/Test/PONAPI/Repository/MockDB.pm, avg 130µs/call | ||||
62 | 86592 | 160ms | my ( $self, %args ) = @_; | ||
63 | 86592 | 686ms | 355358 | 9.12s | $self->add_attribute( $_, $args{ $_ } ) foreach keys %args; # spent 9.12s making 355358 calls to PONAPI::Builder::Resource::add_attribute, avg 26µs/call |
64 | 86592 | 402ms | return $self; | ||
65 | } | ||||
66 | |||||
67 | # spent 60.9s (5.52+55.4) within PONAPI::Builder::Resource::add_relationship which was called 172883 times, avg 352µs/call:
# 172883 times (5.52s+55.4s) by Test::PONAPI::Repository::MockDB::_add_resource_relationships at line 653 of lib/Test/PONAPI/Repository/MockDB.pm, avg 352µs/call | ||||
68 | 172883 | 119ms | my ( $self, $key, $resource, $collection ) = @_; | ||
69 | |||||
70 | 172883 | 413ms | 172883 | 832ms | $self->raise_error( 400, # spent 832ms making 172883 calls to PONAPI::Builder::Resource::has_attribute_for, avg 5µs/call |
71 | title => 'Relationship key conflict, an attribute already exists for key: ' . $key | ||||
72 | ) if $self->has_attribute_for( $key ); | ||||
73 | |||||
74 | 172883 | 329ms | my @resources = | ||
75 | ( ref $resource eq 'ARRAY' ) ? @$resource : | ||||
76 | ( ref $resource eq 'HASH' ) ? $resource : | ||||
77 | die 'Relationship resource information must be a reference (HASH or ARRAY)'; | ||||
78 | |||||
79 | 172883 | 1.07s | 345766 | 22.0s | my $builder = $self->has_relationship_for($key) # spent 21.4s making 158776 calls to PONAPI::Builder::Relationship::new, avg 135µs/call
# spent 555ms making 172883 calls to PONAPI::Builder::Resource::has_relationship_for, avg 3µs/call
# spent 38.6ms making 14107 calls to PONAPI::Builder::Resource::_get_relationship, avg 3µs/call |
80 | ? $self->_get_relationship($key) | ||||
81 | : PONAPI::Builder::Relationship->new( | ||||
82 | parent => $self, | ||||
83 | name => $key, | ||||
84 | collection => $collection, | ||||
85 | ); | ||||
86 | |||||
87 | 172883 | 587ms | 172883 | 28.4s | $builder->add_resource( $_ ) foreach @resources; # spent 28.4s making 172883 calls to PONAPI::Builder::Relationship::add_resource, avg 164µs/call |
88 | |||||
89 | 172883 | 1.31s | 172883 | 4.19s | $self->_add_relationship( $key => $builder ); # spent 4.19s making 172883 calls to PONAPI::Builder::Resource::_add_relationship, avg 24µs/call |
90 | } | ||||
91 | |||||
92 | # spent 60.4s (5.41+55.0) within PONAPI::Builder::Resource::add_self_link which was called 270247 times, avg 224µs/call:
# 183655 times (3.84s+39.3s) by Test::PONAPI::Repository::MockDB::_add_resources at line 565 of lib/Test/PONAPI/Repository/MockDB.pm, avg 235µs/call
# 86592 times (1.57s+15.7s) by Test::PONAPI::Repository::MockDB::_add_included at line 686 of lib/Test/PONAPI/Repository/MockDB.pm, avg 199µs/call | ||||
93 | 270247 | 84.1ms | my $self = shift; | ||
94 | 270247 | 961ms | 540494 | 8.43s | my $base = $self->find_root->req_base; # spent 7.86s making 270247 calls to PONAPI::Builder::find_root, avg 29µs/call
# spent 572ms making 270247 calls to PONAPI::Builder::Document::req_base, avg 2µs/call |
95 | 270247 | 1.24s | 540494 | 46.6s | $self->links_builder->add_link( self => $base . $self->{type} . '/' . $self->{id} ); # spent 39.3s making 270247 calls to PONAPI::Builder::Resource::links_builder, avg 146µs/call
# spent 7.23s making 270247 calls to PONAPI::Builder::Links::add_link, avg 27µs/call |
96 | 270247 | 1.21s | return $self; | ||
97 | } | ||||
98 | |||||
99 | # spent 125s (41.7+83.0) within PONAPI::Builder::Resource::build which was called 607534 times, avg 205µs/call:
# 345766 times (25.7s+56.0s) by PONAPI::Builder::Relationship::_add_relationship_link at line 61 of lib/PONAPI/Builder/Relationship.pm, avg 236µs/call
# 133899 times (8.30s+16.7s) by PONAPI::Builder::Document::build at line 155 of lib/PONAPI/Builder/Document.pm, avg 187µs/call
# 78113 times (4.27s+3.05s) by PONAPI::Builder::Document::build at line 174 of lib/PONAPI/Builder/Document.pm, avg 94µs/call
# 49756 times (3.47s+7.23s) by PONAPI::Builder::Document::build at line 160 of lib/PONAPI/Builder/Document.pm, avg 215µs/call | ||||
100 | 607534 | 179ms | my $self = shift; | ||
101 | 607534 | 325ms | my %args = @_; | ||
102 | 607534 | 252ms | my $result = {}; | ||
103 | |||||
104 | 607534 | 1.09s | 607534 | 917ms | $result->{id} = $self->id; # spent 917ms making 607534 calls to PONAPI::Builder::Resource::id, avg 2µs/call |
105 | 607534 | 976ms | 607534 | 985ms | $result->{type} = $self->type; # spent 985ms making 607534 calls to PONAPI::Builder::Resource::type, avg 2µs/call |
106 | 607534 | 2.33s | 1822602 | 15.7s | $result->{links} = $self->links_builder->build if $self->has_links_builder; # spent 13.8s making 607534 calls to PONAPI::Builder::Links::build, avg 23µs/call
# spent 1.08s making 607534 calls to PONAPI::Builder::Resource::links_builder, avg 2µs/call
# spent 796ms making 607534 calls to PONAPI::Builder::Resource::has_links_builder, avg 1µs/call |
107 | 607534 | 911ms | 607534 | 1.28s | $result->{meta} = $self->_meta if $self->has_meta; # spent 1.28s making 607534 calls to PONAPI::Builder::Resource::has_meta, avg 2µs/call |
108 | |||||
109 | # support filtered output for attributes/relationships through args | ||||
110 | 607534 | 115ms | my @field_filters; | ||
111 | 607534 | 228ms | @field_filters = @{ $args{fields}{ $self->type } } | ||
112 | if exists $args{fields} and exists $args{fields}{ $self->type }; | ||||
113 | |||||
114 | 607534 | 1.15s | 607534 | 1.60s | if ( $self->has_attributes ) { # spent 1.60s making 607534 calls to PONAPI::Builder::Resource::has_attributes, avg 3µs/call |
115 | my @attributes = @field_filters | ||||
116 | 607534 | 1.51s | 607534 | 1.62s | ? grep { $self->has_attribute_for($_) } @field_filters # spent 1.62s making 607534 calls to PONAPI::Builder::Resource::_keys_attributes, avg 3µs/call |
117 | : $self->_keys_attributes; | ||||
118 | |||||
119 | 2405374 | 3.98s | 1797840 | 5.19s | $result->{attributes} = +{ map { $_ => $self->_get_attribute($_) } @attributes }; # spent 5.19s making 1797840 calls to PONAPI::Builder::Resource::_get_attribute, avg 3µs/call |
120 | } | ||||
121 | |||||
122 | 542856 | 801ms | 542856 | 2.15s | $result->{relationships} = +{ # spent 2.15s making 542856 calls to PONAPI::Builder::Resource::_get_relationship, avg 4µs/call |
123 | 1150390 | 3.43s | 1642191 | 53.5s | map { my $v = $self->_get_relationship($_); $v ? ( $_ => $v->build ) : () } # spent 50.7s making 542856 calls to PONAPI::Builder::Relationship::build, avg 93µs/call
# spent 1.53s making 607534 calls to PONAPI::Builder::Resource::has_relationships, avg 3µs/call
# spent 1.33s making 491801 calls to PONAPI::Builder::Resource::_keys_relationships, avg 3µs/call |
124 | ( @field_filters ? @field_filters : $self->_keys_relationships ) | ||||
125 | } if $self->has_relationships; | ||||
126 | |||||
127 | 607534 | 2.48s | return $result; | ||
128 | } | ||||
129 | |||||
130 | 1 | 6µs | 2 | 9.12ms | __PACKAGE__->meta->make_immutable; # spent 9.10ms making 1 call to Class::MOP::Class::make_immutable
# spent 22µs making 1 call to PONAPI::Builder::Resource::meta |
131 | 3 | 69µs | 2 | 180µs | # spent 96µs (12+84) within PONAPI::Builder::Resource::BEGIN@131 which was called:
# once (12µs+84µs) by PONAPI::Builder::Document::BEGIN@6 at line 131 # spent 96µs making 1 call to PONAPI::Builder::Resource::BEGIN@131
# spent 84µs making 1 call to Moose::unimport |
132 | |||||
133 | __END__ |