| 1 | package YATT::Lite::WebMVC0::Partial::Session2; | ||||||||||||||||||||||||||||
| 2 | sub MY () {__PACKAGE__} | ||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings qw(FATAL all NONFATAL misc); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use constant DEBUG => ($ENV{DEBUG_YATT_SESSION2} // 0); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Condition50%1/2
$ENV{"DEBUG_YATT_SESSION2"} // 0
MC/DC0%0/1
$ENV{"DEBUG_YATT_SESSION2"} // 0
$ENV{"DEBUG_YATT_SESSION2"}
Truth table50%1/2
A
A= $ENV{"DEBUG_YATT_SESSION2"}
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use YATT::Lite::Util qw/dputs | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | lexpand | ||||||||||||||||||||||||||||
| 10 | 3 | /; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Plack::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | #======================================== | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # This version of YATT::Lite::WebMVC0::Partial::Session2 directly | ||||||||||||||||||||||||||||
| 17 | # calls *internal* methods of Plack::Middleware::Session. | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use Plack::Middleware::Session; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 3 | ▶ | sub default_session_middleware_class {'Plack::Middleware::Session'} | ||||||||||||||||||||||||||
|
Subroutine
default_session_middleware_class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | #======================================== | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 3 | ▶ | use YATT::Lite::PSGIEnv; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | use YATT::Lite::Partial | ||||||||||||||||||||||||||||
| 27 | 3 | ▶ | (requires => [qw/ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | error | ||||||||||||||||||||||||||||
| 29 | /] | ||||||||||||||||||||||||||||
| 30 | , fields => [qw/ | ||||||||||||||||||||||||||||
| 31 | _session_middleware | ||||||||||||||||||||||||||||
| 32 | session_middleware_class | ||||||||||||||||||||||||||||
| 33 | session_state | ||||||||||||||||||||||||||||
| 34 | session_store | ||||||||||||||||||||||||||||
| 35 | /] | ||||||||||||||||||||||||||||
| 36 | , -Entity, -CON | ||||||||||||||||||||||||||||
| 37 | 3 | ); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | #======================================== | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 6 | ▶ | Entity psgix_session => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 42 | 6 | my ($this, @opts) = @_; | |||||||||||||||||||||||||||
| 43 | 6 | my Env $env = $CON->env; | |||||||||||||||||||||||||||
| 44 | 6 | ▶ | unless ($env->{'psgix.session.options'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 1 | $CON->cget('system')->session_start($CON, @opts); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 6 | $env->{'psgix.session'}; | |||||||||||||||||||||||||||
| 48 | 3 | }; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | Entity psgix_session_or_dummy => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 51 | 0 | my ($this) = @_; | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ($this->entity_session_state_exists) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | $this->entity_psgix_session; | |||||||||||||||||||||||||||
| 54 | } else { | ||||||||||||||||||||||||||||
| 55 | 0 | +{}; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 3 | }; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | Entity psgix_session_options => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 60 | 0 | my ($this) = @_; | |||||||||||||||||||||||||||
| 61 | 0 | my Env $env = $CON->env; | |||||||||||||||||||||||||||
| 62 | 0 | $env->{'psgix.session.options'}; | |||||||||||||||||||||||||||
| 63 | 3 | }; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 10 | ▶ | Entity psgix_session_exists => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 66 | 10 | my ($this) = @_; | |||||||||||||||||||||||||||
| 67 | 10 | my Env $env = $CON->env; | |||||||||||||||||||||||||||
| 68 | defined $env->{'psgix.session.options'} | ||||||||||||||||||||||||||||
| 69 | 10 | ▶ | and $env->{'psgix.session.options'}{'id'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 3 | }; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | #---------------------------------------- | ||||||||||||||||||||||||||||
| 73 | 6 | ▶ | Entity session_start => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 74 | 6 | my ($this, @opts) = @_; | |||||||||||||||||||||||||||
| 75 | 6 | $CON->cget('system')->session_start($CON, @opts); | |||||||||||||||||||||||||||
| 76 | 6 | ""; | |||||||||||||||||||||||||||
| 77 | 3 | }; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 10 | ▶ | Entity session_state_id => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 80 | 10 | my ($this) = @_; | |||||||||||||||||||||||||||
| 81 | 10 | $CON->cget('system')->session_state_extract_id($CON); | |||||||||||||||||||||||||||
| 82 | 3 | }; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 16 | ▶ | Entity session_state_exists => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 85 | 16 | $CON->cget('system')->session_state_exists($CON); | |||||||||||||||||||||||||||
| 86 | 3 | }; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 2 | ▶ | Entity session_change_id => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 89 | 2 | my ($this) = @_; | |||||||||||||||||||||||||||
| 90 | 2 | $CON->cget('system')->session_change_id($CON); | |||||||||||||||||||||||||||
| 91 | 3 | }; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | ▶ | Entity session_expire => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 94 | 1 | my ($this) = @_; | |||||||||||||||||||||||||||
| 95 | 1 | $CON->cget('system')->session_expire($CON); | |||||||||||||||||||||||||||
| 96 | 1 | ""; | |||||||||||||||||||||||||||
| 97 | 3 | }; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | Entity session_middleware => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 100 | 0 | my ($this) = @_; | |||||||||||||||||||||||||||
| 101 | 0 | my MY $self = $CON->cget('system'); | |||||||||||||||||||||||||||
| 102 | 0 | ▶ | my $mw = $self->{_session_middleware} or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | Carp::croak("Session middleware is not initialized!"); | |||||||||||||||||||||||||||
| 104 | }; | ||||||||||||||||||||||||||||
| 105 | 0 | $mw; | |||||||||||||||||||||||||||
| 106 | 3 | }; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | Entity session_csrf_token => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 109 | 0 | my ($this, $name) = @_; | |||||||||||||||||||||||||||
| 110 | 0 | ▶ | $name //= "csrf_token"; # XXX: default name should be configurable. | ||||||||||||||||||||||||||
|
Condition0%0/2
$name //= "csrf_token"
MC/DC0%0/1
$name //= "csrf_token"
$name
Truth table0%0/2
A
A= $name
| |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | $this->entity_psgix_session->{$name} //= do { | ||||||||||||||||||||||||||
|
Condition0%0/3
$this->entity_psgix_session->{$name} //= do {
$this->entity_session_middleware->state->generate
}
MC/DC0%0/2
$this->entity_psgix_session->{$name} //= do {
$this->entity_session_middleware->state->generate
}
$this->entity_psgix_session->{$name}
do {
$this->entity_session_middleware->state->generate
}
Truth table0%0/3
A //= B
A= $this->entity_psgix_session->{$name}B= do {
$this->entity_session_middleware->state->generate
}
| |||||||||||||||||||||||||||||
| 112 | 0 | $this->entity_session_middleware->state->generate; | |||||||||||||||||||||||||||
| 113 | }; | ||||||||||||||||||||||||||||
| 114 | 3 | }; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | #---------------------------------------- | ||||||||||||||||||||||||||||
| 117 | 9 | ▶ | sub default_session_class {'Plack::Session'} | ||||||||||||||||||||||||||
|
Subroutine
default_session_class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | Entity session => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 120 | 0 | my ($this) = @_; | |||||||||||||||||||||||||||
| 121 | 0 | my Env $env = $CON->env; | |||||||||||||||||||||||||||
| 122 | 0 | $env->{'plack.session'}; | |||||||||||||||||||||||||||
| 123 | 3 | }; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||
| 126 | 3 | foreach my $meth (qw(id get keys)) { | |||||||||||||||||||||||||||
| 127 | 4 | ▶ | Entity "session_$meth" => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 128 | 4 | my $this = shift; | |||||||||||||||||||||||||||
| 129 | 4 | my Env $env = $CON->env; | |||||||||||||||||||||||||||
| 130 | 4 | $env->{'plack.session'}->$meth(@_); | |||||||||||||||||||||||||||
| 131 | 9 | }; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | 3 | foreach my $meth (qw(set remove)) { | |||||||||||||||||||||||||||
| 134 | 2 | ▶ | Entity "session_$meth" => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 135 | 2 | my $this = shift; | |||||||||||||||||||||||||||
| 136 | 2 | my Env $env = $CON->env; | |||||||||||||||||||||||||||
| 137 | 2 | $env->{'plack.session'}->$meth(@_); | |||||||||||||||||||||||||||
| 138 | 2 | ""; | |||||||||||||||||||||||||||
| 139 | 6 | }; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | #======================================== | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | # | ||||||||||||||||||||||||||||
| 146 | # Stolen from the top half of Plack::Middleware::Session->call | ||||||||||||||||||||||||||||
| 147 | # | ||||||||||||||||||||||||||||
| 148 | 7 | ▶ | sub session_start { | ||||||||||||||||||||||||||
|
Subroutine
session_start: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 149 | 7 | (my MY $self, my ($CON, @opts)) = @_; | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 7 | ▶ | my $mw = $self->{_session_middleware} or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | 0 | Carp::croak("Session middleware is not initialized!"); | |||||||||||||||||||||||||||
| 153 | }; | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 7 | my Env $env = $CON->env; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 7 | my $id = $self->session_state_extract_id($CON); | |||||||||||||||||||||||||||
| 158 | 7 | ▶ | my $session; $session = $self->session_store_fetch($CON, $id) if $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 7 | $self->session_init_env($env, $session, $id, @opts); | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 1 | ▶ | sub session_expire { | ||||||||||||||||||||||||||
|
Subroutine
session_expire: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 164 | 1 | (my MY $self, my ($CON)) = @_; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 1 | ▶ | my $mw = $self->{_session_middleware} or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | 0 | Carp::croak("Session middleware is not initialized!"); | |||||||||||||||||||||||||||
| 168 | }; | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 1 | my Env $env = $CON->env; | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | # XXX: How about renaming $options->{expire} to $options->{do_expire} | ||||||||||||||||||||||||||||
| 173 | # to avoid confusing with $options->{expires}. | ||||||||||||||||||||||||||||
| 174 | # | ||||||||||||||||||||||||||||
| 175 | 1 | ▶ | if (my $options = $env->{'psgix.session.options'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | $options->{expire} = 1; | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | } else { | ||||||||||||||||||||||||||||
| 180 | 1 | my $id = $self->session_state_extract_id($CON); | |||||||||||||||||||||||||||
| 181 | 1 | $self->session_init_env($env, {}, $id, expire => 1); | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 9 | ▶ | sub session_init_env { | ||||||||||||||||||||||||||
|
Subroutine
session_init_env: called CC=7 SCAR=21.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 187 | 9 | (my MY $self, my Env $env, my ($session, $id, %opts)) = @_; | |||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 9 | ▶ | my $mw = $self->{_session_middleware} or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 0 | Carp::croak("Session middleware is not initialized!"); | |||||||||||||||||||||||||||
| 191 | }; | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 9 | ▶ | if ($id && $session) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$id and $session
MC/DC50%1/2
$id and $session
$id
$session
Truth table66%2/3
A and B
A= $idB= $session
| |||||||||||||||||||||||||||||
| 194 | 6 | $env->{'psgix.session'} = $session; | |||||||||||||||||||||||||||
| 195 | } else { | ||||||||||||||||||||||||||||
| 196 | 3 | $id = $mw->generate_id($env); | |||||||||||||||||||||||||||
| 197 | 3 | $env->{'psgix.session'} = {}; | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 9 | ▶ | $opts{path} //= $env->{'yatt.script_dir'}; | ||||||||||||||||||||||||||
|
Condition66%2/3
$opts{"path"} //= $env->{"yatt.script_dir"}
MC/DC50%1/2
$opts{"path"} //= $env->{"yatt.script_dir"}
$opts{"path"}
$env->{"yatt.script_dir"}
Truth table66%2/3
A //= B
A= $opts{"path"}B= $env->{"yatt.script_dir"}
| |||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 9 | $env->{'psgix.session.options'} = { id => $id, %opts }; | |||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 9 | ▶ | if ($env->{HTTPS}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | 0 | ▶ | $env->{'psgix.session.options'}{secure} //= 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$env->{"psgix.session.options"}{"secure"} //= 1
MC/DC0%0/1
$env->{"psgix.session.options"}{"secure"} //= 1
$env->{"psgix.session.options"}{"secure"}
Truth table0%0/2
A
A= $env->{"psgix.session.options"}{"secure"}
| |||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 9 | $env->{'plack.session'} | |||||||||||||||||||||||||||
| 209 | = Plack::Util::load_class($self->default_session_class)->new($env); | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 16 | ▶ | sub session_state_exists { | ||||||||||||||||||||||||||
|
Subroutine
session_state_exists: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 214 | 16 | (my MY $self, my $CON) = @_; | |||||||||||||||||||||||||||
| 215 | 16 | defined $self->session_state_extract_id($CON); | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 35 | ▶ | sub session_state_extract_id { | ||||||||||||||||||||||||||
|
Subroutine
session_state_extract_id: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 219 | 35 | (my MY $self, my $CON) = @_; | |||||||||||||||||||||||||||
| 220 | 35 | ▶ | my $mw = $self->{_session_middleware} or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 0 | Carp::croak("Session middleware is not initialized!"); | |||||||||||||||||||||||||||
| 222 | }; | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 35 | $CON->cookies_in->{$mw->state->session_key}; | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | # | ||||||||||||||||||||||||||||
| 228 | # In some case, you may want to clear previous session explicitly | ||||||||||||||||||||||||||||
| 229 | # even when previous cookie state exists. | ||||||||||||||||||||||||||||
| 230 | # | ||||||||||||||||||||||||||||
| 231 | 2 | ▶ | sub session_change_id { | ||||||||||||||||||||||||||
|
Subroutine
session_change_id: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 232 | 2 | (my MY $self, my $CON) = @_; | |||||||||||||||||||||||||||
| 233 | 2 | ▶ | my $mw = $self->{_session_middleware} or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | 0 | Carp::croak("Session middleware is not initialized!"); | |||||||||||||||||||||||||||
| 235 | }; | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 2 | my Env $env = $CON->env; | |||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 2 | ▶ | if (not $env->{'psgix.session'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | 1 | ▶ | if (my $prev_sid = $self->session_state_extract_id($CON)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | 1 | $self->session_store_remove($CON, $prev_sid); | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 1 | $self->session_init_env($env); | |||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 1 | return $env->{'psgix.session.options'}{'id'}; | |||||||||||||||||||||||||||
| 247 | } else { | ||||||||||||||||||||||||||||
| 248 | 1 | $mw->change_id($env); | |||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 5 | ▶ | sub session_store_fetch { | ||||||||||||||||||||||||||
|
Subroutine
session_store_fetch: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 253 | 5 | (my MY $self, my ($CON, $id)) = @_; | |||||||||||||||||||||||||||
| 254 | 5 | ▶ | my $mw = $self->{_session_middleware} or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 255 | 0 | Carp::croak("Session middleware is not initialized!"); | |||||||||||||||||||||||||||
| 256 | }; | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 5 | $mw->store->fetch($id); | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 1 | ▶ | sub session_store_remove { | ||||||||||||||||||||||||||
|
Subroutine
session_store_remove: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 262 | 1 | (my MY $self, my ($CON, $id)) = @_; | |||||||||||||||||||||||||||
| 263 | 1 | ▶ | my $mw = $self->{_session_middleware} or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | 0 | Carp::croak("Session middleware is not initialized!"); | |||||||||||||||||||||||||||
| 265 | }; | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 1 | $mw->store->remove($id); | |||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | # | ||||||||||||||||||||||||||||
| 271 | # Stolen from the bottom half of Plack::Middleware::Session->call | ||||||||||||||||||||||||||||
| 272 | # | ||||||||||||||||||||||||||||
| 273 | 11 | ▶ | sub finalize_response { | ||||||||||||||||||||||||||
|
Subroutine
finalize_response: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 274 | 11 | (my MY $self, my ($env, $res)) = @_; | |||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 11 | dputs('START') if DEBUG >= 4; | |||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 11 | $self->maybe::next::method($env, $res); | |||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 11 | my $mw = $self->{_session_middleware}; | |||||||||||||||||||||||||||
| 281 | 11 | my $session = $env->{'psgix.session'}; | |||||||||||||||||||||||||||
| 282 | 11 | my $options = $env->{'psgix.session.options'}; | |||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 11 | ▶ | if (not $session) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | 3 | return; | |||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | # XXX: See comment in session_expire() too. | ||||||||||||||||||||||||||||
| 289 | # | ||||||||||||||||||||||||||||
| 290 | 8 | ▶ | if ($options->{expire}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 291 | 1 | dputs('EXPIRE') if DEBUG >= 4; | |||||||||||||||||||||||||||
| 292 | 1 | $mw->expire_session($options->{id}, $res, $env); | |||||||||||||||||||||||||||
| 293 | } else { | ||||||||||||||||||||||||||||
| 294 | 7 | ▶ | $mw->change_id($env) if $options->{change_id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | 7 | $mw->commit($env); | |||||||||||||||||||||||||||
| 296 | 7 | $mw->save_state($options->{id}, $res, $env); | |||||||||||||||||||||||||||
| 297 | 7 | dputs('SAVED') if DEBUG >= 4; | |||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 8 | dputs('DONE') if DEBUG >= 4; | |||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | # | ||||||||||||||||||||||||||||
| 304 | # This prepare_app is called very late of inheritance chain. | ||||||||||||||||||||||||||||
| 305 | # | ||||||||||||||||||||||||||||
| 306 | 3 | ▶ | sub prepare_app { | ||||||||||||||||||||||||||
|
Subroutine
prepare_app: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 307 | 3 | (my MY $self) = @_; | |||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | 3 | dputs('START') if DEBUG >= 3; | |||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | 3 | my $mw = $self->{_session_middleware} = do { | |||||||||||||||||||||||||||
| 312 | my $class = $self->{session_middleware_class} | ||||||||||||||||||||||||||||
| 313 | 3 | ▶ | || $self->default_session_middleware_class; | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'session_middleware_class'} || $self->default_session_middleware_class
MC/DC0%0/2
$self->{'session_middleware_class'} || $self->default_session_middleware_class
$self->{'session_middleware_class'}
$self->default_session_middleware_class
Truth table33%1/3
A || B
A= $self->{'session_middleware_class'}B= $self->default_session_middleware_class
| |||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | my $state = ($self->{session_state} | ||||||||||||||||||||||||||||
| 316 | 3 | ▶ | ? $self->create_session_backend(State => $self->{session_state}) : $self->default_session_state->new()); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 0 | ▶ | $class->new({app => sub {[200, [], []]} | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 319 | , state => $state | ||||||||||||||||||||||||||||
| 320 | , ($self->{session_store} | ||||||||||||||||||||||||||||
| 321 | 3 | ▶ | ? (store => $self->create_session_backend(Store => $self->{session_store})) : ()) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | }); | ||||||||||||||||||||||||||||
| 323 | }; | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 3 | dputs('session_middleware is created') if DEBUG >= 3; | |||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 3 | $mw->prepare_app; | |||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 3 | dputs('after session_middleware->prepare_app') if DEBUG >= 3; | |||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 3 | dputs('begin maybe::next::method') if DEBUG >= 3; | |||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 3 | $self->maybe::next::method; | |||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | 3 | dputs('DONE') if DEBUG >= 3; | |||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | 0 | ▶ | sub default_session_state {'Plack::Session::State::Cookie'} | ||||||||||||||||||||||||||
|
Subroutine
default_session_state: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 339 | 0 | ▶ | sub default_session_store {'Plack::Session::Store'} | ||||||||||||||||||||||||||
|
Subroutine
default_session_store: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 340 | 3 | ▶ | sub default_session_class_prefix {'Plack::Session'} | ||||||||||||||||||||||||||
|
Subroutine
default_session_class_prefix: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | # From Session::inflate_backend | ||||||||||||||||||||||||||||
| 343 | 6 | ▶ | sub create_session_backend { | ||||||||||||||||||||||||||
|
Subroutine
create_session_backend: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 344 | 6 | (my MY $self, my ($kind, $spec)) = @_; | |||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | # When $spec is not [$backend => @opts], just return it. | ||||||||||||||||||||||||||||
| 347 | 6 | ▶ | return $spec if defined $spec and ref $spec ne 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $spec and ref $spec ne "ARRAY"
MC/DC50%1/2
defined $spec and ref $spec ne "ARRAY"
defined $spec
ref $spec ne "ARRAY"
Truth table66%2/3
A and B
A= defined $specB= ref $spec ne "ARRAY"
| |||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | 3 | my ($backend, @args) = lexpand($spec); | |||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | 3 | my $prefix = join("::", $self->default_session_class_prefix, $kind); | |||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 3 | my $class = Plack::Util::load_class($backend, $prefix); | |||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | 3 | $class->new(@args); | |||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | 3 | 1; | |||||||||||||||||||||||||||