man-pages/man3/URI::QueryParam.3pm.html
2021-03-31 01:06:50 +01:00

281 lines
4.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of URI::QueryParam</TITLE>
</HEAD><BODY>
<H1>URI::QueryParam</H1>
Section: User Contributed Perl Documentation (3pm)<BR>Updated: 2020-02-08<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
URI::QueryParam - Additional query methods for URIs
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
use URI;
use URI::QueryParam;
$u = URI-&gt;new(&quot;&quot;, &quot;http&quot;);
$u-&gt;query_param(foo =&gt; 1, 2, 3);
print $u-&gt;query; # prints foo=1&amp;foo=2&amp;foo=3
for my $key ($u-&gt;query_param) {
print &quot;$key: &quot;, join(&quot;, &quot;, $u-&gt;query_param($key)), &quot;\n&quot;;
}
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
Loading the <TT>&quot;URI::QueryParam&quot;</TT> module adds some extra methods to
URIs that support query methods. These methods provide an alternative
interface to the <TT>$u</TT>-&gt;query_form data.
<P>
The query_param_* methods have deliberately been made identical to the
interface of the corresponding <TT>&quot;CGI.pm&quot;</TT> methods.
<P>
The following additional methods are made available:
<DL COMPACT>
<DT id="1">@keys = $u-&gt;query_param<DD>
<DT id="2">@values = $u-&gt;query_param( $key )<DD>
<DT id="3">$first_value = $u-&gt;query_param( $key )<DD>
<DT id="4">$u-&gt;query_param( $key, $value,... )<DD>
If <TT>$u</TT>-&gt;query_param is called with no arguments, it returns all the
distinct parameter keys of the <FONT SIZE="-1">URI.</FONT> In a scalar context it returns the
number of distinct keys.
<P>
When a <TT>$key</TT> argument is given, the method returns the parameter values with the
given key. In a scalar context, only the first parameter value is
returned.
<P>
If additional arguments are given, they are used to update successive
parameters with the given key. If any of the values provided are
array references, then the array is dereferenced to get the actual
values.
<P>
Please note that you can supply multiple values to this method, but you cannot
supply multiple keys.
<P>
Do this:
<P>
<PRE>
$uri-&gt;query_param( widget_id =&gt; 1, 5, 9 );
</PRE>
<P>
Do <FONT SIZE="-1">NOT</FONT> do this:
<P>
<PRE>
$uri-&gt;query_param( widget_id =&gt; 1, frobnicator_id =&gt; 99 );
</PRE>
<DT id="5">$u-&gt;query_param_append($key, $value,...)<DD>
Adds new parameters with the given
key without touching any old parameters with the same key. It
can be explained as a more efficient version of:
<P>
<PRE>
$u-&gt;query_param($key,
$u-&gt;query_param($key),
$value,...);
</PRE>
<P>
One difference is that this expression would return the old values
of <TT>$key</TT>, whereas the <B>query_param_append()</B> method does not.
<DT id="6">@values = $u-&gt;query_param_delete($key)<DD>
<DT id="7">$first_value = $u-&gt;query_param_delete($key)<DD>
Deletes all key/value pairs with the given key.
The old values are returned. In a scalar context, only the first value
is returned.
<P>
Using the <B>query_param_delete()</B> method is slightly more efficient than
the equivalent:
<P>
<PRE>
$u-&gt;query_param($key, []);
</PRE>
<DT id="8">$hashref = $u-&gt;query_form_hash<DD>
<DT id="9">$u-&gt;query_form_hash( \%new_form )<DD>
Returns a reference to a hash that represents the
query form's key/value pairs. If a key occurs multiple times, then the hash
value becomes an array reference.
<P>
Note that sequence information is lost. This means that:
<P>
<PRE>
$u-&gt;query_form_hash($u-&gt;query_form_hash);
</PRE>
<P>
is not necessarily a no-op, as it may reorder the key/value pairs.
The values returned by the <B>query_param()</B> method should stay the same
though.
</DL>
<A NAME="lbAE">&nbsp;</A>
<H2>SEE ALSO</H2>
<FONT SIZE="-1">URI</FONT>, <FONT SIZE="-1">CGI</FONT>
<A NAME="lbAF">&nbsp;</A>
<H2>COPYRIGHT</H2>
Copyright 2002 Gisle Aas.
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="10"><A HREF="#lbAB">NAME</A><DD>
<DT id="11"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="12"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="13"><A HREF="#lbAE">SEE ALSO</A><DD>
<DT id="14"><A HREF="#lbAF">COPYRIGHT</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:59 GMT, March 31, 2021
</BODY>
</HTML>