Name

Mungo::Request — represent an HTTP request context

Synopsis

<!-- Within your HTML, you get a Request object for free -->
<% if (defined $Request) { ... } %>
<!-- Get params -->
<%
   my $value = $Request->Params('param_name');
   my %params = $Request->Params();
%>
<!-- Get Request Info -->
<%
   my $refer = $Request->ServerVariables('REFERER');
   my $refer = $Request->ServerVariables('REFERRER'); # Same
   my $server_hostname = $Request->ServerVariables('HTTP_HOST');
   my $client_ip = $Request->ServerVariables('REMOTE_IP'); # If proxied, uses HTTP_X_FORWARDED_FOR.
my $header = $Request->Header('HeaderName');
%>
<!-- Get cookies -->
<%
   # for single-valued cookies
   my $value = $Request->Cookies($cookie_name);
# for multi-valued cookies
my $hashref = $Request->Cookies($cookie_name);
# for multi-valued cookies
my $value = $Request->Cookies($cookie_name, $key);
%>
<!-- Get uploaded file data -->
<%
   # Assuming you have <input type="file" name="myfile" />
my $param = $Request->Params->{myfile};
my $handle = $param->{handle};
my $filename_on_client = $param->{filename};
my $total_size = $param->{size};
my $content_type = $param->{'content-type'}; # Not entirely reliable - consider File::MMagic or similar
# $handle is a IO::Handle subclass
my ($content, $chunk);
while (my $bytes_read = $handle->read($chunk, 1024)) {
   $content .= $chunk;
)
%>


DESCRIPTION

Represents the request side of a Mungo request cycle.

See Mungo, and Mungo::Response.

Mungo::Request acts as a singleton on a per-request basis. So even if you have nested includes, there will only ever be one Mungo::Request. That's generally what you'd expect.

$value = $Request->Cookies($cookie_name);

$hashref = $Request->Cookies($cookie_name);

$value = $Request->Cookies($cookie_name, $key);

Reads and parses incoming cookie data. Behavior depends on whether the cookie contained name-value pairs.

If not, the first form simply returns the value set in the given cookie name, or undef.

If name-value pairs are present, the second form returns a hashref of all the name-value pairs.

If name-value pairs are present, the third form returns the value for the given key.

If no such cookie with the given name exists, returns undef.

$value = $Request->QueryString($name);

%params = $Request->QueryString();

$params_hashref = $Request->QueryString();

Returns one value (first form) or all values (second and third forms) from the submitted query string.

Params() is preferred.

$value = $Request->Form($name);

%params = $Request->Form();

$params_hashref = $Request->Form();

Returns one value (first form) or all values (second and third forms) from the submitted POST data.

Params() is preferred.

$value = $Request->Params($name);

%params = $Request->Params();

$params_hashref = $Request->Params();

Returns one value (first form) or all values (second and third forms) from the submitted CGI parameters, whether that was via the query string or via POST data.

This method is recommended over Form and QueryString, because it is independent of how the data was submitted.

If both methods provide data, Form overrides QueryString.

$value = $Request->ServerVariables($variable_name);

Returns information about the request or the server. Only certain variables are supported:

REFERER, REFERRER, DOCUMENT_ROOT, HTTP_HOST

$bool = $req->IsSecure();

Returns true or false depending on whether the request came in over HTTPS.

$value = $Request->Header('User-Agent');

Returns raw header information from the request header.

AUTHOR

Theo Schlossnagle (code)

Clinton Wolfe (docs)