ExSite::Input -- tools for reading http inputs

Usage: my $in = new ExSite::Input;

Reading Input

Input is returned as a hash reference of parameters names => values.

query()

Usage: my $querydata = $in->query()

Reads input passed via GET method (ie. QUERY_STRING)

post()

Usage: my $postdata = $in->post()

Reads input passed via POST method.

query_or_post()

Usage: my $data = $in->query_or_post()

Reads from query preferentially, otherwise from post data.

post_or_query()

Usage: my $data = $in->post_or_query()

Reads from post data preferentially, otherwise from query string.

combine()

Usage: my $data = $in->combine()

Combines the post data and query data into a single hash. Post data is taken preferentially.

Raw Input Data

The raw input is also saved, and can be retrieved using:

    my $raw = $in->fetch("post","raw");   # or, use "get" instead of "post"

Input Order

If the order of the inputs is important, you can fetch the raw key order using:

    my $keylist_ref = $in->fetch("post","keylist");  # or "get"...


Notes

The Input class is a replacement for the generic input parsing routines in ExSite::Misc::, which are deprecated for processing inputs to page.cgi.

The main purpose in having an Input class is so that POST input can be shared by multiple modules working independently. Without an Input class, the first module to get its mitts on STDIN gobbles all the input, and the remaining modules see nothing.

Multipart-encoded Forms

Multipart-encoding is handled automatically using the CGI:: class. Multipart-encoding is normally only enabled by ExSite when the form accepts file uploads.

To fetch the decoded file data directly, use:

    my $raw_file = $in->fetch_file("input_name","raw"); # binary file data
    $my $encoded_file = $in->fetch_file("input_name");  # encoded file data

ExSite encoded file data looks like this:

    filename.jpg#MIMEDATA....

To convert this back to a regular file, split on the separator character ('#' by default) to get the file name, and the mime-encoded data. Then use

    use Mime::Base64;
    decode_base64($mimedata);

If you request the raw input data from a multipart-encoded form, you will receive a CGI:: object.

Input Storage

ExSite::Input stores all input data in %share, where other modules will find it if they also play nice and use ExSite::Input. The input is parsed and cached automatically, and ExSite::Input is smart enough not to redo this work once it has been done.

Input is saved in the following structure:

$share{input}{get|post|combine}{raw|data|keylist}

where get/post/combine selects the input stream, and raw/data/keylist selects the format you would like to view the data in.

Hacking Input

To modify the input cache after input has already been read in, use the following methods:

    $in->set("parameter","newvalue","post"); # or use "get", "combine" instead of "post"

To remove a form parameter from the input cache, use:

    $in->delete("parameter");