← 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/usr/share/perl5/URI/QueryParam.pm
StatementsExecuted 3 statements in 416µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11111µs24µsURI::QueryParam::::BEGIN@3URI::QueryParam::BEGIN@3
0000s0sURI::_query::::query_form_hash URI::_query::query_form_hash
0000s0sURI::_query::::query_param URI::_query::query_param
0000s0sURI::_query::::query_param_append URI::_query::query_param_append
0000s0sURI::_query::::query_param_delete URI::_query::query_param_delete
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package URI::QueryParam;
2
32414µs237µs
# spent 24µs (11+13) within URI::QueryParam::BEGIN@3 which was called: # once (11µs+13µs) by PONAPI::Builder::Role::HasPagination::BEGIN@7 at line 3
use strict;
# spent 24µs making 1 call to URI::QueryParam::BEGIN@3 # spent 13µs making 1 call to strict::import
4
5sub URI::_query::query_param {
6 my $self = shift;
7 my @old = $self->query_form;
8
9 if (@_ == 0) {
10 # get keys
11 my (%seen, $i);
12 return grep !($i++ % 2 || $seen{$_}++), @old;
13 }
14
15 my $key = shift;
16 my @i = grep $_ % 2 == 0 && $old[$_] eq $key, 0 .. $#old;
17
18 if (@_) {
19 my @new = @old;
20 my @new_i = @i;
21 my @vals = map { ref($_) eq 'ARRAY' ? @$_ : $_ } @_;
22
23 while (@new_i > @vals) {
24 splice @new, pop @new_i, 2;
25 }
26 if (@vals > @new_i) {
27 my $i = @new_i ? $new_i[-1] + 2 : @new;
28 my @splice = splice @vals, @new_i, @vals - @new_i;
29
30 splice @new, $i, 0, map { $key => $_ } @splice;
31 }
32 if (@vals) {
33 #print "SET $new_i[0]\n";
34 @new[ map $_ + 1, @new_i ] = @vals;
35 }
36
37 $self->query_form(\@new);
38 }
39
40 return wantarray ? @old[map $_+1, @i] : @i ? $old[$i[0]+1] : undef;
41}
42
43sub URI::_query::query_param_append {
44 my $self = shift;
45 my $key = shift;
46 my @vals = map { ref $_ eq 'ARRAY' ? @$_ : $_ } @_;
47 $self->query_form($self->query_form, $key => \@vals); # XXX
48 return;
49}
50
51sub URI::_query::query_param_delete {
52 my $self = shift;
53 my $key = shift;
54 my @old = $self->query_form;
55 my @vals;
56
57 for (my $i = @old - 2; $i >= 0; $i -= 2) {
58 next if $old[$i] ne $key;
59 push(@vals, (splice(@old, $i, 2))[1]);
60 }
61 $self->query_form(\@old) if @vals;
62 return wantarray ? reverse @vals : $vals[-1];
63}
64
65sub URI::_query::query_form_hash {
66 my $self = shift;
67 my @old = $self->query_form;
68 if (@_) {
69 $self->query_form(@_ == 1 ? %{shift(@_)} : @_);
70 }
71 my %hash;
72 while (my($k, $v) = splice(@old, 0, 2)) {
73 if (exists $hash{$k}) {
74 for ($hash{$k}) {
75 $_ = [$_] unless ref($_) eq "ARRAY";
76 push(@$_, $v);
77 }
78 }
79 else {
80 $hash{$k} = $v;
81 }
82 }
83 return \%hash;
84}
85
8612µs1;
87
88__END__