1Mojolicious::Routes::MaUtscehr(3C)ontributed Perl DocumeMnotjaotliiocnious::Routes::Match(3)
2
3
4

NAME

6       Mojolicious::Routes::Match - Find routes
7

SYNOPSIS

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('/:controller/:action');
16         $r->put('/:controller/:action');
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 => '/foo/bar'});
22         say $match->stack->[0]{controller};
23         say $match->stack->[0]{action};
24
25         # Render
26         say $match->path_for->{path};
27         say $match->path_for(action => 'baz')->{path};
28

DESCRIPTION

30       Mojolicious::Routes::Match finds routes in Mojolicious::Routes
31       structures.
32

ATTRIBUTES

34       Mojolicious::Routes::Match implements the following attributes.
35
36   endpoint
37         my $route = $match->endpoint;
38         $match    = $match->endpoint(Mojolicious::Routes::Route->new);
39
40       The route endpoint that matched, usually a Mojolicious::Routes::Route
41       object.
42
43   position
44         my $position = $match->position;
45         $match       = $match->position(2);
46
47       Current position on the "stack", defaults to 0.
48
49   root
50         my $root = $match->root;
51         $match   = $match->root(Mojolicious::Routes->new);
52
53       The root of the route structure, usually a Mojolicious::Routes object.
54
55   stack
56         my $stack = $match->stack;
57         $match    = $match->stack([{action => 'foo'}, {action => 'bar'}]);
58
59       Captured parameters with nesting history.
60

METHODS

62       Mojolicious::Routes::Match inherits all methods from Mojo::Base and
63       implements the following new ones.
64
65   find
66         $match->find(Mojolicious::Controller->new, {method => 'GET', path => '/'});
67
68       Match controller and options against "root" to find an appropriate
69       "endpoint".
70
71   path_for
72         my $info = $match->path_for;
73         my $info = $match->path_for(foo => 'bar');
74         my $info = $match->path_for({foo => 'bar'});
75         my $info = $match->path_for('named');
76         my $info = $match->path_for('named', foo => 'bar');
77         my $info = $match->path_for('named', {foo => 'bar'});
78
79       Render matching route with parameters into path.
80

SEE ALSO

82       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
83
84
85
86perl v5.28.1                      2018-11-22     Mojolicious::Routes::Match(3)
Impressum