Debian Codegraph @

Debbugs/URI.pm

raw
1 # This module is part of debbugs, and is released
2 # under the terms of the GPL version 2, or any later
3 # version at your option.
4 # See the file README and COPYING for more information.
5 #
6 # Copyright 2007 by Don Armstrong <[email protected]>.
7 # query_form is
8 # Copyright 1995-2003 Gisle Aas.
9 # Copyright 1995 Martijn Koster.
10
11
12 package Debbugs::URI;
13
14 =head1 NAME
15
16 Debbugs::URI -- Derivative of URI which overrides the query_param
17 method to use ';' instead of '&' for separators.
18
19 =head1 SYNOPSIS
20
21 use Debbugs::URI;
22
23 =head1 DESCRIPTION
24
25 See L<URI> for more information.
26
27 =head1 BUGS
28
29 None known.
30
31 =cut
32
33 use warnings;
34 use strict;
35 use base qw(URI URI::_query);
36
37 =head2 query_param
38
39 $uri->query_form( $key1 => $val1, $key2 => $val2, ... )
40
41 Exactly like query_param in L<URI> except query elements are joined by
42 ; instead of &.
43
44 =cut
45
46 {
47
48 package URI::_query;
49
50 no warnings 'redefine';
51 # Handle ...?foo=bar&bar=foo type of query
52 sub URI::_query::query_form {
53 my $self = shift;
54 my $old = $self->query;
55 if (@_) {
56 # Try to set query string
57 my @new = @_;
58 if (@new == 1) {
59 my $n = $new[0];
60 if (ref($n) eq "ARRAY") {
61 @new = @$n;
62 }
63 elsif (ref($n) eq "HASH") {
64 @new = %$n;
65 }
66 }
67 my @query;
68 while (my($key,$vals) = splice(@new, 0, 2)) {
69 $key = '' unless defined $key;
70 $key =~ s/([;\/?:@&=+,\$\[\]%])/$URI::Escape::escapes{$1}/g;
71 $key =~ s/ /+/g;
72 $vals = [ref($vals) eq "ARRAY" ? @$vals : $vals];
73 for my $val (@$vals) {
74 $val = '' unless defined $val;
75 $val =~ s/([;\/?:@&=+,\$\[\]%])/$URI::Escape::escapes{$1}/g;
76 $val =~ s/ /+/g;
77 push(@query, "$key=$val");
78 }
79 }
80 # We've changed & to a ; here.
81 $self->query(@query ? join(';', @query) : undef);
82 }
83 return if !defined($old) || !length($old) || !defined(wantarray);
84 return unless $old =~ /=/; # not a form
85 map { s/\+/ /g; uri_unescape($_) }
86 # We've also changed the split here to split on ; as well as &
87 map { /=/ ? split(/=/, $_, 2) : ($_ => '')} split(/[&;]/, $old);
88 }
89 }
90
91
92
93
94
95
96 1;
97
98
99 __END__
100
101
102
103
104
105