line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer2::Session::CGISession; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
14131
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
45
|
|
4
|
2
|
|
|
2
|
|
35
|
use 5.008_005; |
|
2
|
|
|
|
|
4
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
539
|
use Moo; |
|
2
|
|
|
|
|
9739
|
|
|
2
|
|
|
|
|
9
|
|
8
|
2
|
|
|
2
|
|
1278
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
101
|
|
9
|
2
|
|
|
2
|
|
472
|
use Dancer2::Core::Types; |
|
2
|
|
|
|
|
7122
|
|
|
2
|
|
|
|
|
504
|
|
10
|
2
|
|
|
2
|
|
1110
|
use CGI::Session; |
|
2
|
|
|
|
|
7245
|
|
|
2
|
|
|
|
|
10
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Dancer2::Core::Role::SessionFactory'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#------------------------------------# |
15
|
|
|
|
|
|
|
# Attributes |
16
|
|
|
|
|
|
|
#------------------------------------# |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has driver_params => ( |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
default => sub { {}; } |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has driver => ( |
24
|
|
|
|
|
|
|
is => 'ro', |
25
|
|
|
|
|
|
|
default => sub { 'driver:File'; } |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has name => ( |
29
|
|
|
|
|
|
|
is => 'ro', |
30
|
|
|
|
|
|
|
default => sub { 'CGISESSID'; } |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#------------------------------------# |
34
|
|
|
|
|
|
|
# Role composition |
35
|
|
|
|
|
|
|
#------------------------------------# |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#might be possible to do something with CGI::Session find method here |
38
|
|
|
|
|
|
|
sub _sessions { |
39
|
0
|
|
|
0
|
|
0
|
my ($self) = @_; |
40
|
0
|
|
|
|
|
0
|
return []; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub generate_id { |
44
|
3
|
|
|
3
|
0
|
98120
|
my ( $class ) = @_; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#creation of the cgi session when generating the id, as it using dancer2 id to create CGI session seems not to be working |
47
|
3
|
50
|
|
|
|
27
|
my $cgi_session = CGI::Session->new( |
48
|
|
|
|
|
|
|
$class->driver, |
49
|
|
|
|
|
|
|
undef, |
50
|
|
|
|
|
|
|
$class->driver_params |
51
|
|
|
|
|
|
|
) or die CGI::Session->errstr();; |
52
|
3
|
|
|
|
|
51399
|
$cgi_session->expire( $class->session_duration ); |
53
|
3
|
|
|
|
|
51
|
$cgi_session->name( $class->cookie_name ); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
#Return the newly created CGI::Session id |
56
|
3
|
|
|
|
|
22
|
return $cgi_session->id(); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _retrieve { |
60
|
0
|
|
|
0
|
|
0
|
my ( $class, $id ) = @_; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
my $cgi_session = $class->get_cgi_session( $id ); |
63
|
0
|
0
|
0
|
|
|
0
|
if( $cgi_session->is_empty or $cgi_session->is_expired ) { |
64
|
|
|
|
|
|
|
# CGI Session has been removed from the server, die here, Dancer2::Core::Role::Session |
65
|
|
|
|
|
|
|
# knows how to deal with that, warn Caller by dying |
66
|
0
|
|
|
|
|
0
|
die "CGI Session has disappeared"; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
return $cgi_session->dataref(); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _destroy { |
73
|
0
|
|
|
0
|
|
0
|
my ( $class, $id ) = @_; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
my $cgi_session = $class->get_cgi_session( $id ); |
76
|
0
|
0
|
|
|
|
0
|
if( defined $cgi_session->id ) { |
77
|
0
|
|
|
|
|
0
|
$cgi_session->delete; |
78
|
0
|
|
|
|
|
0
|
$cgi_session->flush; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _flush { |
83
|
3
|
|
|
3
|
|
4256
|
my ( $class, $id, $data ) = @_; |
84
|
|
|
|
|
|
|
|
85
|
3
|
|
|
|
|
8
|
my $cgi_session = $class->get_cgi_session( $id ); |
86
|
0
|
|
|
|
|
0
|
foreach my $key (keys %{$data} ){ |
|
0
|
|
|
|
|
0
|
|
87
|
0
|
0
|
|
|
|
0
|
delete $$data{$key} if ($key =~ m/^_SESSION_/); |
88
|
|
|
|
|
|
|
} |
89
|
0
|
|
|
|
|
0
|
$cgi_session->param( %{$data} ); |
|
0
|
|
|
|
|
0
|
|
90
|
0
|
|
|
|
|
0
|
$cgi_session->flush; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub get_cgi_session { |
94
|
3
|
|
|
3
|
0
|
3
|
my ( $class, $id ) = @_; |
95
|
|
|
|
|
|
|
|
96
|
3
|
50
|
|
|
|
66
|
my $cgi_session = CGI::Session->load( $class->driver, $id, $class->driver_params ) |
97
|
|
|
|
|
|
|
or die CGI::Session->errstr(); |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
return $cgi_session; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
__END__ |