CGI-Tiny

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    "body_parts". Thus "uploads" may not contain file and may instead
    contain content, and "body_params" text field values may be read from
    file, which will be expected to be a seekable filehandle if present.

  set_multipart_form_charset

      $cgi = $cgi->set_multipart_form_charset('UTF-8');

    Sets the default charset for decoding multipart/form-data forms,
    defaults to UTF-8. Parameter and upload field names, upload filenames,
    and text parameter values that don't specify a charset will be decoded
    from this charset. Set to an empty string to disable this decoding,
    effectively interpreting such values in ISO-8859-1.

  set_input_handle

      $cgi = $cgi->set_input_handle($fh);

    Sets the input handle to read the request body from. If not set, reads
    from STDIN. The handle will have binmode applied before reading to
    remove any translation layers.

README  view on Meta::CPAN

    Retrieve values of a request cookie name as an ordered array reference.

  params

      my $pairs = $cgi->params;

    Retrieve URL query string parameters and
    application/x-www-form-urlencoded or multipart/form-data body
    parameters as an ordered array reference of name/value pairs,
    represented as two-element array references. Names and values are
    decoded to Unicode characters.

    Query parameters are returned first, followed by body parameters. Use
    "query_params" or "body_params" to retrieve query or body parameters
    separately.

    NOTE: This will read the text form fields into memory as in
    "body_params".

  param_names

      my $arrayref = $cgi->param_names;

    Retrieve URL query string parameter names and
    application/x-www-form-urlencoded or multipart/form-data body parameter
    names, decoded to Unicode characters, as an ordered array reference,
    without duplication.

    Query parameter names are returned first, followed by body parameter
    names. Use "query_param_names" or "body_param_names" to retrieve query
    or body parameter names separately.

    NOTE: This will read the text form fields into memory as in
    "body_params".

  param

      my $value = $cgi->param('foo');

    Retrieve value of a named URL query string parameter or
    application/x-www-form-urlencoded or multipart/form-data body
    parameter, decoded to Unicode characters.

    If the parameter name was passed multiple times, returns the last body
    parameter value if any, otherwise the last query parameter value. Use
    "param_array" to get multiple values of a parameter, or "query_param"
    or "body_param" to retrieve the last query or body parameter value
    specifically.

    NOTE: This will read the text form fields into memory as in
    "body_params".

  param_array

      my $arrayref = $cgi->param_array('foo');

    Retrieve values of a named URL query string parameter or
    application/x-www-form-urlencoded or multipart/form-data body
    parameter, decoded to Unicode characters, as an ordered array
    reference.

    Query parameter values will be returned first, followed by body
    parameter values. Use "query_param_array" or "body_param_array" to
    retrieve query or body parameter values separately.

    NOTE: This will read the text form fields into memory as in
    "body_params".

  query_params

      my $pairs = $cgi->query_params;

    Retrieve URL query string parameters as an ordered array reference of
    name/value pairs, represented as two-element array references. Names
    and values are decoded to Unicode characters.

  query_param_names

      my $arrayref = $cgi->query_param_names;

    Retrieve URL query string parameter names, decoded to Unicode
    characters, as an ordered array reference, without duplication.

  query_param

      my $value = $cgi->query_param('foo');

    Retrieve value of a named URL query string parameter, decoded to
    Unicode characters.

    If the parameter name was passed multiple times, returns the last
    value. Use "query_param_array" to get multiple values of a parameter.

  query_param_array

      my $arrayref = $cgi->query_param_array('foo');

    Retrieve values of a named URL query string parameter, decoded to
    Unicode characters, as an ordered array reference.

  body

      my $bytes = $cgi->body;

    Retrieve the request body as bytes.

    NOTE: This will read the whole request body into memory, so make sure
    the "set_request_body_limit" can fit well within the available memory.

