Closed zostay closed 3 years ago
I think this may be addressed by the #44 to some extent.
The API has changed somewhat but this actually does work as expected:
use URI;
my $u = URI.new("http://example.com/?foo=bar&foo=baz&bar=qux");
my $q = $u.query;
say "bar = $q<bar>";
say "foo = $q<foo>[0]";
say "foo = ", $u.query<foo>[1];
Imma close this.
While working on my PR for #27, I discovered a problem with the URI interface provided. I'm not sure it can be fixed without breaking existing code, but I believe it needs to be broken. The problem is the code current provides query-form as a Hash. This has a few problems:
To address the last issue, the interface allows for a mixed-value approach where a query form containing duplicate keys causes that key in the Hash to be changed from a Str to an Array. So some of the values are strings and some are arrays of strings. This allows the order of values to be preserved, but not the order of keys. It also means that the caller has to be carefully aware of what it is doing to avoid problems.
The most obvious solution is to use one similar to that of the Perl 5 URI module, which is to just returns a list of Pairs. This would be simplest to implement. However, it will break code that depends on it:
Another solution might be to just document this deficiency and add a different method that does this better.