1 # This module is stolen from debbugs until the real
2 # URI::query_form properly handles ; and is released
3 # under the terms of the GPL version 2, or any later
4 # version at your option.
5 # See the file README and COPYING for more information.
7 # Copyright 2007 by Don Armstrong <don@donarmstrong.com>.
9 # Copyright 1995-2003 Gisle Aas.
10 # Copyright 1995 Martijn Koster.
13 package Devscripts::URI;
17 Devscripts::URI -- Derivative of URI which overrides the query_param
18 method to use ';' instead of '&' for separators.
26 See L<URI> for more information.
36 use base qw(URI URI::_query);
40 $uri->query_form( $key1 => $val1, $key2 => $val2, ... )
42 Exactly like query_param in L<URI> except query elements are joined by
51 no warnings 'redefine';
52 # Handle ...?foo=bar&bar=foo type of query
53 sub URI::_query::query_form {
55 my $old = $self->query;
57 # Try to set query string
61 if (ref($n) eq "ARRAY") {
64 elsif (ref($n) eq "HASH") {
69 while (my($key,$vals) = splice(@new, 0, 2)) {
70 $key = '' unless defined $key;
71 $key =~ s/([;\/?:@&=+,\$\[\]%])/$URI::Escape::escapes{$1}/g;
73 $vals = [ref($vals) eq "ARRAY" ? @$vals : $vals];
74 for my $val (@$vals) {
75 $val = '' unless defined $val;
76 $val =~ s/([;\/?:@&=+,\$\[\]%])/$URI::Escape::escapes{$1}/g;
78 push(@query, "$key=$val");
81 # We've changed & to a ; here.
82 $self->query(@query ? join(';', @query) : undef);
84 return if !defined($old) || !length($old) || !defined(wantarray);
85 return unless $old =~ /=/; # not a form
86 map { s/\+/ /g; uri_unescape($_) }
87 # We've also changed the split here to split on ; as well as &
88 map { /=/ ? split(/=/, $_, 2) : ($_ => '')} split(/[&;]/, $old);