README  view on Meta::CPAN

    NOTE: This will read the whole request body into memory, so make sure
    the "set_request_body_limit" can fit well within the available memory.

  body_params

      my $pairs = $cgi->body_params;

    Retrieve application/x-www-form-urlencoded or multipart/form-data body
    parameters as an ordered array reference of name/value pairs,
    represented as two-element array references. Names and values are
    decoded to Unicode characters.

    NOTE: This will read the text form fields into memory, so make sure the
    "set_request_body_limit" can fit well within the available memory.
    multipart/form-data file uploads will be streamed to temporary files
    accessible via "uploads" and related methods.

  body_param_names

      my $arrayref = $cgi->body_param_names;

    Retrieve application/x-www-form-urlencoded or multipart/form-data body
    parameter names, decoded to Unicode characters, as an ordered array
    reference, without duplication.

    NOTE: This will read the text form fields into memory as in
    "body_params".

  body_param

      my $value = $cgi->body_param('foo');

    Retrieve value of a named application/x-www-form-urlencoded or
    multipart/form-data body parameter, decoded to Unicode characters.

    If the parameter name was passed multiple times, returns the last
    value. Use "body_param_array" to get multiple values of a parameter.

    NOTE: This will read the text form fields into memory as in
    "body_params".

  body_param_array

      my $arrayref = $cgi->body_param_array('foo');

    Retrieve values of a named application/x-www-form-urlencoded or
    multipart/form-data body parameter, decoded to Unicode characters, as
    an ordered array reference.

    NOTE: This will read the text form fields into memory as in
    "body_params".

  body_parts

      my $parts = $cgi->body_parts;

    Retrieve multipart/form-data request body parts as an ordered array

README  view on Meta::CPAN

    NOTE: This will read the text form fields into memory, so make sure the
    "set_request_body_limit" can fit well within the available memory. File
    uploads will be streamed to temporary files.

  uploads

      my $pairs = $cgi->uploads;

    Retrieve multipart/form-data file uploads as an ordered array reference
    of name/upload pairs, represented as two-element array references.
    Names are decoded to Unicode characters.

    NOTE: This will read the text form fields into memory, so make sure the
    "set_request_body_limit" can fit well within the available memory.

    File uploads are represented as a hash reference containing the
    following keys:

    filename

      Original filename supplied to file input. An empty filename may

README  view on Meta::CPAN


      File::Temp object storing the file contents in a temporary file,
      which will be cleaned up when the CGI script ends by default. The
      filehandle will be open with the seek pointer at the start of the
      file for reading.

  upload_names

      my $arrayref = $cgi->upload_names;

    Retrieve multipart/form-data file upload names, decoded to Unicode
    characters, as an ordered array reference, without duplication.

    NOTE: This will read the text form fields into memory as in "uploads".

  upload

      my $upload = $cgi->upload('foo');

    Retrieve a named multipart/form-data file upload. If the upload name
    was passed multiple times, returns the last value. Use "upload_array"

README  view on Meta::CPAN

    The Content-Type response header will be set according to
    "set_response_type", or autodetected depending on the data type of any
    non-empty response content passed.

    The Date response header will be set to the current time as an HTTP
    date string if not set manually.

    If the "request_method" is HEAD, any provided response content will be
    ignored (other than redirect URLs) and Content-Length will be set to 0.

    text, html, or xml data is expected to be decoded Unicode characters,
    and will be encoded according to "set_response_charset" (UTF-8 by
    default). Unicode::UTF8 will be used for efficient UTF-8 encoding if
    available.

    json data structures will be encoded to JSON and UTF-8.

    data or file will render bytes from a string or local file path
    respectively. A handle, or a file whose size cannot be determined
    accurately from the filesystem, must be rendered using "render_chunk"
    since its Content-Length cannot be determined beforehand.

