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:
MojoliciousMojolicious::Guides- <https://mojolicious.org>
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
- 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