Service/SessionMemory.pm

filter: Statementstmt 33.3% 1 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 50.0% 2 / 4 CC 1 SCAR 2.6
CC
1
Cov
33%
BEGIN
1.3
CRAP 1.3
« Service/SessionFile.pm ↑ Summary Sessions/Storage.pm »
1 package Mojolicious::Service::SessionMemory;
2 0 ▶use Mojo::Base 'Mojolicious::Service';
Subroutine BEGIN: called CC=1 SCAR=2.6
3  
4 has storage => sub{{}};
5  
6  
7 sub fetch{
8 my $self = shift;
9 my $session_id = shift;
10 my $session = $self->storage->{$session_id};
11 if($session){
12 if($session->{expires} && $session->{expires} > time){
13 return $session;
14 }
15 ## 因为cookie也会过期,所以正常情况下是无法执行到下面的代码的
16 $self->remove($session_id);
17 }
18 return undef;
19 }
20  
21 sub remove{
22 my $self = shift;
23 my $session_id = shift;
24 delete $self->storage->{$session_id} if(defined $session_id && $session_id ne "");
25 }
26  
27 sub store{
28 my $self = shift;
29 my $session_id = shift;
30 my $session = shift;
31 $self->storage->{$session_id} = $session;
32 }
33  
34  
35  
36  
37 1; # End of Mojolicious::Sessions::Storage::Memory
« Service/SessionFile.pm ↑ Summary Sessions/Storage.pm »