The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Web::Response - common response class for web frameworks

VERSION

version 0.05

SYNOPSIS

  use Web::Request;

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

DESCRIPTION

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.

METHODS

status($status)

Sets (and returns) the status attribute, as described above.

headers($headers)

Sets (and returns) the headers attribute, as described above.

header($name, $val)

Shortcut for $ret->headers->header($name, $val).

content_length($length)

Shortcut for $ret->headers->content_length($length).

content_type($type)

Shortcut for $ret->headers->content_type($type).

content_encoding($encoding)

Shortcut for $ret->headers->content_encoding($encoding).

location($location)

Shortcut for $ret->headers->header('Location', $location).

content($content)

Sets (and returns) the content attribute, as described above.

cookies($cookies)

Sets (and returns) the cookies attribute, as described above.

redirect($location, $status)

Sets the Location header to $location, and sets the status code to $status (defaulting to 302 if not given).

finalize

Returns a valid PSGI response, based on the values given.

CONSTRUCTOR

new(%params)

Returns a new Web::Response object. Valid parameters are:

status

The HTTP status code for the response.

headers

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.

content

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 [].

cookies

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 {}.

AUTHOR

Jesse Luehrs <doy at cpan dot org>

COPYRIGHT AND LICENSE

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.