NAME

HTTP::Router - Yet Another Path Router for HTTP

SYNOPSIS

use HTTP::Router;

my $router = HTTP::Router->define(sub {
    $_->match('/')->to({ controller => 'Root', action => 'index' });
    $_->match('/index.{format}')->to({ controller => 'Root', action => 'index' });

    $_->match('/archives/{year}/{month}', { year => qr/\d{4}/, month => qr/\d{2}/ })
        ->to({ controller => 'Archive', action => 'by_month' });

    $_->match('/account/login', { method => ['GET', 'POST'] })
        ->to({ controller => 'Account', action => 'login' });

    $_->resources('users');

    $_->resource('account');

    $_->resources('members', sub {
        $_->resources('articles');
    });
});

# GET /index.html
my $match = $router->match($req);
$match->params;   # { controller => 'Root', action => 'index', format => 'html' }
$match->captures; # { format => 'html' }

$match->uri_for({ format => 'xml' }); # '/index.xml'

DESCRIPTION

HTTP::Router provides a Merb-like way of constructing routing tables.

METHODS

new

define($code)

reset

match($req)

route_for($req)

show_table

PROPERTIES

routeset

AUTHOR

NAKAGAWA Masaki <masaki@cpan.org>

Takatoshi Kitano <kitano.tk@gmail.com>

LICENSE

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

SEE ALSO

HTTP::Router::Mapper, HTTP::Router::Resources, HTTP::Router::Route, HTTP::Router::Match,

MojoX::Routes, http://merbivore.com/, HTTPx::Dispatcher, Path::Router, Path::Dispatcher