HTTP::...:Cookie(3pm)

πŸ“¦
version 0.11 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

okay bestie, so this is the Perl doc page for HTTP::...:Cookie(3pm) from the User Contributed Perl Documentation, and we're gonna walk through it together. grab a snack, it's giving cookie lore. πŸŽ€


✨ NAME ✨

HTTP::CookieMonster::Cookie β€” the cookie representation that HTTP::CookieMonster uses, periodt. πŸͺ

🌸 VERSION 🌸

version 0.11 β€” yeah she's on 0.11, keep up πŸ’…

πŸ¦‹ SYNOPSIS πŸ¦‹

okay so here's the whole vibe in code, literally verbatim, don't touch:

use HTTP::CookieMonster::Cookie;
my $cookie = HTTP::CookieMonster::Cookie->new(
    key       => 'cookie-name',
    val       => 'cookie-val',
    path      => '/',
    domain    => '.somedomain.org',
    path_spec => 1,
    secure    => 0,
    expires   => 1376081877
);

use WWW::Mechanize;
use HTTP::CookieMonster;

my $mech = WWW::Mechanize->new;
my $monster = HTTP::CookieMonster->new( cookie_jar => $mech->cookie_jar );
$monster->set_cookie( $cookie );

$mech->get('https://example.com');    # passes $cookie in request

so you make a cookie, you hand it to the monster, the monster stuffs it in mechanize's cookie jar, and then the request just… carries it. no cap. ✨

πŸ’œ DESCRIPTION πŸ’œ

so the whole point of this module is that HTTP::CookieMonster uses it to represent the cookies it finds chilling in an HTTP::Cookies cookie_jar. and to keep things familiar β€” because who wants to learn a whole new vocabulary β€” the method names were deliberately chosen to mirror the positional parameter names laid out in the $cookie_jar->scan( \&callback ) documentation. iykyk. 🫢

real talk though: being not intimately familiar with the HTTP cookie spec, the author did not force any validation or default values onto any of the attributes. so please be aware β€” the burden is on you, the user, to provide "correct" data if you're using this module directly. it's giving trust falls. πŸ™ˆ

there are some sample values below, but if you want a better idea of what's actually required? try visiting a few sites and dumping their cookies. field research, bestie. πŸ”₯

use Data::Printer;
my $mech = WWW::Mechanize->new;
$mech->get( 'http://www.google.ca' );
my $monster = HTTP::CookieMonster->new( cookie_jar => $mech->cookie_jar );
p $monster->all_cookies;

⭐ version ⭐

$cookie->version( 0 );

πŸ“ key πŸ“

The name of the cookie. that's it, that's the whole job.

$cookie->key( "session_id" );

🧚 val 🧚

The value of the cookie. iconic.

$cookie->val( "random_stuff" );

If you are creating a new cookie, you should escape the value first. do not skip this step bestie, it's for your own good πŸ’…

use URI::Escape qw( uri_escape );
$cookie->value( uri_escape( 'random_stuff' ) );

🌈 path 🌈

$cookie->path( "/" );

πŸ’– domain πŸ’–

$cookie->domain( ".google.ca" );

🌸 port 🌸

(yes, she exists. that's the whole note. slay.)

πŸŽ€ path_spec πŸŽ€

$cookie->path_spec( 1 );

πŸ’… secure πŸ’…

$cookie->secure( 1 );

πŸ”₯ expires πŸ”₯

$cookie->expires( 1407696193 );

πŸ’€ discard πŸ’€

(also just vibing here on her own. no example given, no example needed.)

πŸ‘‘ hash πŸ‘‘

$cookie->hash( { HttpOnly => undef } );

πŸ¦‹ SEE ALSO πŸ¦‹

This is mainly useful for creating cookies to be used by LWP::UserAgent and WWW::Mechanize classes. If you need to create cookies to set via headers, have a look at Cookie::Baker. go give them a lil visit 🫢

✨ AUTHOR ✨

Olaf Alders <olaf@wundercounter.com> β€” thank you king πŸ‘‘

This software is copyright (c) 2012 by Olaf Alders.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. free as in freedom, bestie πŸ•ŠοΈ


and that's the whole page, no notes. πŸ’–

so this doc was rendered up by perl v5.36.0 on 2022-10-14, and it lives in the HTTP::...:Cookie(3pm) manual page from the User Contributed Perl Documentation. mwah, slay, go forth and cookie responsibly πŸͺβœ¨πŸ’…

πŸ“¦ where this page comes from