
Web::Response - common response class for web frameworks

version 0.05

use Web::Request;
my $app = sub {
my ($env) = @_;
my $req = Web::Request->new_from_env($env);
# ...
return $req->new_response(status => 404)->finalize;
};

Web::Response is a response class for PSGI applications. Generally, you will want to create instances of this class via new_response on the request object, since that allows a framework which subclasses Web::Request to also return an appropriate subclass of Web::Response.
All attributes on Web::Response objects are writable, and the final state of them will be used to generate a real PSGI response when finalize is called.

Sets (and returns) the status attribute, as described above.
Sets (and returns) the headers attribute, as described above.
Shortcut for $ret->headers->header($name, $val).
Shortcut for $ret->headers->content_length($length).
Shortcut for $ret->headers->content_type($type).
Shortcut for $ret->headers->content_encoding($encoding).
Shortcut for $ret->headers->header('Location', $location).
Sets (and returns) the content attribute, as described above.
Sets (and returns) the cookies attribute, as described above.
Sets the Location header to $location, and sets the status code to $status (defaulting to 302 if not given).
Returns a valid PSGI response, based on the values given.

Returns a new Web::Response object. Valid parameters are:
The HTTP status code for the response.
The headers to return with the response. Can be provided as an arrayref, a hashref, or an HTTP::Headers object. Defaults to an HTTP::Headers object with no contents.
The content of the request. Can be provided as a string, an object which overloads "", an arrayref containing a list of either of those, a filehandle, or an object that implements the getline and close methods. Defaults to [].
A hashref of cookies to return with the response. The values in the hashref can either be the string values of the cookies, or a hashref whose keys can be any of value, domain, path, expires, max-age, secure, httponly. In addition to the date format that expires normally uses, expires can also be provided as a UNIX timestamp (an epoch time, as returned from time). Defaults to {}.

Jesse Luehrs <doy at cpan dot org>

This software is copyright (c) 2012 by Jesse Luehrs.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.