Mojolic...Pattern(3)

✨ NAME ✨

okay bestie, this is the Mojolic...Pattern(3) page from the User Contributed Perl Documentation β€” aka Mojolicious::Routes::Pattern, the Route pattern module. πŸ’…

🌸 SYNOPSIS 🌸

use Mojolicious::Routes::Pattern;

# Create pattern
my $pattern = Mojolicious::Routes::Pattern->new('/test/:name');

# Match routes
my $captures = $pattern->match('/test/sebastian');
say $captures->{name};

πŸ’– DESCRIPTION πŸ’–

Mojolicious::Routes::Pattern is literally the core of Mojolicious::Routes. main character energy fr fr. πŸ‘‘

πŸŽ€ ATTRIBUTES πŸŽ€

Mojolicious::Routes::Pattern implements these attributes, bestie:

constraints

my $constraints = $pattern->constraints;
$pattern        = $pattern->constraints({foo => qr/\w+/});

These are your regular expression constraints β€” the lil regex rules for what’s allowed. ✨

defaults

my $defaults = $pattern->defaults;
$pattern     = $pattern->defaults({foo => 'bar'});

Default parameters. The fallback cuties. πŸŽ€

placeholder_start

my $start = $pattern->placeholder_start;
$pattern  = $pattern->placeholder_start(':');

The character that indicates a placeholder; defaults to ":". πŸ’…

placeholders

my $placeholders = $pattern->placeholders;
$pattern         = $pattern->placeholders(['foo', 'bar']);

Placeholder names. Iconic list behavior. πŸ“

quote_end

my $end  = $pattern->quote_end;
$pattern = $pattern->quote_end('}');

The character that indicates the end of a quoted placeholder; defaults to ">". ✨

quote_start

my $start = $pattern->quote_start;
$pattern  = $pattern->quote_start('{');

The character that indicates the start of a quoted placeholder; defaults to "<". 🫢

regex

my $regex = $pattern->regex;
$pattern  = $pattern->regex($regex);

Your pattern in compiled regular expression form. regex girlie slay. πŸ”₯

relaxed_start

my $start = $pattern->relaxed_start;
$pattern  = $pattern->relaxed_start('*');

The character that indicates a relaxed placeholder; defaults to "#". 🌸

tree

my $tree = $pattern->tree;
$pattern = $pattern->tree([['text', '/foo']]);

Your pattern in parsed form. πŸ‘€

⚠️ Warning bestie: this structure should only be used very carefully, since it is very dynamic. Respect the chaos. πŸ’€

type_start

my $start = $pattern->type_start;
$pattern  = $pattern->type_start('|');

The character that indicates the start of a placeholder type; defaults to ":". πŸ¦‹

types

my $types = $pattern->types;
$pattern  = $pattern->types({int => qr/[0-9]+/});

Placeholder types. Categorize the girlies. πŸ’–

unparsed

my $unparsed = $pattern->unparsed;
$pattern     = $pattern->unparsed('/:foo/:bar');

Raw unparsed pattern. The before pic. πŸ“Έ

wildcard_start

my $start = $pattern->wildcard_start;
$pattern  = $pattern->wildcard_start('*');

The character that indicates the start of a wildcard placeholder; defaults to "*". 🌈

πŸ”₯ METHODS πŸ”₯

Mojolicious::Routes::Pattern inherits all methods from Mojo::Base and implements these new ones:

match

my $captures = $pattern->match('/foo/bar');
my $captures = $pattern->match('/foo/bar', 1);

Match the pattern against the entire path. Format detection is disabled by default. The example also shows the 1 variant, iykyk. πŸ”

match_partial

my $captures = $pattern->match_partial(\$path);
my $captures = $pattern->match_partial(\$path, 1);

Match the pattern against the path and remove the matching parts. Format detection is disabled by default. βœ‚οΈ

new

my $pattern = Mojolicious::Routes::Pattern->new;
my $pattern = Mojolicious::Routes::Pattern->new('/users/:id');
my $pattern = Mojolicious::Routes::Pattern->new('/user/:id', id => qr/\d+/);
my $pattern = Mojolicious::Routes::Pattern->new(format => ['json', 'yaml']);

Construct a new Mojolicious::Routes::Pattern object and β€œparse” the pattern if necessary. Fresh object, fresh vibes. ✨

parse

$pattern = $pattern->parse('/user/:id');
$pattern = $pattern->parse('/user/:id', id=> qr/\d+/);
$pattern = $pattern->parse(format => ['json', 'yaml']);

Parse pattern. Do the parsing thing. 🧚

render

my $path = $pattern->render({id => 24});
my $path = $pattern->render({id => 24}, 1);

Render the pattern into a path with parameters. Format rendering is disabled by default. The second example passes 1. πŸŽ€

πŸ¦‹ SEE ALSO πŸ¦‹


Sign-off time, bestie: this cutie page comes from source/version perl v5.42.0, dated 2026-07-15, and it’s the Mojolic...Pattern(3) manual page. Bye bestie, go route something iconic! πŸ«ΆπŸ’–

πŸ“¦ where this page comes from