5 use URI::Escape qw(uri_unescape);
10 $$self =~ m,^([^?\#]*)(?:\?([^\#]*))?(.*)$,s or die;
16 $q =~ s/([^$URI::uric])/ URI::Escape::escape_char($1)/ego;
24 # Handle ...?foo=bar&bar=foo type of query
27 my $old = $self->query;
29 # Try to set query string
32 if (ref($r) eq "ARRAY") {
36 elsif (ref($r) eq "HASH") {
40 $delim = pop if @_ % 2;
43 while (my($key,$vals) = splice(@_, 0, 2)) {
44 $key = '' unless defined $key;
45 $key =~ s/([;\/?:@&=+,\$\[\]%])/ URI::Escape::escape_char($1)/eg;
47 $vals = [ref($vals) eq "ARRAY" ? @$vals : $vals];
48 for my $val (@$vals) {
49 $val = '' unless defined $val;
50 $val =~ s/([;\/?:@&=+,\$\[\]%])/ URI::Escape::escape_char($1)/eg;
52 push(@query, "$key=$val");
57 $delim = $1 if $old && $old =~ /([&;])/;
58 $delim ||= $URI::DEFAULT_QUERY_FORM_DELIMITER || "&";
60 $self->query(join($delim, @query));
66 return if !defined($old) || !length($old) || !defined(wantarray);
67 return unless $old =~ /=/; # not a form
68 map { s/\+/ /g; uri_unescape($_) }
69 map { /=/ ? split(/=/, $_, 2) : ($_ => '')} split(/[&;]/, $old);
72 # Handle ...?dog+bones type of query
76 my $old = $self->query;
78 # Try to set query string
80 @copy = @{$copy[0]} if @copy == 1 && ref($copy[0]) eq "ARRAY";
81 for (@copy) { s/([;\/?:@&=+,\$\[\]%])/ URI::Escape::escape_char($1)/eg; }
82 $self->query(@copy ? join('+', @copy) : undef);
84 return if !defined($old) || !defined(wantarray);
85 return if $old =~ /=/; # not keywords, but a form
86 map { uri_unescape($_) } split(/\+/, $old, -1);
89 # Some URI::URL compatibility stuff