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