Mojolic...ndition(3)

πŸ’… Mojolicious::Plugin::HeaderCondition

okay bestie, so this is a page from the User Contributed Perl Documentation (that's the manual name, iykyk), and honestly? It's a little gem. Let's get into it 🫢


✨ NAME ✨

Mojolicious::Plugin::HeaderCondition β€” the Header condition plugin. Literally what it says on the tin, no cap πŸ’–


πŸ¦‹ SYNOPSIS πŸ¦‹

Here's the whole vibe, in code, exactly as the universe intended:

# Mojolicious
$app->plugin('HeaderCondition');
$app->routes->get('/foo')->requires(headers => {Referer => qr/example\.com/});

# Mojolicious::Lite
plugin 'HeaderCondition';
get '/' => (headers => {Referer => qr/example\.com/}) => sub {...};

# All headers need to match
$app->routes->get('/foo')->requires(headers => {
  'X-Secret-Header' => 'Foo',
  Referer => qr/example\.com/
});

# The "agent" condition is a shortcut for the "User-Agent" header
get '/' => (agent => qr/Firefox/) => sub {...};

# The "host" condition is a shortcut for the detected host
get '/' => (host => qr/mojolicious\.org/) => sub {...};

So iconic of Perl to let you filter routes by header, fr fr 🌸


πŸŽ€ DESCRIPTION πŸŽ€

Mojolicious::Plugin::HeaderCondition is a route condition for header-based routes. That's the whole point of it β€” route matching, but make it header-flavoured πŸ’…

This is a core plugin, which means it is always enabled β€” you don't have to do anything, it's just there, main character energy πŸ‘‘ And the code? It's a good example for learning to build new plugins. The author literally says you're welcome to fork it. So like, go off 🧚

See "PLUGINS" in Mojolicious::Plugins for a list of plugins that are available by default. That's where the whole squad is listed ✨


πŸ’œ METHODS πŸ’œ

Mojolicious::Plugin::HeaderCondition inherits all methods from Mojolicious::Plugin and implements the following new ones. Yes, it got the family traits and then added its own lil' signature move πŸ¦‹

🌈 register

$plugin->register(Mojolicious->new);

Register conditions in Mojolicious application. That's it, that's the method 🫢


⭐ SEE ALSO ⭐

Go give these a read, bestie, they're the whole lore:


ok real talk, don't sleep on the guides β€” they're giving "required reading" πŸ“šπŸ’€

this page was brought to you by perl v5.42.0, dated 2026-07-15, and the User Contributed Perl Documentation crew β€” mwah, love u, bye! πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from