line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Easy::Session; |
2
|
2
|
|
|
2
|
|
1096
|
use 5.010001; |
|
2
|
|
|
|
|
6
|
|
3
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
37
|
|
4
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
27
|
|
5
|
2
|
|
|
2
|
|
6
|
use utf8; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
6
|
|
6
|
2
|
|
|
2
|
|
36
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
126
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = 'v2.0.1'; |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
702
|
use Data::UUID; |
|
2
|
|
|
|
|
837
|
|
|
2
|
|
|
|
|
98
|
|
11
|
2
|
|
|
2
|
|
10
|
use CGI::Easy::Util qw( quote_list unquote_hash ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
8
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
189
|
use constant SESSION_EXPIRE => 365*24*60*60; # 1 year |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
779
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $UG; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
11
|
|
|
11
|
1
|
51
|
my ($class, $r, $h) = @_; |
20
|
11
|
|
|
|
|
50
|
my $self = { |
21
|
|
|
|
|
|
|
id => undef, |
22
|
|
|
|
|
|
|
perm => undef, |
23
|
|
|
|
|
|
|
temp => undef, |
24
|
|
|
|
|
|
|
_r => $r, |
25
|
|
|
|
|
|
|
_h => $h, |
26
|
|
|
|
|
|
|
}; |
27
|
11
|
|
|
|
|
17
|
bless $self, $class; |
28
|
11
|
|
|
|
|
27
|
$self->_init; |
29
|
11
|
|
|
|
|
240
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _init { |
33
|
11
|
|
|
11
|
|
17
|
my ($self) = @_; |
34
|
11
|
|
|
|
|
14
|
my $r = $self->{_r}; |
35
|
11
|
|
|
|
|
13
|
my $c = $r->{cookie}; |
36
|
11
|
50
|
|
|
|
17
|
if ($c->{sid}) { |
37
|
0
|
|
|
|
|
0
|
$self->{id} = $c->{sid}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else { |
40
|
11
|
|
100
|
|
|
39
|
my $referer = $r->{ENV}{HTTP_REFERER} || q{}; |
41
|
11
|
100
|
|
|
|
95
|
if ($referer !~ m{\A\w+://\Q$r->{host}\E[:/]}xms) { |
42
|
10
|
|
66
|
|
|
496
|
$UG ||= Data::UUID->new(); |
43
|
10
|
|
|
|
|
119
|
$self->{id} = $UG->create_b64(); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
11
|
100
|
|
|
|
24
|
if ($self->{id}) { |
47
|
|
|
|
|
|
|
$self->{_h}->add_cookie({ |
48
|
|
|
|
|
|
|
name => 'sid', |
49
|
|
|
|
|
|
|
value => $self->{id}, |
50
|
10
|
|
|
|
|
41
|
expires => time + SESSION_EXPIRE, |
51
|
|
|
|
|
|
|
}); |
52
|
|
|
|
|
|
|
} |
53
|
11
|
|
100
|
|
|
32
|
$self->{perm} = unquote_hash($c->{perm}) || {}; |
54
|
11
|
|
100
|
|
|
29
|
$self->{temp} = unquote_hash($c->{temp}) || {}; |
55
|
11
|
|
|
|
|
18
|
return; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub save { |
59
|
2
|
|
|
2
|
1
|
474
|
my ($self) = @_; |
60
|
2
|
|
|
|
|
3
|
my $h = $self->{_h}; |
61
|
2
|
50
|
|
|
|
13
|
my @other_cookies = grep {$_->{name} ne 'perm' && $_->{name} ne 'temp'} |
62
|
2
|
|
|
|
|
3
|
@{ $h->{'Set-Cookie'} }; |
|
2
|
|
|
|
|
6
|
|
63
|
|
|
|
|
|
|
$h->{'Set-Cookie'} = [ |
64
|
|
|
|
|
|
|
@other_cookies, |
65
|
|
|
|
|
|
|
{ |
66
|
|
|
|
|
|
|
name => 'perm', |
67
|
2
|
|
|
|
|
9
|
value => quote_list(%{ $self->{perm} }), |
68
|
|
|
|
|
|
|
expires => time + SESSION_EXPIRE, |
69
|
|
|
|
|
|
|
}, |
70
|
|
|
|
|
|
|
{ |
71
|
|
|
|
|
|
|
name => 'temp', |
72
|
2
|
|
|
|
|
4
|
value => quote_list(%{ $self->{temp} }), |
|
2
|
|
|
|
|
5
|
|
73
|
|
|
|
|
|
|
}, |
74
|
|
|
|
|
|
|
]; |
75
|
2
|
|
|
|
|
5
|
return; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
80
|
|
|
|
|
|
|
__END__ |