Mojo::Cookie(3)
π Mojo::Cookie β the HTTP cookie base class, bestie π
Okay so welcome to Mojo::Cookie(3), a page from the User Contributed Perl Documentation β yes it's a real manual page, and yes it's actually kind of iconic once you get what it's doing. Grab a snack π, this one's short and sweet.
β¨ NAME β¨
Mojo::Cookie β the HTTP cookie base class. That's it, that's the whole vibe. It's the parent class, the blueprint, the main character that other cookie classes inherit their whole personality from. π
π SYNOPSIS π
Here's how you actually use it β you make your own subclass and you fill in the blanks:
package Mojo::Cookie::MyCookie;
use Mojo::Base 'Mojo::Cookie';
sub parse {...}
sub to_string {...}
Not me leaving the method bodies as {...} π β that's literally the point though, you're supposed to write them.
π¦ DESCRIPTION π¦
So Mojo::Cookie is an abstract base class for HTTP cookie containers. It's based on [RFC 6265](https://tools.ietf.org/html/rfc6265) (the cookie bible, no cap πͺ), and the actual usable classes you'll be touching are like Mojo::Cookie::Request and Mojo::Cookie::Response.
Think of it as the vibe check that all cookie containers have to pass before they get to exist. You don't instantiate this one directly β you subclass it. π
πΈ ATTRIBUTES πΈ
Mojo::Cookie implements the following attributes β here's the whole list, all two of them:
π name
my $name = $cookie->name;
$cookie = $cookie->name('foo');
The cookie's name. Getter, setter, the classic Mojo double-duty situation. Chain it, love it, live it. π«Ά
π value
my $value = $cookie->value;
$cookie = $cookie->value('/test');
The cookie's value. Same deal β read it with no args, set it by passing something in. Note the example value is literally '/test' there, so yes, paths are perfectly valid values, don't overthink it. β¨
β METHODS β
Mojo::Cookie inherits all methods from Mojo::Base (so you get all that free Mojo goodness for nothing, we love inherited behaviour) and implements the following new ones.
π§ parse
my $cookies = $cookie->parse($str);
Parses cookies. This one is meant to be overloaded in a subclass β so if you call it on the base class expecting magic, that's a you problem, bestie. Override it. π
π§ to_string
my $str = $cookie->to_string;
Renders the cookie into a string. Also meant to be overloaded in a subclass. Same energy, opposite direction: this is where you turn your cookie object back into something you can actually send. π₯
π OPERATORS π
Mojo::Cookie overloads the following operators β yes, actual Perl operator overloading, she's fancy like that. π
π bool
my $bool = !!$cookie;
Always true. Every Mojo::Cookie object is truthy. No falsy cookies, no empty-vibe objects, periodt. π
π stringify
my $str = "$cookie";
An alias for "to_string". So when you shove a cookie into a string, it just quietly calls to_string behind the scenes. Sneaky, elegant, iconic. β¨
π SEE ALSO π
Go deeper, bestie β the whole ecosystem is right there:
MojoliciousMojolicious::Guides- <https://mojolicious.org>
π Real talk: this is an abstract base class, so don't go instantiating it and expectingparse/to_stringto do anything. Subclass it like the SYNOPSIS shows, or useMojo::Cookie::Request/Mojo::Cookie::Response. That's the whole assignment, no cap.
And that's the page! π Big shoutout to the footer crew: it's perl v5.42.0, dated 2026-07-15, brought to you by the User Contributed Perl Documentation squad, filed under Mojo::Cookie(3). Love that for them. π«Άπ
π¦ 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