Mojo::U...okieJar(3)
π Mojo::UserAgent::CookieJar β the manual, but make it cute
okay so bestie, pull up a chair π this is Mojo::UserAgent::CookieJar, aka the actual manual name of this page, and it's the cookie jar for HTTP user agents. yes, a cookie jar. for your HTTP user agent. she's iconic for that π
β¨ SYNOPSIS β¨
here's the whole vibe in code, fr fr β no notes needed:
use Mojo::UserAgent::CookieJar;
# Add response cookies
my $jar = Mojo::UserAgent::CookieJar->new;
$jar->add(
Mojo::Cookie::Response->new(
name => 'foo',
value => 'bar',
domain => 'localhost',
path => '/test'
)
);
# Find request cookies
for my $cookie (@{$jar->find(Mojo::URL->new('http://localhost/test'))}) {
say $cookie->name;
say $cookie->value;
}
like, add response cookies, find request cookies. the duality of cookie πͺβ¨
πΈ DESCRIPTION πΈ
Mojo::UserAgent::CookieJar is a minimalistic and relaxed cookie jar used by Mojo::UserAgent, and it's based on RFC 6265 <https://tools.ietf.org/html/rfc6265> π¦ yes she cites her sources, we stan.
lowkey she's chill, highkey she's correct. the way that she's minimalistic and relaxed? main character energy honestly π
π ATTRIBUTES π
Mojo::UserAgent::CookieJar implements the following attributes. let's go π«Ά
π file
my $file = $jar->file;
$jar = $jar->file('/home/sri/cookies.txt');
this is the file you "load" cookies from and "save" cookies to, in Netscape format. yes, Netscape format. she's vintage π
# Save cookies to file
$jar->file('cookies.txt')->save;
# Empty cookie jar and load cookies from file
$jar->file('cookies.txt')->empty->load;
look at that chaining. empty then load. chef's kiss π
π¦ ignore
my $ignore = $jar->ignore;
$jar = $jar->ignore(sub {...});
a callback that decides whether a cookie should be ignored by "collect" β very much a vibe check for cookies if you think about it β
# Ignore all cookies
$jar->ignore(sub { 1 });
# Ignore cookies for domains "com", "net" and "org"
$jar->ignore(sub ($cookie) {
return undef unless my $domain = $cookie->domain;
return $domain eq 'com' || $domain eq 'net' || $domain eq 'org';
});
not her rejecting the entire com, net and org domains π honestly fair.
π max_cookie_size
my $size = $jar->max_cookie_size;
$jar = $jar->max_cookie_size(4096);
maximum cookie size in bytes, and it defaults to 4096 (that's 4KiB bestie π§). size matters, she's just setting boundaries periodt.
π METHODS π
Mojo::UserAgent::CookieJar inherits all methods from Mojo::Base and implements the following new ones. slay, let's get into it π
π₯ add
$jar = $jar->add(@cookies);
add multiple Mojo::Cookie::Response objects to the jar. multiple. she's a collector.
π all
my $cookies = $jar->all;
return all Mojo::Cookie::Response objects that are currently stored in the jar. yes, all of them, no crumbs left behind πͺ
# Names of all cookies
say $_->name for @{$jar->all};
β¨ collect
$jar->collect(Mojo::Transaction::HTTP->new);
collect response cookies from transaction. go little cookie, go get collected π¦
π empty
$jar = $jar->empty;
empty the jar. she's empty. she's cleansed. she's at peace πΈ
β find
my $cookies = $jar->find(Mojo::URL->new);
find Mojo::Cookie::Request objects in the jar for a Mojo::URL object. a little scavenger hunt, but make it HTTP π
# Names of all cookies found
say $_->name for @{$jar->find(Mojo::URL->new('http://example.com/foo'))};
π load
$jar = $jar->load;
load cookies from "file". that's it, that's the method π
π«Ά prepare
$jar->prepare(Mojo::Transaction::HTTP->new);
prepare request cookies for transaction. getting them ready, doing their makeup, sending them out π
π§ save
$jar = $jar->save;
save cookies to "file". persistence queen π
π to_string
my $string = $jar->to_string;
stringify cookies in Netscape format. turn the whole jar into one string, iykyk β¨
lowkey a reminder bestie:file,ignoreandmax_cookie_sizeare attributes, andload/saveliterally read and write that"file"β so don't be weird about it π
πΈ SEE ALSO πΈ
MojoliciousMojolicious::Guides- <https://mojolicious.org>
okay that's the whole page π perl v5.42.0, dated 2026-07-15 β and that's genuinely the source/version and date, bestie, so now you can't say I never told you anything ππ bye, go set some cookies πͺβ¨
π¦ 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