| 1 | package Kelp::Test::CookieJar; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 31 | ▶ | use Kelp::Base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 31 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # Stripped-down HTTP::Cookies interface for testing purposes and proper url escaping | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 32 | ▶ | attr cookies => sub { {} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | sub set_cookie | ||||||||||||||||||||||||||||
| 11 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_cookie: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 2 | my ($self, undef, $name, $value) = @_; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | $self->cookies->{$name} = $value; | |||||||||||||||||||||||||||
| 15 | 2 | return 1; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub get_cookies | ||||||||||||||||||||||||||||
| 19 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_cookies: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | 1 | my ($self, undef, @names) = @_; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | my %ret; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | if (@names) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | return $self->cookies->{$names[0]} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | unless wantarray; | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 1 | return map { $self->cookies->{$_} } @names; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | else { | ||||||||||||||||||||||||||||
| 31 | 0 | return $self->cookies; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub clear | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
clear: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | 0 | my ($self, undef, undef, $name) = @_; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ($name) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 0 | delete $self->cookies->{$name}; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | else { | ||||||||||||||||||||||||||||
| 43 | 0 | %{$self->cookies} = (); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | return $self; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub add_cookie_header | ||||||||||||||||||||||||||||
| 50 | 255 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
add_cookie_header: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 255 | my ($self, $request) = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 255 | my %c = %{$self->cookies}; | |||||||||||||||||||||||||||
| 54 | 255 | my @vals = map { uri_escape($_) . '=' . uri_escape($c{$_}) } keys %c; | |||||||||||||||||||||||||||
| 55 | 255 | $request->header(Cookie => join '; ', @vals); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 255 | return $request; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | sub extract_cookies | ||||||||||||||||||||||||||||
| 61 | 255 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
extract_cookies: called CC=5 SCAR=16.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 62 | 255 | my ($self, $response) = @_; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 255 | ▶ | my @headers = split ', ', $response->header('Set-Cookie') // ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$response->header("Set-Cookie") // ""
MC/DC100%1/1
$response->header("Set-Cookie") // ""
$response->header("Set-Cookie")
Truth table100%2/2
A
A= $response->header("Set-Cookie")
| |||||||||||||||||||||||||||||
| 65 | 255 | foreach my $header (@headers) { | |||||||||||||||||||||||||||
| 66 | 1 | my $cookie = (split /; /, $header)[0]; | |||||||||||||||||||||||||||
| 67 | 1 | my ($name, $value) = split '=', $cookie; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | ▶ | next unless defined $name && defined $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $name and defined $value
MC/DC0%0/2
defined $name and defined $value
defined $name
defined $value
Truth table33%1/3
A and B
A= defined $nameB= defined $value
| |||||||||||||||||||||||||||||
| 70 | 1 | $self->set_cookie(undef, uri_unescape($name), uri_unescape($value)); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 255 | return $response; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 31 | 1; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||