CGI::Lite::Request - Request object based on CGI::Lite
use CGI::Lite::Request; my $req = CGI::Lite::Request->new; my $req = CGI::Lite::Request->instance; # parse the incoming request $req->parse(); $foo = $req->param('foo'); @foos = $req->param('foo'); # multiple values @params = $req->params(); # params in parse order $foo = $req->args->{foo}; # hash ref %args = $req->args; # hash $uri = $req->uri; # URI $req->print(@out); # print to STDOUT $req->headers; # HTTP::Headers instance $req->send_http_header; # print the header $req->content_type('text/html'); # set $req->content_type; # get $path = $req->path_info; # $ENV{PATH_INFO} $cookie = $req->cookie('my_cookie'); # fetch or create a cookie $req->cookie('SID')->value($sessid); # set a cookie $upload = $req->upload('my_field'); # CGI::Lite::Upload instance $uploads = $req->uploads; # hash ref of CGI::Lite::Upload objects
This module extends the CGI::Lite manpage to provide an interface which is compatible with the most commonly used methods of the Apache::Request manpage as a fat free alternative to the CGI manpage.
All methods of the CGI::Lite manpage are inherited as is, and the following are defined herein:
Allows the CGI::Lite::Request manpage to behave as a singleton.
Constructor
This method must be called explicitly to fetch the incoming request before
accessor to an internally kept the HTTP::Headers manpage object.
parses the incoming request - this is called automatically from the constructor, so you shouldn't need to call this expicitly.
return the request parameters as a hash or hash reference depending on the context. All form data, query string and cookie parameters are available in the returned hash(ref)
get a named parameter. If called in a scalar context, and if more than one value exists for a field name in the incoming form data, then an array reference is returned, otherwise for multiple values, if called in a list context, then an array is returned. If the value is a simple scalar, then in a scalar context just that value is returned.
returns all the parameters in the order in which they were parsed. Also includes cookies and query string parameters.
returns the url minus the query string
returns true if the request came over https
accessor to the part of the url after the script name
print to respond to the request. This is normally done after
send_http_header to print the body of data which should be
sent back the the user agent
combines the response headers and sends these to the user agent
returnes a named the CGI::Lite::Cookie manpage object. If one doesn't exist by the passed name, then creates a new one and returns it. Typical semantics would be:
$sessid = $req->cookie('SID')->value;
$req->cookie('SID')->value($sessid);
both of these methods will create a new the CGI::Lite::Request::Cookie manpage
object if one named 'SID' doesn't already exist. If you don't
want this behaviour, see cookies method
returns a hash reference of the CGI::Lite::Request::Cookie manpage objects keyed on their names. This can be used for accessing cookies where you don't want them to be created automatically if they don't exists, or for simply checking for their existence:
if (exists $req->cookies->{'SID'}) {
$sessid = $req->cookies->{'SID'}->value;
}
see the CGI::Lite::Request::Cookie manpage for more details
returns a named the CGI::Lite::Upload manpage object keyed on the field name with which it was associated when uploaded.
returns a hash reference of all the the CGI::Lite::Request::Upload manpage objects keyed on their names.
see the CGI::Lite::Request::Upload manpage for details
Richard Hundt <richard NO SPAM AT protea-systems.com>
Thanks to Sebastian Riedel for the code shamelessly stolen from the Catalyst::Request manpage and the Catalyst::Request::Upload manpage
the CGI::Lite manpage, the CGI::Lite::Cookie manpage, the CGI::Lite::Upload manpage
This library is free software and may be used under the same terms as Perl itself