-
Notifications
You must be signed in to change notification settings - Fork 1
/
README
95 lines (69 loc) · 2.32 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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.
freeze
Creates inline matcher using registered routes.
thaw
Clears inline matcher.
is_frozen
Returns true if inline matcher is defined.
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