xref: /openbsd-src/gnu/usr.bin/perl/cpan/HTTP-Tiny/t/SimpleCookieJar.pm (revision 5759b3d249badf144a6240f7eec4dcf9df003e6b)
1*5759b3d2Safresh1package SimpleCookieJar;
26fb12b70Safresh1
36fb12b70Safresh1use strict;
46fb12b70Safresh1use warnings;
56fb12b70Safresh1
66fb12b70Safresh1sub new {
76fb12b70Safresh1    my $class = shift;
86fb12b70Safresh1    return bless {} => $class;
96fb12b70Safresh1}
106fb12b70Safresh1
116fb12b70Safresh1sub add {
126fb12b70Safresh1    my ($self, $url, $cookie) = @_;
136fb12b70Safresh1
146fb12b70Safresh1    my ($kv) = split qr/;/, $cookie;
156fb12b70Safresh1    my ($k, $v) = split qr/\s*=\s*/, $kv, 2;
166fb12b70Safresh1
176fb12b70Safresh1    $self->{$url}{$k} = $v;
186fb12b70Safresh1}
196fb12b70Safresh1
206fb12b70Safresh1sub cookie_header {
216fb12b70Safresh1    my ($self, $url) = @_;
226fb12b70Safresh1
236fb12b70Safresh1    my $cookies = $self->{$url}
246fb12b70Safresh1        or return '';
256fb12b70Safresh1
266fb12b70Safresh1    return join( "; ", map{ "$_=$cookies->{$_}" } sort keys %$cookies );
276fb12b70Safresh1}
286fb12b70Safresh1
296fb12b70Safresh11;
30