Cookie::Baker(3pm)
okay bestie, welcome to Cookie::Baker(3pm) from the User Contributed Perl Documentation β it's the little module that bakes cookie strings for HTTP responses and crushes cookie strings back into a hashref. it's giving tiny-but-iconic, no cap. πͺβ¨
πΈ NAME πΈ
Cookie::Baker β cookie string generator / parser. that's literally the whole name vibe. π
β¨ SYNOPSIS β¨
use Cookie::Baker;
$headers->push_header('Set-Cookie', bake_cookie($key,$val));
my $cookies_hashref = crush_cookie($headers->header('Cookie'));
π¦ DESCRIPTION π¦
Cookie::Baker provides simple cookie string generator and parser. lowkey does exactly what it says on the tin. π
π₯ XS IMPLEMENTATION π₯
This module tries to use Cookie::Baker::XS's crush_cookie by default. If this fails, it will use Cookie::Baker's pure Perl crush_cookie.
There is no XS implementation of bake_cookie yet. periodt. π
π FUNCTION π
π bake_cookie π
my $cookie = bake_cookie('foo','val');
my $cookie = bake_cookie('foo', {
value => 'val',
path => "test",
domain => '.example.com',
expires => '+24h'
} );
Generates a cookie string for an HTTP response header. The first argument is the cookie's name and the second argument is a plain string or hash reference that can contain keys such as "value", "domain", "expires", "path", "httponly", "secure", "max-age", "samesite". π
value
Cookie's value. simple, iconic, does what it says. π
domain
Cookie's domain. π
partitioned
If true, sets Partitioned flag, and also enforces secure, SameSite=None. false by default. this is the Cookies Having Independent Partitioned State specification: <https://www.ietf.org/archive/id/draft-cutler-httpbis-partitioned-cookies-00.html> πͺ
expires
Cookie's expires date time. Several formats are supported:
expires => time + 24 * 60 * 60 # epoch time
expires => 'Wed, 03-Nov-2010 20:54:16 GMT'
expires => '+30s' # 30 seconds from now
expires => '+10m' # ten minutes from now
expires => '+1h' # one hour from now
expires => '-1d' # yesterday (i.e. "ASAP!")
expires => '+3M' # in three months
expires => '+10y' # in ten years time (60*60*24*365*10 seconds)
expires => 'now' #immediately
-1d being "yesterday" and also "(i.e. "ASAP!")" is genuinely sending me π
max-age
If defined, sets the max-age for the cookie. π
path
Cookie's path.
httponly
If true, sets HttpOnly flag. false by default. π‘οΈ
secure
If true, sets secure flag. false by default. π
samesite
If defined as 'lax' or 'strict' or 'none' (case-insensitive), sets the SameSite restriction for the cookie as described in the draft proposal <https://tools.ietf.org/html/draft-west-first-party-cookies-07>, which is already implemented in Chrome (v51), Safari (v12), Edge (v16), Opera (v38) and Firefox (v60). π
π§ crush_cookie π§
Parses cookie string and returns a hashref.
my $cookies_hashref = crush_cookie($headers->header('Cookie'));
my $cookie_value = $cookies_hashref->{cookie_name}
π SEE ALSO π
CPAN already has many cookie related modules. But there is no simple cookie string generator and parser module.
the see-also squad: CGI, CGI::Simple, Plack, Dancer::Cookie. π
π LICENSE π
Copyright (C) Masahiro Nagano.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. π«Ά
π AUTHOR π
Masahiro Nagano <kazeburo@gmail.com> β icon behavior. β¨
π okay that's the whole Cookie::Baker(3pm) situation β signing off from the perl v5.42.0 docs, dated 2024-03-08. bye bestie, go slay those cookies (the HTTP kind)! π
πͺβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Cookie-Baker 0.120.0-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms