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

NAME

PEF::Front::Response - HTTP response object

SYNOPSIS

  use PEF::Front::Response;
  use PEF::Front::Route;
  
  PEF::Front::Route::add_route(
   get '/' => sub {
      PEF::Front::Response->new(
        headers => ['Content-Type' => 'text/plain'], 
        body => 'Hello World!'
      );
    }
  );

DESCRIPTION

PEF::Front::Response is a response class for your applications. Generally, you will want to create instances of this class only as exceptions or in special cases.

FUNCTIONS

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 PEF::Front::HTTPHeaders object.

cookies

The cookies to return with the response. Can be provided as an arrayref, a hashref, or an PEF::Front::Headers object.

The values of cookies 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. Defaults to {}.

body

The content of the request. Can be provided as a string, an arrayref containing a list of either of strings, a filehandle, or code reference. Defaults to ''.

base

Base URL for incomplete redirect location.

request

PEF::Front::Request object to import base, headers and cookies from.

status([$status])

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

add_header($key, $value)

Adds response header. This action allows to have multiple headers with the same name.

set_header($key, $value)

Sets response header. This action ensures that there's only one header with given name in response.

remove_header($key)

Removes header.

get_header($key)

Returns header.

set_cookie($key, $value)

Sets cookie value.

remove_cookie($key)

Removes cookie.

get_cookie($key)

Returns get_cookie.

set_body($body)

Sets response body. It can be string, array of strings, file handle or code reference.

add_body($body_chunk)

Adds response body chunk.

get_body

Returns response body.

redirect($location, $status)

Response will redirect browser to new location.

content_type($ct)

Sets 'Content-Type'

expires($expires)

Makes 'expires' cookie attribute. $expires is time interval parseable by Time::Duration.

make_headers

Makes all response headers.

response

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

AUTHOR

This module was written and is maintained by Anton Petrusevich.

Copyright and License

Copyright (c) 2016 Anton Petrusevich. Some Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.