man URI::Query () - class providing URI query string manipulation

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 set of key => value parameters 
    $qq = URI::Query->new(%Vars);

    # 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;

    # Revert back to the initial constructor state (to do it all again)
    $qq->revert;

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.

BUGS AND CAVEATS

None known.

Note that this module doesn't do any input unescaping of query strings - you're (currently) expected to handle that explicitly yourself.

AUTHOR

Gavin Carr <gavin@openfusion.com.au>

COPYRIGHT

Copyright 2004-2005, Gavin Carr. All Rights Reserved.

This program is free software. You may copy or redistribute it under the same terms as perl itself.