README  view on Meta::CPAN

    there is no more appropriate value. It will be set even if no content
    is passed to the first render_chunk call, in case content is rendered
    in subsequent calls.

    The Date response header will be set to the current time as an HTTP
    date string if not set manually.

    If the "request_method" is HEAD, any provided response content will be
    ignored.

    text, html, or xml data is expected to be decoded Unicode characters,
    and will be encoded according to "set_response_charset" (UTF-8 by
    default). Unicode::UTF8 will be used for efficient UTF-8 encoding if
    available.

    json data structures will be encoded to JSON and UTF-8.

    data, file, or handle will render bytes from a string, local file path,
    or open filehandle respectively. A handle will have binmode applied to
    remove any translation layers, and its contents will be streamed until
    EOF.

lib/CGI/Tiny.pod  view on Meta::CPAN

L</"body_parts">. Thus L</"uploads"> may not contain C<file> and may instead
contain C<content>, and L</"body_params"> text field values may be read from
C<file>, which will be expected to be a seekable filehandle if present.

=head3 set_multipart_form_charset

  $cgi = $cgi->set_multipart_form_charset('UTF-8');

Sets the default charset for decoding C<multipartE<sol>form-data> forms,
defaults to C<UTF-8>. Parameter and upload field names, upload filenames, and
text parameter values that don't specify a charset will be decoded from this
charset. Set to an empty string to disable this decoding, effectively
interpreting such values in C<ISO-8859-1>.

=head3 set_input_handle

  $cgi = $cgi->set_input_handle($fh);

Sets the input handle to read the request body from. If not set, reads from
C<STDIN>. The handle will have C<binmode> applied before reading to remove any
translation layers.

lib/CGI/Tiny.pod  view on Meta::CPAN


Retrieve values of a request cookie name as an ordered array reference.

=head3 params

  my $pairs = $cgi->params;

Retrieve URL query string parameters and C<application/x-www-form-urlencoded>
or C<multipart/form-data> body parameters as an ordered array reference of
name/value pairs, represented as two-element array references. Names and values
are decoded to Unicode characters.

Query parameters are returned first, followed by body parameters. Use
L</"query_params"> or L</"body_params"> to retrieve query or body parameters
separately.

B<NOTE:> This will read the text form fields into memory as in
L</"body_params">.

=head3 param_names

  my $arrayref = $cgi->param_names;

Retrieve URL query string parameter names and
C<application/x-www-form-urlencoded> or C<multipart/form-data> body parameter
names, decoded to Unicode characters, as an ordered array reference, without
duplication.

Query parameter names are returned first, followed by body parameter names. Use
L</"query_param_names"> or L</"body_param_names"> to retrieve query or body
parameter names separately.

B<NOTE:> This will read the text form fields into memory as in
L</"body_params">.

=head3 param

  my $value = $cgi->param('foo');

Retrieve value of a named URL query string parameter or
C<application/x-www-form-urlencoded> or C<multipart/form-data> body parameter,
decoded to Unicode characters.

If the parameter name was passed multiple times, returns the last body
parameter value if any, otherwise the last query parameter value. Use
L</"param_array"> to get multiple values of a parameter, or L</"query_param">
or L</"body_param"> to retrieve the last query or body parameter value
specifically.

B<NOTE:> This will read the text form fields into memory as in
L</"body_params">.

=head3 param_array

  my $arrayref = $cgi->param_array('foo');

Retrieve values of a named URL query string parameter or
C<application/x-www-form-urlencoded> or C<multipart/form-data> body parameter,
decoded to Unicode characters, as an ordered array reference.

Query parameter values will be returned first, followed by body parameter
values. Use L</"query_param_array"> or L</"body_param_array"> to retrieve query
or body parameter values separately.

B<NOTE:> This will read the text form fields into memory as in
L</"body_params">.

=head3 query_params

  my $pairs = $cgi->query_params;

Retrieve URL query string parameters as an ordered array reference of
name/value pairs, represented as two-element array references. Names and values
are decoded to Unicode characters.

=head3 query_param_names

  my $arrayref = $cgi->query_param_names;

