Mojo::Cookie(3)

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:


πŸ’€ Real talk: this is an abstract base class, so don't go instantiating it and expecting parse/to_string to do anything. Subclass it like the SYNOPSIS shows, or use Mojo::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