line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Prancer::Session; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
10
|
use strict; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
155
|
|
4
|
4
|
|
|
4
|
|
10
|
use warnings FATAL => 'all'; |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
101
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
9
|
use Storable qw(dclone); |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
1313
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
0
|
|
|
0
|
0
|
|
my ($class, $env) = @_; |
10
|
0
|
|
|
|
|
|
my $self = bless({ |
11
|
|
|
|
|
|
|
'env' => $env, |
12
|
|
|
|
|
|
|
'_session' => $env->{'psgix.session'}, |
13
|
|
|
|
|
|
|
'_options' => $env->{'psgix.session.options'}, |
14
|
|
|
|
|
|
|
}, $class); |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
return $self; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub id { |
20
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
21
|
0
|
|
|
|
|
|
return $self->{'_options'}->{'id'}; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub has { |
25
|
0
|
|
|
0
|
0
|
|
my ($self, $key) = @_; |
26
|
0
|
|
|
|
|
|
return exists($self->{'_session'}->{$key}); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub get { |
30
|
0
|
|
|
0
|
0
|
|
my ($self, $key) = @_; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
0
|
|
|
|
if (defined(wantarray()) && defined($self->{'_session'}->{$key})) { |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $value = $self->{'_session'}->{$key}; |
37
|
0
|
0
|
|
|
|
|
return dclone($value) if ref($value); |
38
|
0
|
|
|
|
|
|
return $value; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
return; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub set { |
45
|
0
|
|
|
0
|
0
|
|
my ($self, $key, $value) = @_; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $old = undef; |
48
|
0
|
0
|
|
|
|
|
$old = $self->get($key) if defined(wantarray()); |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
if (ref($value)) { |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$self->{'_session'}->{$key} = dclone($value); |
54
|
|
|
|
|
|
|
} else { |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$self->{'_session'}->{$key} = $value; |
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
|
return $old; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub remove { |
62
|
0
|
|
|
0
|
0
|
|
my ($self, $key) = @_; |
63
|
0
|
|
|
|
|
|
return delete($self->{'_session'}->{$key}); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub expire { |
67
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
68
|
0
|
|
|
|
|
|
for my $key (keys %{$self->{'_session'}}) { |
|
0
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
delete($self->{'_session'}->{$key}); |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
|
$self->{'_options'}->{'expire'} = 1; |
72
|
0
|
|
|
|
|
|
return; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub as_hashref { |
76
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
77
|
0
|
|
|
|
|
|
return $self->{'_session'}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 NAME |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Prancer::Session |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SYNOPSIS |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
This module should not be used directly to access a session. Instead, one |
89
|
|
|
|
|
|
|
should use L<Prancer::Context>. For configuration options, please refer to the |
90
|
|
|
|
|
|
|
documentation for the specific session state manager and session store manager |
91
|
|
|
|
|
|
|
you wish to use. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 SEE ALSO |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=over 4 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item1 L<Prancer::Session::State::Cookie> |
98
|
|
|
|
|
|
|
=item1 L<Prancer::Session::Store::Memory> |
99
|
|
|
|
|
|
|
=item1 L<Prancer::Session::Store::YAML> |
100
|
|
|
|
|
|
|
=item1 L<Prancer::Session::Store::Database> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=back |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|