HTTP::Rollup - translate an HTTP query string to a hierarchical structure
use HTTP::Rollup qw(RollupQueryString); my $rollup = new HTTP::Rollup; my $hashref = $rollup->RollupQueryString($query_string);
Given input text of the format:
employee.name.first=Jane employee.name.last=Smith employee.address=123%20Main%20St. employee.city=New%20York id=444 phone=(212)123-4567 phone=(212)555-1212 @fax=(212)999-8877
Construct an output data structure like this:
$hashref = { employee => { name => { "first" => "Jane", "last" => "Smith", }, address => "123 Main St.", city => "New York" }, phone => [ "(212)123-4567", "(212)555-1212" ], fax => [ "(212)999-8877" ], id => 444 };
This is intended as a drop-in replacement for the HTTP query string parsing implemented in CGI.pm, adding the ability to assemble a nested data structure (CGI.pm constructs purely flat structures).
e.g. given the sample input above, CGI.pm would produce:
$hashref = { "employee.name.first" => [ "Jason" ], "employee.name.last" => [ "Smith" ], "employee.name.address" => [ "123 Main St." ], "employee.name.city" => [ "New York" ], "phone" => [ "(212)123-4567", "(212)555-1212" ], "@fax"=> [ "(212)999-8877" ], "id" => [ 444 ] };
If no $query_string parameter is provided, HTTP::Rollup will attempt to find the input in the same manner used by CGI.pm (the internal _query_string function is pretty much cloned from CGI.pm).
HTTP::Rollup runs under both CGI or mod_perl contexts, and from the command line (reads from @ARGV or stdin).
Data nesting using dot notation
Recognizes a list if there is more than one value with the same name
Lists can be forced with a leading @-sign, to allow for lists that could have just one element (eliminating ambiguity between scalar and single- element list). The @ will be stripped.
The FORCE_LIST switch causes CGI.pm-style behavior, as above, for backward compatibility.
The DELIM option specifies the input field delimiter. This is not auto-detected. Default is the standard ampersand, though semicolon has been proposed as a replacement to avoid conflict with the ampersand used for character entities.
Specifying "\n" for the delimiter is helpful for parsing parameters on stdin.
Workhorse function.
Jason W. May <jmay@pobox.com>
Copyright (C) 2002-2005 Jason W. May. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2 POD Errors
The following errors were encountered while parsing the POD:
'=item' outside of any '=over'
You forgot a '=back' before '=head1'
To install HTTP::Rollup, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::Rollup
CPAN shell
perl -MCPAN -e shell install HTTP::Rollup
For more information on module installation, please visit the detailed CPAN module installation guide.