• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

inc/H18-Mar-2010-9,7227,075

lib/H18-Mar-2010-1,038502

t/H18-Mar-2010-582452

xt/H18-Mar-2010-4337

ChangesH A D18-Mar-2010505 2115

MANIFESTH A D18-Mar-20102.4 KiB102101

META.ymlH A D18-Mar-2010927 4342

Makefile.PLH A D18-Mar-20101,009 4433

READMEH A D18-Mar-20102.3 KiB9669

README.podH A D18-Mar-20102.3 KiB11972

README

1NAME
2    HTTP::Router - Yet Another Path Router for HTTP
3
4SYNOPSIS
5      use HTTP::Router;
6
7      my $router = HTTP::Router->new;
8
9      my $route = HTTP::Router::Route->new(
10          path       => '/',
11          conditions => { method => 'GET' },
12          params     => { controller => 'Root', action => 'index' },
13      );
14      $router->add_route($route);
15      # or
16      $router->add_route('/' => (
17          conditions => { method => 'GET' },
18          params     => { controller => 'Root', action => 'index' },
19      ));
20
21      # GET /
22      my $match = $router->match($req);
23      $match->params;  # { controller => 'Root', action => 'index' }
24      $match->uri_for; # '/'
25
26DESCRIPTION
27    HTTP::Router provides a way of constructing routing tables.
28
29    If you are interested in a Merb-like constructing way, please check
30    HTTP::Router::Declare.
31
32METHODS
33  new
34    Returns a HTTP::Router object.
35
36  add_route($route)
37  add_route($path, %args)
38    Adds a new route. You can specify HTTP::Router::Route object, or path
39    string and options pair.
40
41    example:
42
43      my $route = HTTP::Router::Route->new(
44          path       => '/',
45          conditions => { method => 'GET' },
46          params     => { controller => 'Root', action => 'index' },
47      );
48
49      $router->add_route($route);
50
51    equals to:
52
53      $router->add_route('/' => (
54          conditions => { method => 'GET' },
55          params     => { controller => 'Root', action => 'index' },
56      ));
57
58  routes
59    Returns registered routes.
60
61  reset
62    Clears registered routes.
63
64  freeze
65    Creates inline matcher using registered routes.
66
67  thaw
68    Clears inline matcher.
69
70  is_frozen
71    Returns true if inline matcher is defined.
72
73  match($req)
74    Returns a HTTP::Router::Match object that matches a given request. If no
75    routes match, it returns "undef".
76
77  route_for($req)
78    Returns a HTTP::Router::Route object that matches a given request. If no
79    routes match, it returns "undef".
80
81AUTHOR
82    NAKAGAWA Masaki <masaki@cpan.org>
83
84    Takatoshi Kitano <kitano.tk@gmail.com>
85
86LICENSE
87    This library is free software; you can redistribute it and/or modify it
88    under the same terms as Perl itself.
89
90SEE ALSO
91    HTTP::Router::Declare, HTTP::Router::Route, HTTP::Router::Match,
92
93    MojoX::Routes, <http://merbivore.com/>, HTTPx::Dispatcher, Path::Router,
94    Path::Dispatcher
95
96

README.pod

1=for stopwords inline
2
3=head1 NAME
4
5HTTP::Router - Yet Another Path Router for HTTP
6
7=head1 SYNOPSIS
8
9  use HTTP::Router;
10
11  my $router = HTTP::Router->new;
12
13  my $route = HTTP::Router::Route->new(
14      path       => '/',
15      conditions => { method => 'GET' },
16      params     => { controller => 'Root', action => 'index' },
17  );
18  $router->add_route($route);
19  # or
20  $router->add_route('/' => (
21      conditions => { method => 'GET' },
22      params     => { controller => 'Root', action => 'index' },
23  ));
24
25  # GET /
26  my $match = $router->match($req);
27  $match->params;  # { controller => 'Root', action => 'index' }
28  $match->uri_for; # '/'
29
30=head1 DESCRIPTION
31
32HTTP::Router provides a way of constructing routing tables.
33
34If you are interested in a Merb-like constructing way,
35please check L<HTTP::Router::Declare>.
36
37=head1 METHODS
38
39=head2 new
40
41Returns a HTTP::Router object.
42
43=head2 add_route($route)
44
45=head2 add_route($path, %args)
46
47Adds a new route.
48You can specify L<HTTP::Router::Route> object,
49or path string and options pair.
50
51example:
52
53  my $route = HTTP::Router::Route->new(
54      path       => '/',
55      conditions => { method => 'GET' },
56      params     => { controller => 'Root', action => 'index' },
57  );
58
59  $router->add_route($route);
60
61equals to:
62
63  $router->add_route('/' => (
64      conditions => { method => 'GET' },
65      params     => { controller => 'Root', action => 'index' },
66  ));
67
68=head2 routes
69
70Returns registered routes.
71
72=head2 reset
73
74Clears registered routes.
75
76=head2 freeze
77
78Creates inline matcher using registered routes.
79
80=head2 thaw
81
82Clears inline matcher.
83
84=head2 is_frozen
85
86Returns true if inline matcher is defined.
87
88=head2 match($req)
89
90Returns a L<HTTP::Router::Match> object that matches a given request.
91If no routes match, it returns C<undef>.
92
93=head2 route_for($req)
94
95Returns a L<HTTP::Router::Route> object that matches a given request.
96If no routes match, it returns C<undef>.
97
98=head1 AUTHOR
99
100NAKAGAWA Masaki E<lt>masaki@cpan.orgE<gt>
101
102Takatoshi Kitano E<lt>kitano.tk@gmail.comE<gt>
103
104=head1 LICENSE
105
106This library is free software; you can redistribute it and/or modify
107it under the same terms as Perl itself.
108
109=head1 SEE ALSO
110
111L<HTTP::Router::Declare>, L<HTTP::Router::Route>, L<HTTP::Router::Match>,
112
113L<MojoX::Routes>, L<http://merbivore.com/>,
114L<HTTPx::Dispatcher>, L<Path::Router>, L<Path::Dispatcher>
115
116
117=cut
118
119