NAME

HTTP::Response::Maker - easy HTTP response object maker functions

SYNOPSIS

  use HTTP::Response::Maker 'HTTPResponse', (
      default_headers => [
          'Content-Type' => 'text/html; charset=utf-8'
      ],
      prefix => 'RESPOND_',
  );

  # now you can use functions like RESPOND_OK() or RESPOND_NOT_FOUND()

or

  use HTTP::Response::Maker::Exception prefix => 'throw_';

  throw_FOUND(Location => '/');

DESCRIPTION

HTTP::Response::Maker provides HTTP response object maker functions. They are named as OK() or NOT_FOUND(), corresponding to the HTTP::Status constant names.

USAGE

use HTTP::Response::Maker $impl, %args;

Exports HTTP response maker functions to current package.

$impl specifies what functions make. See IMPLEMENTATION.

%args has these keys:

prefix => ''

Prefix for exported functions names.

default_headers => \@HTTP::Response::Maker::DefaultHeaders

Default HTTP headers in arrayref.

IMPLEMENTATION

import()'s first argument specifies what type of objects functions generate. Currently it is one of:

HTTPResponse

Generates an HTTP::Response object.

PSGI

Generates an arrayref of PSGI response format.

Plack

Generates a Plack::Response object.

You can specify subclass of Plack::Response to generate:

  use HTTP::Response::Maker 'Plack', class => 'Your::Plack::Response';
Exception

Throws an HTTP::Exception.

FUNCTION ARGS

Exported functions accept arguments in some ways:

  my $res = OK;
  my $res = OK $content;
  my $res = OK \@headers;
  my $res = OK \@headers, $content;

AUTHOR

motemen <motemen@gmail.com>

SEE ALSO

HTTP::Status, PSGI, HTTP::Response, HTTP::Exception

LICENSE

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