| 1 | package Plack::Session::State::Cookie; | ||||||||||||||||||||||||||||
| 2 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 14 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 14 | our $VERSION = '0.36'; | |||||||||||||||||||||||||||
| 6 | 14 | our $AUTHORITY = 'cpan:STEVAN'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 14 | ▶ | use parent 'Plack::Session::State'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 14 | ▶ | use Cookie::Baker; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 14 | ▶ | use Plack::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 14 | ▶ | use Plack::Util::Accessor qw[ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | path | ||||||||||||||||||||||||||||
| 14 | domain | ||||||||||||||||||||||||||||
| 15 | expires | ||||||||||||||||||||||||||||
| 16 | secure | ||||||||||||||||||||||||||||
| 17 | httponly | ||||||||||||||||||||||||||||
| 18 | samesite | ||||||||||||||||||||||||||||
| 19 | partitioned | ||||||||||||||||||||||||||||
| 20 | 14 | ]; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 28 | ▶ | sub get_session_id { | ||||||||||||||||||||||||||
|
Subroutine
get_session_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 28 | my ($self, $env) = @_; | |||||||||||||||||||||||||||
| 24 | 28 | crush_cookie($env->{HTTP_COOKIE})->{$self->session_key}; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 33 | ▶ | sub merge_options { | ||||||||||||||||||||||||||
|
Subroutine
merge_options: called CC=16 SCAR=27.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | 33 | my($self, %options) = @_; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 33 | delete $options{id}; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 33 | ▶ | $options{path} = $self->path || '/' if !exists $options{path}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->path || '/'
MC/DC100%1/1
$self->path || '/'
$self->path
Truth table100%2/2
A
A= $self->path
| |||||||||||||||||||||||||||||
| 33 | 33 | ▶ | $options{domain} = $self->domain if !exists $options{domain} && defined $self->domain; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $options{"domain"} and defined $self->domain
MC/DC100%2/2
not exists $options{"domain"} and defined $self->domain
not exists $options{"domain"}
defined $self->domain
Truth table100%3/3
not(A) and B
A= not exists $options{"domain"}B= defined $self->domain
| |||||||||||||||||||||||||||||
| 34 | 33 | ▶ | $options{secure} = $self->secure if !exists $options{secure} && defined $self->secure; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $options{"secure"} and defined $self->secure
MC/DC100%2/2
not exists $options{"secure"} and defined $self->secure
not exists $options{"secure"}
defined $self->secure
Truth table100%3/3
not(A) and B
A= not exists $options{"secure"}B= defined $self->secure
| |||||||||||||||||||||||||||||
| 35 | 33 | ▶ | $options{httponly} = $self->httponly if !exists $options{httponly} && defined $self->httponly; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not exists $options{"httponly"} and defined $self->httponly
MC/DC50%1/2
not exists $options{"httponly"} and defined $self->httponly
not exists $options{"httponly"}
defined $self->httponly
Truth table66%2/3
not(A) and B
A= not exists $options{"httponly"}B= defined $self->httponly
| |||||||||||||||||||||||||||||
| 36 | 33 | ▶ | $options{samesite} = $self->samesite if !exists $options{samesite} && defined $self->samesite; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not exists $options{"samesite"} and defined $self->samesite
MC/DC50%1/2
not exists $options{"samesite"} and defined $self->samesite
not exists $options{"samesite"}
defined $self->samesite
Truth table66%2/3
not(A) and B
A= not exists $options{"samesite"}B= defined $self->samesite
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # https://developer.mozilla.org/en-US/docs/Web/Privacy/Privacy_sandbox/Partitioned_cookies | ||||||||||||||||||||||||||||
| 39 | 33 | ▶ | $options{partitioned} = $self->partitioned if !exists $options{partitioned} && defined $self->partitioned; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $options{"partitioned"} and defined $self->partitioned
MC/DC100%2/2
not exists $options{"partitioned"} and defined $self->partitioned
not exists $options{"partitioned"}
defined $self->partitioned
Truth table100%3/3
not(A) and B
A= not exists $options{"partitioned"}B= defined $self->partitioned
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 33 | ▶ | if (!exists $options{expires} && defined $self->expires) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $options{"expires"} and defined $self->expires
MC/DC100%2/2
not exists $options{"expires"} and defined $self->expires
not exists $options{"expires"}
defined $self->expires
Truth table100%3/3
not(A) and B
A= not exists $options{"expires"}B= defined $self->expires
| |||||||||||||||||||||||||||||
| 43 | 2 | $options{expires} = time + $self->expires; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 33 | ▶ | if ($options{partitioned}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 4 | $options{secure} = 1; | |||||||||||||||||||||||||||
| 48 | 4 | $options{samesite} = 'None'; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 33 | return %options; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | ▶ | sub expire_session_id { | ||||||||||||||||||||||||||
|
Subroutine
expire_session_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 2 | my ($self, $id, $res, $options) = @_; | |||||||||||||||||||||||||||
| 56 | 2 | my %opts = $self->merge_options(%$options, expires => time); | |||||||||||||||||||||||||||
| 57 | 2 | $self->_set_cookie($id, $res, %opts); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 26 | ▶ | sub finalize { | ||||||||||||||||||||||||||
|
Subroutine
finalize: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 26 | my ($self, $id, $res, $options) = @_; | |||||||||||||||||||||||||||
| 62 | 26 | my %opts = $self->merge_options(%$options); | |||||||||||||||||||||||||||
| 63 | 26 | $self->_set_cookie($id, $res, %opts); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 28 | ▶ | sub _set_cookie { | ||||||||||||||||||||||||||
|
Subroutine
_set_cookie: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 67 | 28 | my($self, $id, $res, %options) = @_; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 28 | my $cookie = bake_cookie( | |||||||||||||||||||||||||||
| 70 | $self->session_key, { | ||||||||||||||||||||||||||||
| 71 | value => $id, | ||||||||||||||||||||||||||||
| 72 | %options, | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||
| 75 | 28 | Plack::Util::header_push($res->[1], 'Set-Cookie', $cookie); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 14 | 1; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | __END__ | ||||||||||||||||||||||||||||