uri::queryparam(3) [suse man page]
URI::QueryParam(3) User Contributed Perl Documentation URI::QueryParam(3) NAME
URI::QueryParam - Additional query methods for URIs SYNOPSIS
use URI; use URI::QueryParam; $u = URI->new("", "http"); $u->query_param(foo => 1, 2, 3); print $u->query; # prints foo=1&foo=2&foo=3 for my $key ($u->query_param) { print "$key: ", join(", ", $u->query_param($key)), " "; } DESCRIPTION
Loading the "URI::QueryParam" module adds some extra methods to URIs that support query methods. These methods provide an alternative interface to the $u->query_form data. The query_param_* methods have deliberately been made identical to the interface of the corresponding "CGI.pm" methods. The following additional methods are made available: @keys = $u->query_param @values = $u->query_param( $key ) $first_value = $u->query_param( $key ) $u->query_param( $key, $value,... ) If $u->query_param is called with no arguments, it returns all the distinct parameter keys of the URI. In a scalar context it returns the number of distinct keys. When a $key argument is given, the method returns the parameter values with the given key. In a scalar context, only the first parameter value is returned. 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. $u->query_param_append($key, $value,...) 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: $u->query_param($key, $u->query_param($key), $value,...); One difference is that this expression would return the old values of $key, whereas the query_param_append() method does not. @values = $u->query_param_delete($key) $first_value = $u->query_param_delete($key) Deletes all key/value pairs with the given key. The old values are returned. In a scalar context, only the first value is returned. Using the query_param_delete() method is slightly more efficient than the equivalent: $u->query_param($key, []); $hashref = $u->query_form_hash $u->query_form_hash( \%new_form ) 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. Note that sequence information is lost. This means that: $u->query_form_hash($u->query_form_hash); is not necessarily a no-op, as it may reorder the key/value pairs. The values returned by the query_param() method should stay the same though. SEE ALSO
URI, CGI COPYRIGHT
Copyright 2002 Gisle Aas. perl v5.12.1 2009-05-28 URI::QueryParam(3)
Check Out this Related Man Page
Query(3pm) User Contributed Perl Documentation Query(3pm) NAME
URI::Query - class providing URI query string manipulation SYNOPSIS
# Constructor - using a GET query string $qq = URI::Query->new($query_string); # OR Constructor - using a hashref of key => value parameters $qq = URI::Query->new($cgi->Vars); # OR Constructor - using an array of successive keys and values $qq = URI::Query->new(@params); # Revert back to the initial constructor state (to do it all again) $qq->revert; # Remove all occurrences of the given parameters $qq->strip('page', 'next'); # Remove all parameters except the given ones $qq->strip_except('pagesize', 'order'); # Remove all empty/undefined parameters $qq->strip_null; # Replace all occurrences of the given parameters $qq->replace(page => $page, foo => 'bar'); # Set the argument separator to use for output (default: unescaped '&') $qq->separator(';'); # Output the current query string print "$qq"; # OR $qq->stringify; # Stringify with explicit argument separator $qq->stringify(';'); # Get a flattened hash/hashref of the current parameters # (single item parameters as scalars, multiples as an arrayref) my %qq = $qq->hash; # Get a non-flattened hash/hashref of the current parameters # (parameter => arrayref of values) my %qq = $qq->hash_arrayref; # Get the current query string as a set of hidden input tags print $qq->hidden; DESCRIPTION
URI::Query provides simple URI query string manipulation, allowing you to create and manipulate URI query strings from GET and POST requests in web applications. This is primarily useful for creating links where you wish to preserve some subset of the parameters to the current request, and potentially add or replace others. Given a query string this is doable with regexes, of course, but making sure you get the anchoring and escaping right is tedious and error-prone - this module is simpler. CONSTRUCTOR URI::Query objects can be constructed from scalar query strings ('foo=1&bar=2&bar=3'), from a hashref which has parameters as keys, and values either as scalars or arrayrefs of scalars (to handle the case of parameters with multiple values e.g. { foo => '1', bar => [ '2', '3' ] }), or arrays composed of successive parameters-value pairs e.g. ('foo', '1', 'bar', '2', 'bar', '3'). For instance: # Constructor - using a GET query string $qq = URI::Query->new($query_string); # Constructor - using an array of successive keys and values $qq = URI::Query->new(@params); # Constructor - using a hashref of key => value parameters, # where values are either scalars or arrayrefs of scalars $qq = URI::Query->new($cgi->Vars); URI::Query also handles CGI.pm-style hashrefs, where multiple values are packed into a single string, separated by the "