CGI::Lite::Request - Request object based on CGI::Lite


NAME

CGI::Lite::Request - Request object based on CGI::Lite


SYNOPSIS

  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


DESCRIPTION

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:


METHODS

instance

Allows the CGI::Lite::Request manpage to behave as a singleton.

new

Constructor

parse

This method must be called explicitly to fetch the incoming request before

headers

accessor to an internally kept the HTTP::Headers manpage object.

parse

parses the incoming request - this is called automatically from the constructor, so you shouldn't need to call this expicitly.

args

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)

param( $key )

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.

params

returns all the parameters in the order in which they were parsed. Also includes cookies and query string parameters.

uri

returns the url minus the query string

secure

returns true if the request came over https

path_info

accessor to the part of the url after the script name

print

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

send_http_header

combines the response headers and sends these to the user agent

cookie

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

cookies

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

upload

returns a named the CGI::Lite::Upload manpage object keyed on the field name with which it was associated when uploaded.

uploads

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


AUTHOR

Richard Hundt <richard NO SPAM AT protea-systems.com>


ACKNOWLEDGEMENTS

Thanks to Sebastian Riedel for the code shamelessly stolen from the Catalyst::Request manpage and the Catalyst::Request::Upload manpage


SEE ALSO

the CGI::Lite manpage, the CGI::Lite::Cookie manpage, the CGI::Lite::Upload manpage


LICENCE

This library is free software and may be used under the same terms as Perl itself