1Mojolicious::Routes::MaUtscehr(3C)ontributed Perl DocumeMnotjaotliiocnious::Routes::Match(3)
2
3
4
6 Mojolicious::Routes::Match - Find routes
7
9 use Mojolicious::Controller;
10 use Mojolicious::Routes;
11 use Mojolicious::Routes::Match;
12
13 # Routes
14 my $r = Mojolicious::Routes->new;
15 $r->get('/user/:id');
16 $r->put('/user/:id');
17
18 # Match
19 my $c = Mojolicious::Controller->new;
20 my $match = Mojolicious::Routes::Match->new(root => $r);
21 $match->find($c => {method => 'PUT', path => '/user/23'});
22 say $match->stack->[0]{id};
23
24 # Render
25 say $match->path_for->{path};
26 say $match->path_for(id => 24)->{path};
27
29 Mojolicious::Routes::Match finds routes in Mojolicious::Routes
30 structures.
31
33 Mojolicious::Routes::Match implements the following attributes.
34
35 endpoint
36 my $route = $match->endpoint;
37 $match = $match->endpoint(Mojolicious::Routes::Route->new);
38
39 The route endpoint that matched, usually a Mojolicious::Routes::Route
40 object.
41
42 position
43 my $position = $match->position;
44 $match = $match->position(2);
45
46 Current position on the "stack", defaults to 0.
47
48 root
49 my $root = $match->root;
50 $match = $match->root(Mojolicious::Routes->new);
51
52 The root of the route structure, usually a Mojolicious::Routes object.
53
54 stack
55 my $stack = $match->stack;
56 $match = $match->stack([{action => 'foo'}, {action => 'bar'}]);
57
58 Captured parameters with nesting history.
59
61 Mojolicious::Routes::Match inherits all methods from Mojo::Base and
62 implements the following new ones.
63
64 find
65 $match->find(Mojolicious::Controller->new, {method => 'GET', path => '/'});
66
67 Match controller and options against "root" to find an appropriate
68 "endpoint".
69
70 path_for
71 my $info = $match->path_for;
72 my $info = $match->path_for(foo => 'bar');
73 my $info = $match->path_for({foo => 'bar'});
74 my $info = $match->path_for('named');
75 my $info = $match->path_for('named', foo => 'bar');
76 my $info = $match->path_for('named', {foo => 'bar'});
77
78 Render matching route with parameters into path.
79
81 Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
82
83
84
85perl v5.34.0 2022-01-21 Mojolicious::Routes::Match(3)