Retrieve URL query string parameter names, decoded to Unicode characters, as an
ordered array reference, without duplication.

=head3 query_param

  my $value = $cgi->query_param('foo');

Retrieve value of a named URL query string parameter, decoded to Unicode
characters.

If the parameter name was passed multiple times, returns the last value. Use
L</"query_param_array"> to get multiple values of a parameter.

=head3 query_param_array

  my $arrayref = $cgi->query_param_array('foo');

Retrieve values of a named URL query string parameter, decoded to Unicode
characters, as an ordered array reference.

=head3 body

  my $bytes = $cgi->body;

Retrieve the request body as bytes.

B<NOTE:> This will read the whole request body into memory, so make sure the
L</"set_request_body_limit"> can fit well within the available memory.

lib/CGI/Tiny.pod  view on Meta::CPAN

B<NOTE:> This will read the whole request body into memory, so make sure the
L</"set_request_body_limit"> can fit well within the available memory.

=head3 body_params

  my $pairs = $cgi->body_params;

Retrieve C<applicationE<sol>x-www-form-urlencoded> or
C<multipartE<sol>form-data> body parameters as an ordered array reference of
name/value pairs, represented as two-element array references. Names and values
are decoded to Unicode characters.

B<NOTE:> This will read the text form fields into memory, so make sure the
L</"set_request_body_limit"> can fit well within the available memory.
C<multipartE<sol>form-data> file uploads will be streamed to temporary files
accessible via L</"uploads"> and related methods.

=head3 body_param_names

  my $arrayref = $cgi->body_param_names;

Retrieve C<applicationE<sol>x-www-form-urlencoded> or
C<multipartE<sol>form-data> body parameter names, decoded to Unicode
characters, as an ordered array reference, without duplication.

B<NOTE:> This will read the text form fields into memory as in
L</"body_params">.

=head3 body_param

  my $value = $cgi->body_param('foo');

Retrieve value of a named C<applicationE<sol>x-www-form-urlencoded> or
C<multipartE<sol>form-data> body parameter, decoded to Unicode characters.

If the parameter name was passed multiple times, returns the last value. Use
L</"body_param_array"> to get multiple values of a parameter.

B<NOTE:> This will read the text form fields into memory as in
L</"body_params">.

=head3 body_param_array

  my $arrayref = $cgi->body_param_array('foo');

Retrieve values of a named C<applicationE<sol>x-www-form-urlencoded> or
C<multipartE<sol>form-data> body parameter, decoded to Unicode characters, as
an ordered array reference.

B<NOTE:> This will read the text form fields into memory as in
L</"body_params">.

=head3 body_parts

  my $parts = $cgi->body_parts;

Retrieve C<multipartE<sol>form-data> request body parts as an ordered array

lib/CGI/Tiny.pod  view on Meta::CPAN

B<NOTE:> This will read the text form fields into memory, so make sure the
L</"set_request_body_limit"> can fit well within the available memory. File
uploads will be streamed to temporary files.

=head3 uploads

  my $pairs = $cgi->uploads;

Retrieve C<multipartE<sol>form-data> file uploads as an ordered array reference
of name/upload pairs, represented as two-element array references. Names are
decoded to Unicode characters.

B<NOTE:> This will read the text form fields into memory, so make sure the
L</"set_request_body_limit"> can fit well within the available memory.

File uploads are represented as a hash reference containing the following keys:

=over

=item filename

lib/CGI/Tiny.pod  view on Meta::CPAN

L<File::Temp> object storing the file contents in a temporary file, which will
be cleaned up when the CGI script ends by default. The filehandle will be open
with the C<seek> pointer at the start of the file for reading.

=back

=head3 upload_names

  my $arrayref = $cgi->upload_names;

Retrieve C<multipartE<sol>form-data> file upload names, decoded to Unicode
characters, as an ordered array reference, without duplication.

B<NOTE:> This will read the text form fields into memory as in L</"uploads">.

