← 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/Builder/Role/HasPagination.pm
StatementsExecuted 10 statements in 529µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111520µs544µsPONAPI::Builder::Role::HasPagination::::BEGIN@7PONAPI::Builder::Role::HasPagination::BEGIN@7
11117µs2.29msPONAPI::Builder::Role::HasPagination::::BEGIN@4PONAPI::Builder::Role::HasPagination::BEGIN@4
1117µs7µsPONAPI::Builder::Role::HasPagination::::BEGIN@6PONAPI::Builder::Role::HasPagination::BEGIN@6
1117µs82µsPONAPI::Builder::Role::HasPagination::::BEGIN@81PONAPI::Builder::Role::HasPagination::BEGIN@81
0000s0sPONAPI::Builder::Role::HasPagination::::_hash_to_uri_queryPONAPI::Builder::Role::HasPagination::_hash_to_uri_query
0000s0sPONAPI::Builder::Role::HasPagination::::add_pagination_linksPONAPI::Builder::Role::HasPagination::add_pagination_links
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# ABSTRACT: document builder - role - pagination
2package PONAPI::Builder::Role::HasPagination;
3
4247µs24.57ms
# spent 2.29ms (17µs+2.28) within PONAPI::Builder::Role::HasPagination::BEGIN@4 which was called: # once (17µs+2.28ms) by Module::Runtime::require_module at line 4
use Moose::Role;
# spent 2.29ms making 1 call to PONAPI::Builder::Role::HasPagination::BEGIN@4 # spent 2.28ms making 1 call to Moose::Role::import
5
6222µs17µs
# spent 7µs within PONAPI::Builder::Role::HasPagination::BEGIN@6 which was called: # once (7µs+0s) by Module::Runtime::require_module at line 6
use URI;
# spent 7µs making 1 call to PONAPI::Builder::Role::HasPagination::BEGIN@6
72430µs1544µs
# spent 544µs (520+24) within PONAPI::Builder::Role::HasPagination::BEGIN@7 which was called: # once (520µs+24µs) by Module::Runtime::require_module at line 7
use URI::QueryParam;
# spent 544µs making 1 call to PONAPI::Builder::Role::HasPagination::BEGIN@7
8
9# requires 'links_builder';
10# requires 'req_path';
11
12# self isn't really part of pagination, but it can be overriden here
1314µsmy %allowed_page_keys = map +($_=>1), qw/
14 first
15 last
16 next
17 prev
18 self
19/;
20
21sub add_pagination_links {
22 my ($self, %page_links) = @_;
23
24 $page_links{self} ||= delete $page_links{current}
25 if exists $page_links{current};
26
27 foreach my $link_name ( keys %page_links ) {
28 die "Tried to add pagination link `$link_name`, not allowed by the spec"
29 unless exists $allowed_page_keys{ $link_name };
30 }
31
32 my $link = $self->req_path;
33
34 my $uri = URI->new($link);
35 my $path = $uri->path;
36
37 $self->links_builder->add_links(
38 map {
39 my $query = $self->_hash_to_uri_query( {
40 page => $page_links{$_}
41 }, $uri );
42 ( $_ => $path . '?' . $query )
43 }
44 grep scalar keys %{ $page_links{$_} || {} },
45 keys %page_links
46 );
47}
48
49sub _hash_to_uri_query {
50 my ($self, $data, $u) = @_;
51 $u ||= URI->new("", "http");
52
53 for my $d_k ( sort keys %$data ) {
54 my $d_v = $data->{$d_k};
55 defined($d_v) or next;
56
57 if ( ref $d_v ne 'HASH' ) {
58 $u->query_param( $d_k =>
59 join ',' => ( ref $d_v eq 'ARRAY' ? @{$d_v} : $d_v ) );
60 next;
61 }
62
63 # HASH
64 for my $k ( sort keys %{$d_v} ) {
65 my $v = $d_v->{$k};
66 defined($v) or next;
67
68 die "_hash_to_uri_query: nested value can be scalar/arrayref only"
69 unless !ref $v or ref $v eq 'ARRAY';
70
71 $u->query_param( $d_k . '[' . $k . ']' =>
72 join ',' => ( ref $v eq 'ARRAY' ? @{$v} : $v ) );
73 }
74 }
75
76 return $u->query;
77}
78
- -
81326µs2158µs
# spent 82µs (7+76) within PONAPI::Builder::Role::HasPagination::BEGIN@81 which was called: # once (7µs+76µs) by Module::Runtime::require_module at line 81
no Moose::Role; 1;
# spent 82µs making 1 call to PONAPI::Builder::Role::HasPagination::BEGIN@81 # spent 76µs making 1 call to Moose::Role::unimport
82
83__END__