Session/State/Cookie.pm

filter: Statementstmt 100% 46 / 46 Branchbran 100% 16 / 16 Conditioncond 90.0% 18 / 20 MC/DCmcdc 84.6% 11 / 13 Subroutinesub 100% 11 / 11 Podpod 75.0% 3 / 4 totaltotal 95.4% 105 / 110 CC 16 SCAR 23.3
CC
16
Cov
98%
merge_options
16.0
BEGIN
1.0
BEGIN
1.0
CRAP 10.2
↑ Summary Session/Store/DBI.pm »
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
BranchTrueFalseTotal
unless exists $options{"path"} 26 7 33
Condition100%2/2
$self->path || '/'
l!l
422
MC/DC100%1/1
$self->path || '/'
$self->path
Truth table100%2/2
A
A= $self->path
Aresult
11
00
33 33 ▶ $options{domain} = $self->domain if !exists $options{domain} && defined $self->domain;
Branch: 1 branch
BranchTrueFalseTotal
if not exists $options{"domain"} and defined $self->domain 4 29 33
Condition100%3/3
not exists $options{"domain"} and defined $self->domain
!ll&&!rl&&r
7224
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
ABresult
0X0
100
111
34 33 ▶ $options{secure} = $self->secure if !exists $options{secure} && defined $self->secure;
Branch: 1 branch
BranchTrueFalseTotal
if not exists $options{"secure"} and defined $self->secure 2 31 33
Condition100%3/3
not exists $options{"secure"} and defined $self->secure
!ll&&!rl&&r
3282
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
ABresult
0X0
100
111
35 33 ▶ $options{httponly} = $self->httponly if !exists $options{httponly} && defined $self->httponly;
Branch: 1 branch
BranchTrueFalseTotal
if not exists $options{"httponly"} and defined $self->httponly 6 27 33
Condition66%2/3
not exists $options{"httponly"} and defined $self->httponly
!ll&&!rl&&r
0276
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
ABresult
0X0
100
111
36 33 ▶ $options{samesite} = $self->samesite if !exists $options{samesite} && defined $self->samesite;
Branch: 1 branch
BranchTrueFalseTotal
if not exists $options{"samesite"} and defined $self->samesite 4 29 33
Condition66%2/3
not exists $options{"samesite"} and defined $self->samesite
!ll&&!rl&&r
0294
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if not exists $options{"partitioned"} and defined $self->partitioned 3 30 33
Condition100%3/3
not exists $options{"partitioned"} and defined $self->partitioned
!ll&&!rl&&r
2283
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
ABresult
0X0
100
111
40  
41  
42 33 ▶ if (!exists $options{expires} && defined $self->expires) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $options{"expires"} and defined $self->expires) 2 31 33
Condition100%3/3
not exists $options{"expires"} and defined $self->expires
!ll&&!rl&&r
5262
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
ABresult
0X0
100
111
43 2 $options{expires} = time + $self->expires;
44 }
45  
46 33 ▶ if ($options{partitioned}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"partitioned"}) 4 29 33
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__
↑ Summary Session/Store/DBI.pm »