NAME
CGI::Easy::Util - low-level helpers for HTTP/CGI
VERSION
This document describes CGI::Easy::Util version v2.0.1
SYNOPSIS
use CGI::Easy::Util qw( date_http date_cookie make_cookie );
my $mtime = (stat '/some/file')[9];
printf "Last-Modified: %s\r\n", date_http($mtime);
printf "Set-Cookie: a=5; expires=%s\r\n", date_cookie(time+86400);
printf make_cookie({ name=>'a', value=>5, expires=>time+86400 });
use CGI::Easy::Util qw( uri_unescape_plus
burst_urlencoded burst_multipart );
my $s = uri_unescape_plus('a+b%20c'); # $s is 'a b c'
my %param = %{ burst_urlencoded($ENV{QUERY_STRING}) };
my $a = $param{a}[0];
($params, $filenames, $mimetypes) = burst_multipart($STDIN_data, $1)
if $ENV{CONTENT_TYPE} =~ m/;\s+boundary=(.*)/xms;
my $avatar_image = $params->{avatar}[0];
my $avatar_filename = $filenames->{avatar}[0];
my $avatar_mimetype = $mimetypes->{avatar}[0];
DESCRIPTION
This module contain low-level function which you usually doesn't need - use CGI::Easy::Request and CGI::Easy::Headers instead.
EXPORTS
Nothing by default, but all documented functions can be explicitly imported.
INTERFACE
date_http
$date = date_http( $seconds );
Convert given time into text format suitable for sending in HTTP headers.
Return date string.
date_cookie
$date = date_cookie( $seconds );
Convert given time into text format suitable for sending in HTTP header Set-Cookie's "expires" option.
Return date string.
make_cookie
$header = make_cookie( \%cookie );
Convert HASHREF with cookie properties to "Set-Cookie: ..." HTTP header.
Possible keys in %cookie:
name REQUIRED STRING
value OPTIONAL STRING (default "")
domain OPTIONAL STRING (default "")
path OPTIONAL STRING (default "/")
expires OPTIONAL STRING or SECONDS
secure OPTIONAL BOOL
Format for "expires" should be either correct date 'Thu, 01-Jan-1970 00:00:00 GMT' or time in seconds.
Return HTTP header string.
uri_unescape_plus
$unescaped = uri_unescape_plus( $uri_escaped_value );
Same as uri_unescape from URI::Escape but additionally replace '+' with space.
Return unescaped string.
burst_urlencoded
my %param = %{ burst_urlencoded( $url_encoded_name_value_pairs ) };
Unpack name/value pairs from url-encoded string (like $ENV{QUERY_STRING} or STDIN content for non-multipart forms sent using POST method).
Return HASHREF with params, each param's value will be ARRAYREF (because there can be more than one value for any parameter in source string).
burst_multipart
($params, $filenames, $mimetypes) = burst_multipart( $buffer, $boundary );
Unpack buffer with name/value pairs in multipart/form-data format. This format usually used to upload files from forms, and each name/value pair may additionally contain 'file name' and 'mime type' properties.
Return three HASHREF (with param's values, with param's file names, and with param's mime types), all values in all three HASHREF are ARRAYREF (because there can be more than one value for any parameter in source string). For non-file-upload parameters corresponding values in last two hashes (with file names and mime types) will be undef().
SUPPORT
Bugs / Feature Requests
Please report any bugs or feature requests through the issue tracker at https://github.com/powerman/perl-CGI-Easy/issues. You will be notified automatically of any progress on your issue.
Source Code
This is open source software. The code repository is available for public review and contribution under the terms of the license. Feel free to fork the repository and submit pull requests.
https://github.com/powerman/perl-CGI-Easy
git clone https://github.com/powerman/perl-CGI-Easy.git
Resources
MetaCPAN Search
CPAN Ratings
AnnoCPAN: Annotated CPAN documentation
CPAN Testers Matrix
CPANTS: A CPAN Testing Service (Kwalitee)
AUTHOR
Alex Efros <powerman@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2009- by Alex Efros <powerman@cpan.org>.
This module also include some code derived from
- CGI::Minimal (1.29)
-
by Benjamin Franz <snowhare@nihongo.org>. Copyright (c) Benjamin Franz. All rights reserved.
This is free software, licensed under:
The MIT (X11) License