1HTTP::CookieMonster::CoUoskeire(C3o)ntributed Perl DocumHeTnTtPa:t:iCoonokieMonster::Cookie(3)
2
3
4
6 HTTP::CookieMonster::Cookie - Cookie representation used by
7 HTTP::CookieMonster
8
10 version 0.11
11
13 use HTTP::CookieMonster::Cookie;
14 my $cookie = HTTP::CookieMonster::Cookie->new(
15 key => 'cookie-name',
16 val => 'cookie-val',
17 path => '/',
18 domain => '.somedomain.org',
19 path_spec => 1,
20 secure => 0,
21 expires => 1376081877
22 );
23
24 use WWW::Mechanize;
25 use HTTP::CookieMonster;
26
27 my $mech = WWW::Mechanize->new;
28 my $monster = HTTP::CookieMonster->new( cookie_jar => $mech->cookie_jar );
29 $monster->set_cookie( $cookie );
30
31 $mech->get('https://example.com'); # passes $cookie in request
32
34 This module is intended to be used by HTTP::CookieMonster to represent
35 cookies found in an HTTP::Cookies cookie_jar. To keep things familiar,
36 I have chosen method names which reflect the positional parameter names
37 laid out in the $cookie_jar->scan( \&callback ) documentation.
38
39 Not being intimately familiar with the HTTP cookie spec, I haven't
40 forced validation or default values on any attributes, so please be
41 aware that the burden is on the user to provide "correct" data if you
42 are using this module directly.
43
44 I have provided some sample values below. To get a better idea of what
45 is required, try visiting a few sites and dumping their cookies.
46
47 use Data::Printer;
48 my $mech = WWW::Mechanize->new;
49 $mech->get( 'http://www.google.ca' );
50 my $monster = HTTP::CookieMonster->new( cookie_jar => $mech->cookie_jar );
51 p $monster->all_cookies;
52
53 version
54 $cookie->version( 0 );
55
56 key
57 The name of the cookie.
58
59 $cookie->key( "session_id" );
60
61 val
62 The value of the cookie.
63
64 $cookie->val( "random_stuff" );
65
66 If you are creating a new cookie, you should escape the value first.
67
68 use URI::Escape qw( uri_escape );
69 $cookie->value( uri_escape( 'random_stuff' ) );
70
71 path
72 $cookie->path( "/" );
73
74 domain
75 $cookie->domain( ".google.ca" );
76
77 port
78 path_spec
79 $cookie->path_spec( 1 );
80
81 secure
82 $cookie->secure( 1 );
83
84 expires
85 $cookie->expires( 1407696193 );
86
87 discard
88 hash
89 $cookie->hash( { HttpOnly => undef } );
90
92 This is mainly useful for creating cookies to be used by LWP::UserAgent
93 and WWW::Mechanize classes. If you need to create cookies to set via
94 headers, have a look at Cookie::Baker.
95
97 Olaf Alders <olaf@wundercounter.com>
98
100 This software is copyright (c) 2012 by Olaf Alders.
101
102 This is free software; you can redistribute it and/or modify it under
103 the same terms as the Perl 5 programming language system itself.
104
105
106
107perl v5.38.0 2023-07-20 HTTP::CookieMonster::Cookie(3)