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

NAME

Eve::HttpDispatcher - an event handler for HTTP request events.

SYNOPSIS

    use Eve::HttpDispatcher;

    my $dispatcher = Eve::HttpDispatcher->new(
        request_constructor => $request_constructor,
        response => $response,
        base_uri => $base_uri,
        alias_base_uri_list => [$alias_base_uri, $another_alias_base_uri],
        event_map => $event_map);

    $dispatcher->bind(
        name => $name
        pattern => $pattern,
        resource_constructor => $resource_constructor);

    $dispatcher->bind(
        name => $name_404
        pattern => $pattern_404,
        resource_constructor => $resource_constructor_404,
        exception => 'Eve::Exception::Http::404NotFound');

    $dispatcher->handle(event => $event);

DESCRIPTION

Eve::HttpDispatcher class is a central component to a web service application.

Constructor arguments

request_constructor

a code reference that returns an HTTP request object when passed an environment hash

response

an HTTP response object

event_map

an event map object.

base_uri

a base URI object used for resource binding.

alias_base_uri_list

(optional) a reference to a list of additional base URI objects that will be used for resource matching.

METHODS

init()

bind()

Binds an HTTP resource.

Arguments

name

a name identifying the binding

pattern

an URI pattern string that can contain placeholders

base_uri

a URI object that represents a base URL for the binding resource

resource_constructor

a code reference that returns an HTTP resource object

exception

(optional) an HTTP exception class name that the bound resource should be used to handle. Note: there can be only one resource bound to handle a certain exception.

Throws

Eve::Exception::HttpDispatcher

if either name or compound URI or exception class name is not unique.

get_uri()

Arguments

name

a name identifying the binding

Returns

A URI bound to the resource name.

Throws

Eve::Error::HttpDispatcher

When there is no resource with the requested name.

handle()

Chooses a resource using the request URI and delegates control to the resource's process() method. It also passes placeholder matches into this method.

Arguments

event

a Eve::Event::HttpRequestReceived object.

Throws

Eve::Exception::Http::404NotFound

if no resources match the request and no resources that handle the Eve::Exception::Http::404NotFound are bound.

SEE ALSO

Eve::Class
Eve::Event::HttpResponseReady
Eve::Exception
Eve::HttpResource

LICENSE AND COPYRIGHT

Copyright 2012 Igor Zinovyev.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

AUTHOR

Sergey Konoplev
Igor Zinovyev