From 2c18114353029cfd5784df5c6def6c0b22de4ca7 Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Sat, 27 May 2006 00:00:22 -0700 Subject: [PATCH] Add Debbugs::URI which overrides parts of URI to use ; instead of & --- Debbugs/URI.pm | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 Debbugs/URI.pm diff --git a/Debbugs/URI.pm b/Debbugs/URI.pm new file mode 100644 index 0000000..307f11f --- /dev/null +++ b/Debbugs/URI.pm @@ -0,0 +1,94 @@ +package Debbugs::URI; + +=head1 NAME + +Debbugs::URI -- Derivative of URI which overrides the query_param + method to use ';' instead of '&' for separators. + +=head1 SYNOPSIS + +use Debbugs::URI; + +=head1 DESCRIPTION + +See L for more information. + +=head1 BUGS + +None known. + +=cut + +use warnings; +use strict; +use base qw(URI URI::_query); + +=head2 query_param + + $uri->query_form( $key1 => $val1, $key2 => $val2, ... ) + +Exactly like query_param in L except query elements are joined by +; instead of &. + +=cut + +{ + + package URI::_query; + + no warnings 'redefine'; + # Handle ...?foo=bar&bar=foo type of query + sub URI::_query::query_form { + my $self = shift; + my $old = $self->query; + if (@_) { + # Try to set query string + my @new = @_; + if (@new == 1) { + my $n = $new[0]; + if (ref($n) eq "ARRAY") { + @new = @$n; + } + elsif (ref($n) eq "HASH") { + @new = %$n; + } + } + my @query; + while (my($key,$vals) = splice(@new, 0, 2)) { + $key = '' unless defined $key; + $key =~ s/([;\/?:@&=+,\$\[\]%])/$URI::Escape::escapes{$1}/g; + $key =~ s/ /+/g; + $vals = [ref($vals) eq "ARRAY" ? @$vals : $vals]; + for my $val (@$vals) { + $val = '' unless defined $val; + $val =~ s/([;\/?:@&=+,\$\[\]%])/$URI::Escape::escapes{$1}/g; + $val =~ s/ /+/g; + push(@query, "$key=$val"); + } + } + # We've changed & to a ; here. + $self->query(@query ? join(';', @query) : undef); + } + return if !defined($old) || !length($old) || !defined(wantarray); + return unless $old =~ /=/; # not a form + map { s/\+/ /g; uri_unescape($_) } + # We've also changed the split here to split on ; as well as & + map { /=/ ? split(/=/, $_, 2) : ($_ => '')} split(/[&;]/, $old); + } +} + + + + + + +1; + + +__END__ + + + + + + -- 2.39.2