1Cookie::Baker(3pm)    User Contributed Perl Documentation   Cookie::Baker(3pm)
2
3
4

NAME

6       Cookie::Baker - Cookie string generator / parser
7

SYNOPSIS

9           use Cookie::Baker;
10
11           $headers->push_header('Set-Cookie', bake_cookie($key,$val));
12
13           my $cookies_hashref = crush_cookie($headers->header('Cookie'));
14

DESCRIPTION

16       Cookie::Baker provides simple cookie string generator and parser.
17

XS IMPLEMENTATION

19       This module tries to use Cookie::Baker::XS's crush_cookie by default.
20       If this fails, it will use Cookie::Baker's pure Perl crush_cookie.
21
22       There is no XS implementation of bake_cookie yet.
23

FUNCTION

25       bake_cookie
26             my $cookie = bake_cookie('foo','val');
27             my $cookie = bake_cookie('foo', {
28                 value => 'val',
29                 path => "test",
30                 domain => '.example.com',
31                 expires => '+24h'
32             } );
33
34           Generates a cookie string for an HTTP response header.  The first
35           argument is the cookie's name and the second argument is a plain
36           string or hash reference that can contain keys such as "value",
37           "domain", "expires", "path", "httponly", "secure", "max-age",
38           "samesite".
39
40           value
41               Cookie's value.
42
43           domain
44               Cookie's domain.
45
46           expires
47               Cookie's expires date time. Several formats are supported:
48
49                 expires => time + 24 * 60 * 60 # epoch time
50                 expires => 'Wed, 03-Nov-2010 20:54:16 GMT'
51                 expires => '+30s' # 30 seconds from now
52                 expires => '+10m' # ten minutes from now
53                 expires => '+1h'  # one hour from now
54                 expires => '-1d'  # yesterday (i.e. "ASAP!")
55                 expires => '+3M'  # in three months
56                 expires => '+10y' # in ten years time (60*60*24*365*10 seconds)
57                 expires => 'now'  #immediately
58
59           max-age
60               If defined, sets the max-age for the cookie.
61
62           path
63               Cookie's path.
64
65           httponly
66               If true, sets HttpOnly flag. false by default.
67
68           secure
69               If true, sets secure flag. false by default.
70
71           samesite
72               If defined as 'lax' or 'strict' (case-insensitive), sets the
73               SameSite restriction for the cookie as described in the draft
74               proposal <https://tools.ietf.org/html/draft-west-first-party-
75               cookies-07>, which is already implemented in Chrome (v51),
76               Opera (v38) and Firefox (v60).
77
78       crush_cookie
79           Parses cookie string and returns a hashref.
80
81               my $cookies_hashref = crush_cookie($headers->header('Cookie'));
82               my $cookie_value = $cookies_hashref->{cookie_name}
83

SEE ALSO

85       CPAN already has many cookie related modules. But there is no simple
86       cookie string generator and parser module.
87
88       CGI, CGI::Simple, Plack, Dancer::Cookie
89

LICENSE

91       Copyright (C) Masahiro Nagano.
92
93       This library is free software; you can redistribute it and/or modify it
94       under the same terms as Perl itself.
95

AUTHOR

97       Masahiro Nagano <kazeburo@gmail.com>
98
99
100
101perl v5.28.1                      2018-09-21                Cookie::Baker(3pm)
Impressum