Mojolic...::Match(3)
π NAME π
Mojolicious::Routes::Match β Find routes β¨
okay so quick vibe check first: this whole page is straight out of the User Contributed Perl Documentation bestie, and it's literally the tool that goes "ooh where does this request go" and finds it for you π«Ά
πΈ SYNOPSIS πΈ
here's the whole little glow-up in action, no cap:
use Mojolicious::Controller;
use Mojolicious::Routes;
use Mojolicious::Routes::Match;
# Routes
my $r = Mojolicious::Routes->new;
$r->get('/user/:id');
$r->put('/user/:id');
# Match
my $c = Mojolicious::Controller->new;
my $match = Mojolicious::Routes::Match->new(root => $r);
$match->find($c => {method => 'PUT', path => '/user/23'});
say $match->stack->[0]{id};
# Render
say $match->path_for->{path};
say $match->path_for(id => 24)->{path};
likeβ¦ build routes, match a request, print the id, then render paths back out. iconic behavior only π
π¦ DESCRIPTION π¦
So Mojolicious::Routes::Match finds routes inside Mojolicious::Routes structures. That's it, that's the whole job, and it does it flawlessly fr fr π
β¨ ATTRIBUTES β¨
Mojolicious::Routes::Match implements the following attributes. (yes, all of them, we're not skipping a single one π)
π endpoint
my $route = $match->endpoint;
$match = $match->endpoint(Mojolicious::Routes::Route->new);
The route endpoint that actually matched β usually a Mojolicious::Routes::Route object. it's the one that ate and left no crumbs π₯
π position
my $position = $match->position;
$match = $match->position(2);
Your current position on the "stack", and it defaults to 0. baby steps, bestie πΆ
π§ root
my $root = $match->root;
$match = $match->root(Mojolicious::Routes->new);
The root of the whole route structure β usually a Mojolicious::Routes object. main character energy, everything lives under it π³
π stack
my $stack = $match->stack;
$match = $match->stack([{action => 'foo'}, {action => 'bar'}]);
Captured parameters with nesting history β like a little receipts trail of where you've been π
β METHODS β
Mojolicious::Routes::Match inherits all methods from Mojo::Base and implements the following new ones. slay π₯
π¦ find
$match->find(Mojolicious::Controller->new, {method => 'GET', path => '/'});
Matches the controller and options against "root" to find an appropriate "endpoint". this is the moment of truth ngl π
π path_for
my $info = $match->path_for;
my $info = $match->path_for(foo => 'bar');
my $info = $match->path_for({foo => 'bar'});
my $info = $match->path_for('named');
my $info = $match->path_for('named', foo => 'bar');
my $info = $match->path_for('named', {foo => 'bar'});
Renders the matching route with parameters into a path. so many ways to call it and every single one is valid, we love versatility π
π SEE ALSO π
MojoliciousMojolicious::Guides- <https://mojolicious.org>
go read the guides bestie, they're lowkey a whole education π
k that's the page!! brought to you by perl v5.42.0, dated 2026-07-15, and yes it's still filed under Mojolic...::Match(3) because the header only has room for so much π
β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Mojolicious 9.480.0-bp160.2.1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms