Filename | /usr/share/perl5/URI/QueryParam.pm |
Statements | Executed 4 statements in 1.08ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 32µs | 41µs | BEGIN@3 | URI::QueryParam::
0 | 0 | 0 | 0s | 0s | query_form_hash | URI::_query::
0 | 0 | 0 | 0s | 0s | query_param | URI::_query::
0 | 0 | 0 | 0s | 0s | query_param_append | URI::_query::
0 | 0 | 0 | 0s | 0s | query_param_delete | URI::_query::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package URI::QueryParam; | ||||
2 | |||||
3 | 3 | 1.07ms | 2 | 50µs | # spent 41µs (32+9) within URI::QueryParam::BEGIN@3 which was called:
# once (32µs+9µs) by Authen::CAS::Client::BEGIN@11 at line 3 # spent 41µs making 1 call to URI::QueryParam::BEGIN@3
# spent 9µs making 1 call to strict::import |
4 | |||||
5 | sub URI::_query::query_param { | ||||
6 | my $self = shift; | ||||
7 | my @old = $self->query_form; | ||||
8 | |||||
9 | if (@_ == 0) { | ||||
10 | # get keys | ||||
11 | my %seen; | ||||
12 | my @keys; | ||||
13 | for (my $i = 0; $i < @old; $i += 2) { | ||||
14 | push(@keys, $old[$i]) unless $seen{$old[$i]}++; | ||||
15 | } | ||||
16 | return @keys; | ||||
17 | } | ||||
18 | |||||
19 | my $key = shift; | ||||
20 | my @i; | ||||
21 | |||||
22 | for (my $i = 0; $i < @old; $i += 2) { | ||||
23 | push(@i, $i) if $old[$i] eq $key; | ||||
24 | } | ||||
25 | |||||
26 | if (@_) { | ||||
27 | my @new = @old; | ||||
28 | my @new_i = @i; | ||||
29 | my @vals = map { ref($_) eq 'ARRAY' ? @$_ : $_ } @_; | ||||
30 | #print "VALS:@vals [@i]\n"; | ||||
31 | while (@new_i > @vals) { | ||||
32 | #print "REMOVE $new_i[-1]\n"; | ||||
33 | splice(@new, pop(@new_i), 2); | ||||
34 | } | ||||
35 | while (@vals > @new_i) { | ||||
36 | my $i = @new_i ? $new_i[-1] + 2 : @new; | ||||
37 | #print "SPLICE $i\n"; | ||||
38 | splice(@new, $i, 0, $key => pop(@vals)); | ||||
39 | } | ||||
40 | for (@vals) { | ||||
41 | #print "SET $new_i[0]\n"; | ||||
42 | $new[shift(@new_i)+1] = $_; | ||||
43 | } | ||||
44 | |||||
45 | $self->query_form(\@new); | ||||
46 | } | ||||
47 | |||||
48 | return wantarray ? @old[map $_+1, @i] : @i ? $old[$i[0]+1] : undef; | ||||
49 | } | ||||
50 | |||||
51 | sub URI::_query::query_param_append { | ||||
52 | my $self = shift; | ||||
53 | my $key = shift; | ||||
54 | $self->query_form($self->query_form, $key => \@_); # XXX | ||||
55 | return; | ||||
56 | } | ||||
57 | |||||
58 | sub URI::_query::query_param_delete { | ||||
59 | my $self = shift; | ||||
60 | my $key = shift; | ||||
61 | my @old = $self->query_form; | ||||
62 | my @vals; | ||||
63 | |||||
64 | for (my $i = @old - 2; $i >= 0; $i -= 2) { | ||||
65 | next if $old[$i] ne $key; | ||||
66 | push(@vals, (splice(@old, $i, 2))[1]); | ||||
67 | } | ||||
68 | $self->query_form(\@old) if @vals; | ||||
69 | return wantarray ? reverse @vals : $vals[-1]; | ||||
70 | } | ||||
71 | |||||
72 | sub URI::_query::query_form_hash { | ||||
73 | my $self = shift; | ||||
74 | my @old = $self->query_form; | ||||
75 | if (@_) { | ||||
76 | $self->query_form(@_ == 1 ? %{shift(@_)} : @_); | ||||
77 | } | ||||
78 | my %hash; | ||||
79 | while (my($k, $v) = splice(@old, 0, 2)) { | ||||
80 | if (exists $hash{$k}) { | ||||
81 | for ($hash{$k}) { | ||||
82 | $_ = [$_] unless ref($_) eq "ARRAY"; | ||||
83 | push(@$_, $v); | ||||
84 | } | ||||
85 | } | ||||
86 | else { | ||||
87 | $hash{$k} = $v; | ||||
88 | } | ||||
89 | } | ||||
90 | return \%hash; | ||||
91 | } | ||||
92 | |||||
93 | 1 | 4µs | 1; | ||
94 | |||||
95 | __END__ |