Rechercher une page de manuel
Catalyst::Request.3pm
Langue: en
Version: 2009-02-04 (fedora - 05/07/09)
Section: 3 (Bibliothèques de fonctions)
NAME
Catalyst::Request - provides information about the current client requestSYNOPSIS
$req = $c->request; $req->action; $req->address; $req->arguments; $req->args; $req->base; $req->body; $req->body_parameters; $req->content_encoding; $req->content_length; $req->content_type; $req->cookie; $req->cookies; $req->header; $req->headers; $req->hostname; $req->input; $req->query_keywords; $req->match; $req->method; $req->param; $req->parameters; $req->params; $req->path; $req->protocol; $req->query_parameters; $req->read; $req->referer; $req->secure; $req->captures; # previously knows as snippets $req->upload; $req->uploads; $req->uri; $req->user; $req->user_agent;
See also Catalyst, Catalyst::Request::Upload.
DESCRIPTION
This is the Catalyst Request class, which provides an interface to data for the current client request. The request object is prepared by Catalyst::Engine, thus hiding the details of the particular engine implementation.METHODS
$req->action
$req->action
[DEPRECATED] Returns the name of the requested action.
Use "$c->action" instead (which returns a Catalyst::Action object).
$req->address
$req->address
Returns the IP address of the client.
$req->arguments
$req->arguments
Returns a reference to an array containing the arguments.
print $c->request->arguments->[0];
For example, if your action was
package MyApp::C::Foo; sub moose : Local { ... }
and the URI for the request was "http://.../foo/moose/bah", the string "bah" would be the first and only argument.
$req->args
$req->args
Shortcut for arguments.
$req->base
$req->base
Contains the URI base. This will always have a trailing slash.
If your application was queried with the URI "http://localhost:3000/some/path" then "base" is "http://localhost:3000/".
$req->body
$req->body
Returns the message body of the request, unless Content-Type is "application/x-www-form-urlencoded" or "multipart/form-data".
$req->body_parameters
$req->body_parameters
Returns a reference to a hash containing body (POST) parameters. Values can be either a scalar or an arrayref containing scalars.
print $c->request->body_parameters->{field}; print $c->request->body_parameters->{field}->[0];
These are the parameters from the POST part of the request, if any.
$req->body_params
$req->body_params
Shortcut for body_parameters.
$req->content_encoding
$req->content_encoding
Shortcut for $req->headers->content_encoding.
$req->content_length
$req->content_length
Shortcut for $req->headers->content_length.
$req->content_type
$req->content_type
Shortcut for $req->headers->content_type.
$req->cookie
$req->cookie
A convenient method to access $req->cookies.
$cookie = $c->request->cookie('name'); @cookies = $c->request->cookie;
$req->cookies
$req->cookies
Returns a reference to a hash containing the cookies.
print $c->request->cookies->{mycookie}->value;
The cookies in the hash are indexed by name, and the values are CGI::Cookie objects.
$req->header
$req->header
Shortcut for $req->headers->header.
$req->headers
$req->headers
Returns an HTTP::Headers object containing the headers for the current request.
print $c->request->headers->header('X-Catalyst');
$req->hostname
$req->hostname
Returns the hostname of the client.
$req->input
$req->input
Alias for $req->body.
$req->query_keywords
$req->query_keywords
Contains the keywords portion of a query string, when no '=' signs are present.
http://localhost/path?some+keywords $c->request->query_keywords will contain 'some keywords'
$req->match
$req->match
This contains the matching part of a Regex action. Otherwise it returns the same as 'action', except for default actions, which return an empty string.
$req->method
$req->method
Contains the request method ("GET", "POST", "HEAD", etc).
$req->param
$req->param
Returns GET and POST parameters with a CGI.pm-compatible param method. This is an alternative method for accessing parameters in $c->req->parameters.
$value = $c->request->param( 'foo' ); @values = $c->request->param( 'foo' ); @params = $c->request->param;
Like CGI, and unlike earlier versions of Catalyst, passing multiple arguments to this method, like this:
$c->request->param( 'foo', 'bar', 'gorch', 'quxx' );
will set the parameter "foo" to the multiple values "bar", "gorch" and "quxx". Previously this would have added "bar" as another value to "foo" (creating it if it didn't exist before), and "quxx" as another value for "gorch".
$req->parameters
$req->parameters
Returns a reference to a hash containing GET and POST parameters. Values can be either a scalar or an arrayref containing scalars.
print $c->request->parameters->{field}; print $c->request->parameters->{field}->[0];
This is the combination of "query_parameters" and "body_parameters".
$req->params
$req->params
Shortcut for $req->parameters.
$req->path
$req->path
Returns the path, i.e. the part of the URI after $req->base, for the current request.
$req->path_info
$req->path_info
Alias for path, added for compability with CGI.
$req->protocol
$req->protocol
Returns the protocol (HTTP/1.0 or HTTP/1.1) used for the current request.
$req->query_parameters
$req->query_parameters
$req->query_params
$req->query_params
Returns a reference to a hash containing query string (GET) parameters. Values can be either a scalar or an arrayref containing scalars.
print $c->request->query_parameters->{field}; print $c->request->query_parameters->{field}->[0];
$req->read( [$maxlength] )
$req->read( [$maxlength] )
Reads a chunk of data from the request body. This method is intended to be used in a while loop, reading $maxlength bytes on every call. $maxlength defaults to the size of the request if not specified.
You have to set MyApp->config->{parse_on_demand} to use this directly.
$req->referer
$req->referer
Shortcut for $req->headers->referer. Returns the referring page.
$req->secure
$req->secure
Returns true or false, indicating whether the connection is secure (https).
$req->captures
$req->captures
Returns a reference to an array containing regex captures.
my @captures = @{ $c->request->captures };
$req->snippets
$req->snippets
"captures" used to be called snippets. This is still available for backwoards compatibility, but is considered deprecated.
$req->upload
$req->upload
A convenient method to access $req->uploads.
$upload = $c->request->upload('field'); @uploads = $c->request->upload('field'); @fields = $c->request->upload; for my $upload ( $c->request->upload('field') ) { print $upload->filename; }
$req->uploads
$req->uploads
Returns a reference to a hash containing uploads. Values can be either a Catalyst::Request::Upload object, or an arrayref of Catalyst::Request::Upload objects.
my $upload = $c->request->uploads->{field}; my $upload = $c->request->uploads->{field}->[0];
$req->uri
$req->uri
Returns a URI object for the current request. Stringifies to the URI text.
$req->uri_with( { key => 'value' } );
$req->uri_with( { key => 'value' } );
Returns a rewritten URI object for the current request. Key/value pairs passed in will override existing parameters. You can remove an existing parameter by passing in an undef value. Unmodified pairs will be preserved.
$req->user
$req->user
Returns the currently logged in user. Deprecated. The method recommended for newer plugins is $c->user.
$req->user_agent
$req->user_agent
Shortcut to $req->headers->user_agent. Returns the user agent (browser) version string.
AUTHORS
Catalyst Contributors, see Catalyst.pmCOPYRIGHT
This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.Contenus ©2006-2024 Benjamin Poulain
Design ©2006-2024 Maxime Vantorre