=head3 upload

  my $upload = $cgi->upload('foo');

Retrieve a named C<multipartE<sol>form-data> file upload. If the upload name
was passed multiple times, returns the last value. Use L</"upload_array">

lib/CGI/Tiny.pod  view on Meta::CPAN

The C<Content-Type> response header will be set according to
L</"set_response_type">, or autodetected depending on the data type of any
non-empty response content passed.

The C<Date> response header will be set to the current time as an HTTP date
string if not set manually.

If the L</"request_method"> is C<HEAD>, any provided response content will be
ignored (other than redirect URLs) and C<Content-Length> will be set to 0.

C<text>, C<html>, or C<xml> data is expected to be decoded Unicode characters,
and will be encoded according to L</"set_response_charset"> (UTF-8 by default).
L<Unicode::UTF8> will be used for efficient UTF-8 encoding if available.

C<json> data structures will be encoded to JSON and UTF-8.

C<data> or C<file> will render bytes from a string or local file path
respectively. A C<handle>, or a C<file> whose size cannot be determined
accurately from the filesystem, must be rendered using L</"render_chunk"> since
its C<Content-Length> cannot be determined beforehand.

lib/CGI/Tiny.pod  view on Meta::CPAN

is no more appropriate value. It will be set even if no content is passed to
the first C<render_chunk> call, in case content is rendered in subsequent
calls.

The C<Date> response header will be set to the current time as an HTTP date
string if not set manually.

If the L</"request_method"> is C<HEAD>, any provided response content will be
ignored.

C<text>, C<html>, or C<xml> data is expected to be decoded Unicode characters,
and will be encoded according to L</"set_response_charset"> (UTF-8 by default).
L<Unicode::UTF8> will be used for efficient UTF-8 encoding if available.

C<json> data structures will be encoded to JSON and UTF-8.

C<data>, C<file>, or C<handle> will render bytes from a string, local file
path, or open filehandle respectively. A C<handle> will have C<binmode> applied
to remove any translation layers, and its contents will be streamed until EOF.

C<redirect> responses must be rendered with L</"render">.

lib/CGI/Tiny/Multipart.pod  view on Meta::CPAN

  on_file_buffer => sub { my ($bytes, $hashref, $eof) = @_; }

Callback for custom parsing of file upload form fields. If specified, it will
be called with each (possibly empty) chunk of file contents that is read from
the form as bytes. The hash reference representing this form field is passed as
the second argument. The third argument will be true the last time the callback
is called for a particular form field.

The hash reference passed to the callback persists between calls for the same
form field, and is the same hash reference that will ultimately be returned to
represent the form field. It will contain the C<headers>, undecoded C<name> and
C<filename>, and C<size> of contents read so far (including the bytes just
passed to the callback). Modifying these values may result in unexpected
behavior, but other modifications to the hash reference are allowed.

If C<on_file_buffer> is not specified, file uploads will be stored in C<file>
as a L<File::Temp> object created with C<tempfile_args>.

  # approximate the default behavior
  on_file_buffer => sub {
    my ($bytes, $hashref, $eof) = @_;

lib/CGI/Tiny/Multipart.pod  view on Meta::CPAN


=over

=item headers

Hash reference of form field headers. Header names are represented in
lowercase.

=item name

Form field name from C<Content-Disposition> header, undecoded.

=item filename

Filename from C<Content-Disposition> header if present, undecoded.

=item size

Size of form field contents in bytes.

=item content

Form field contents as undecoded bytes, for form fields without a defined
C<filename>, or for all form fields if the C<parse_as_files> option was set to
a false value. File uploads are stored in a temporary C<file> instead by
default.

=item file

L<File::Temp> object referencing temporary file containing the form field
contents, for form fields with a defined C<filename>, or for all form fields if
the C<parse_as_files> option was set to a true value.



( run in 1.248 second using v1.01-cache-2.11-cpan-26ccb49234f )