Session/State/Cookie.pm

filter: Statementstmt 98.1% 54 / 55 Branchbran 92.3% 24 / 26 Conditioncond 100% 7 / 7 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 10 / 10 Podpod 100% 4 / 4 totaltotal 97.1% 103 / 106 CC 17 SCAR 13.3
CC
17
Cov
97%
__ANON__
6.0
get_session_id
5.0
new
4.1
CRAP 3.8
« Session.pm ↑ Summary Session/Store/CHI.pm »
1 package HTTP::Session::State::Cookie;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use HTTP::Session::State::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 our $COOKIE_CLASS = 'CGI::Cookie';
8  
9 4 __PACKAGE__->mk_accessors(qw/name path domain expires secure samesite httponly/);
10  
11 {
12 4 my $required = 0;
13 49 ▶ sub _cookie_class {
Subroutine _cookie_class: called CC=2 SCAR=6.9
14 49 my $class = shift;
15 49 ▶ unless ($required) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($required) 4 45 49
16 4 (my $klass = $COOKIE_CLASS) =~ s!::!/!g;
17 4 $klass .= ".pm";
18 4 require $klass;
19 4 $required++;
20 }
21 49 return $COOKIE_CLASS
22 }
23 }
24  
25 4 ▶sub new {
Subroutine new: called CC=4 SCAR=14.0
Pod documented
26 30 my $class = shift;
27 0 ▶ my %args = ref($_[0]) ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 30 30
28 # set default values
29 30 ▶ $args{name} ||= 'http_session_sid';
Condition100%2/2
$args{"name"} ||= "http_session_sid"
l!l
1614
MC/DC100%1/1
$args{"name"} ||= "http_session_sid"
$args{"name"}
Truth table100%2/2
A
A= $args{"name"}
Aresult
11
00
30 30 ▶ $args{path} ||= '/';
Condition100%2/2
$args{"path"} ||= "/"
l!l
426
MC/DC100%1/1
$args{"path"} ||= "/"
$args{"path"}
Truth table100%2/2
A
A= $args{"path"}
Aresult
11
00
31 30 bless {%args}, $class;
32 }
33  
34 30 ▶sub get_session_id {
Subroutine get_session_id: called CC=5 SCAR=16.1
Pod documented
35 30 my ($self, $req) = @_;
36  
37 30 ▶ my $cookie_header = $ENV{HTTP_COOKIE} || (Scalar::Util::blessed($req) ? $req->header('Cookie') : $req->{HTTP_COOKIE});
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($req) ? : 7 1 8
Condition100%3/3
$ENV{'HTTP_COOKIE'} || (builtin::blessed($req) ? $req->header('Cookie') : $req->{'HTTP_COOKIE'})
l!l&&r!l&&!r
2262
MC/DC100%2/2
$ENV{'HTTP_COOKIE'} || (builtin::blessed($req) ? $req->header('Cookie') : $req->{'HTTP_COOKIE'})
$ENV{'HTTP_COOKIE'} (builtin::blessed($req) ? $req->header('Cookie') : $req->{'HTTP_COOKIE'})
Truth table100%3/3
A || B
A= $ENV{'HTTP_COOKIE'}B= (builtin::blessed($req) ? $req->header('Cookie') : $req->{'HTTP_COOKIE'})
ABresult
1X1
011
000
38 30 ▶ return unless $cookie_header;
Branch: 1 branch
BranchTrueFalseTotal
unless $cookie_header 2 28 30
39  
40 28 my %jar = _cookie_class()->parse($cookie_header);
41 28 my $cookie = $jar{$self->name};
42 28 ▶ return $cookie ? $cookie->value : undef;
Branch: 1 branch
BranchTrueFalseTotal
$cookie ? : 21 7 28
43 }
44  
45 21 ▶sub response_filter {
Subroutine response_filter: called CC=2 SCAR=6.9
Pod documented
46 21 my ($self, $session_id, $res) = @_;
47 21 ▶ Carp::croak "missing session_id" unless $session_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $session_id 2 19 21
48  
49 19 $self->header_filter($session_id, $res);
50 }
51  
52 21 ▶sub header_filter {
Subroutine header_filter: called CC=3 SCAR=11.0
Pod documented
53 21 my ($self, $session_id, $res) = @_;
54 21 ▶ Carp::croak "missing session_id" unless $session_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $session_id 0 21 21
55  
56 my $cookie = _cookie_class()->new(
57 21 ▶ sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
58 21 my %options = (
59 -name => $self->name,
60 -value => $session_id,
61 -path => $self->path,
62 );
63 21 ▶ $options{'-domain'} = $self->domain if $self->domain;
Branch: 1 branch
BranchTrueFalseTotal
if $self->domain 4 17 21
64 21 ▶ $options{'-expires'} = $self->expires if $self->expires;
Branch: 1 branch
BranchTrueFalseTotal
if $self->expires 4 17 21
65 21 ▶ $options{'-secure'} = $self->secure if $self->secure;
Branch: 1 branch
BranchTrueFalseTotal
if $self->secure 4 17 21
66 21 ▶ $options{'-samesite'} = $self->samesite if $self->samesite;
Branch: 1 branch
BranchTrueFalseTotal
if $self->samesite 6 15 21
67 21 ▶ $options{'-httponly'} = $self->httponly if $self->httponly;
Branch: 1 branch
BranchTrueFalseTotal
if $self->httponly 2 19 21
68 21 %options;
69 21 }->()
70 );
71 21 ▶ if (Scalar::Util::blessed($res)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($res)) { } 20 1 21
72 20 $res->header( 'Set-Cookie' => $cookie->as_string );
73 20 $res;
74 } else {
75 1 push @{$res->[1]}, 'Set-Cookie' => $cookie->as_string;
76 1 $res;
77 }
78 }
79  
80 4 1;
81 __END__
« Session.pm ↑ Summary Session/Store/CHI.pm »