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 🌈

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