Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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

branch: caf

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 t
Octocat-spinner-32 tools
Octocat-spinner-32 xt
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .shipit
Octocat-spinner-32 Changes
Octocat-spinner-32 MANIFEST.SKIP
Octocat-spinner-32 Makefile.PL
Octocat-spinner-32 README
Octocat-spinner-32 README.pod
README.pod

NAME

HTTP::Router - Yet Another Path Router for HTTP

SYNOPSIS

  use HTTP::Router;

  my $router = HTTP::Router->new;

  my $route = HTTP::Router::Route->new(
      path       => '/',
      conditions => { method => 'GET' },
      params     => { controller => 'Root', action => 'index' },
  );
  $router->add_route($route);
  # or
  $router->add_route('/' => (
      conditions => { method => 'GET' },
      params     => { controller => 'Root', action => 'index' },
  ));

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

DESCRIPTION

HTTP::Router provides a way of constructing routing tables.

If you are interested in a Merb-like constructing way, please check HTTP::Router::Declare.

METHODS

new

Returns a HTTP::Router object.

add_route($route)

add_route($path, %args)

Adds a new route. You can specify HTTP::Router::Route object, or path string and options pair.

example:

  my $route = HTTP::Router::Route->new(
      path       => '/',
      conditions => { method => 'GET' },
      params     => { controller => 'Root', action => 'index' },
  );

  $router->add_route($route);

equals to:

  $router->add_route('/' => (
      conditions => { method => 'GET' },
      params     => { controller => 'Root', action => 'index' },
  ));

routes

Returns registered routes.

reset

Clears registered routes.

match($req)

Returns a HTTP::Router::Match object that matches a given request. If no routes match, it returns undef.

route_for($req)

Returns a HTTP::Router::Route object that matches a given request. If no routes match, it returns undef.

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::Declare, HTTP::Router::Route, HTTP::Router::Match,

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

Something went wrong with that request. Please try again.