Method
NAME
Router::Boost::Method - Router::Boost with HTTP method support
SYNOPSIS
use Router::Boost::Method;
my $router = Router::Boost::Method.new();
$router.add(['GET'], '/a', 'g');
$router.add(['POST'], '/a', 'p');
$router.add([], '/b', 'any');
$router.add(['GET'], '/c', 'get only');
$router.add(['GET', 'HEAD'], '/d', 'get/head');
$router.add(['GET'], '/user/{id:\d ** 3}', 'capture');
my $dest = $router.match('GET', '/user/123');
# => {:allowed-methods($[]), :captured(${:id("123")}), :!is-method-not-allowed, :stuff("capture")}
my $dest = $router.match('/access/to/not/existed/path');
# => {}
DESCRIPTION
Router::Boost doesn't care the routing with HTTP method. It's simple and good. But it makes hard to implement the rule like this:
get '/' => { 'get ok' };
post '/' => { 'post ok' };
Then, this class helps you to realize such functions.
METHODS
add(Router::Boost::Method:D: @methods, Str $path, Any $stuff)
Add a new path to the router.
@methods
is a list to represent HTTP method. i.e. ['GET'], ['POST'], ['DELETE'], ['PUT'], etc.
If you want to allow any HTTP methods, please pass []
for this argument (e.g. $router.add([], '/any', 'any')
).
You can specify the multiple HTTP methods in list like $router.add(['GET', 'HEAD'], '/', 'top')
>.
$path
is the path string.
$stuff
is the destination path data. Any data is OK.
match(Router::Boost::Method:D: Str $request-method, Str $path)
Matching with the router.
$request-method
is the HTTP request method.
$path
is the path string.
Return value is like following;
return {
stuff => 'foobar',
captured => {},
is-method-not-allowed => False,
allowed-methods => [],
};
If the request is not matching with any path, this method returns empty hash.
If the request is matched well then, return stuff
, captured
. And is-method-not-allowed
is False.
If the request path is matched but the $request-method
is not matched, then stuff
and captured
is Nil. And is-method-not-allowed
is True. And then allowed-method
suggests allowed HTTP methods.
< my @routes = $router->routes()
>
Get the list of registered routes. Every routes has following schema.
[List, Str, Any]
For example:
[['GET','HEAD'], "/foo", \&dispatch-foo]
AUTHOR
moznion <[email protected]>
ORIGINAL AUTHOR
Tokuhiro Matsuno