line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::okSession; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#use 5.008; |
4
|
4
|
|
|
4
|
|
118934
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
132
|
|
5
|
|
|
|
|
|
|
#use warnings; |
6
|
4
|
|
|
4
|
|
4678
|
use Storable; |
|
4
|
|
|
|
|
17496
|
|
|
4
|
|
|
|
|
296
|
|
7
|
4
|
|
|
4
|
|
39
|
use Exporter; #Export functions |
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
4198
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
12
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
13
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# This allows declaration use CGI::okSession ':all'; |
16
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
17
|
|
|
|
|
|
|
# will save memory. |
18
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
) ] ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our @EXPORT = qw( |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my @known_options = qw( |
30
|
|
|
|
|
|
|
dir |
31
|
|
|
|
|
|
|
timout |
32
|
|
|
|
|
|
|
app |
33
|
|
|
|
|
|
|
id |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub new { |
37
|
4
|
|
|
4
|
1
|
6001820
|
my $class = shift; |
38
|
4
|
|
|
|
|
58
|
my %config = ( |
39
|
|
|
|
|
|
|
dir => '/tmp', |
40
|
|
|
|
|
|
|
timeout => 30*60, |
41
|
|
|
|
|
|
|
app => 'default' |
42
|
|
|
|
|
|
|
,@_ |
43
|
|
|
|
|
|
|
); |
44
|
4
|
|
|
|
|
40
|
_remove_expired(%config); |
45
|
4
|
|
|
|
|
2143546
|
my $self; |
46
|
4
|
100
|
|
|
|
41
|
unless ($config{id}) { |
47
|
1
|
|
|
|
|
2763
|
require Time::HiRes; |
48
|
1
|
|
|
|
|
2363
|
require Digest::MD5; |
49
|
1
|
|
|
|
|
16
|
$config{id} = Digest::MD5::md5_hex(Time::HiRes::time()); |
50
|
|
|
|
|
|
|
} |
51
|
4
|
100
|
|
|
|
152
|
if (-e "$config{dir}/$config{id}.sess") { |
52
|
2
|
|
|
|
|
22
|
$self = Storable::lock_retrieve("$config{dir}/$config{id}.sess"); |
53
|
|
|
|
|
|
|
} else { |
54
|
2
|
|
|
|
|
9
|
$self->{___ID} = $config{id}; |
55
|
2
|
|
|
|
|
6
|
$self->{___config} = \%config; |
56
|
2
|
|
|
|
|
12
|
Storable::lock_nstore($self,"$config{dir}/$config{id}.sess"); |
57
|
|
|
|
|
|
|
} |
58
|
4
|
|
|
|
|
1137
|
$self->{___ID} = $config{id}; |
59
|
4
|
|
|
|
|
16
|
$self->{___expires} = time() + $config{timeout}; |
60
|
4
|
|
|
|
|
13
|
$self->{___config} = \%config; |
61
|
|
|
|
|
|
|
# $self->DESTROY = DESTROY; |
62
|
4
|
|
|
|
|
16
|
_set_expiration_2_app($self->{___ID},$self->{___expires},%{$self->{___config}}); |
|
4
|
|
|
|
|
31
|
|
63
|
4
|
|
|
|
|
569624
|
return bless($self,$class); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub get_ID { |
67
|
2
|
|
|
2
|
1
|
1070
|
return shift->{___ID}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _remove_expired { |
71
|
4
|
|
|
4
|
|
17
|
my (%config) = @_; |
72
|
4
|
|
|
|
|
11
|
my $a; |
73
|
4
|
50
|
|
|
|
157
|
if (-e "$config{dir}/$config{app}") { |
74
|
4
|
|
|
|
|
34
|
$a = Storable::lock_retrieve("$config{dir}/$config{app}"); |
75
|
|
|
|
|
|
|
} else { |
76
|
0
|
|
|
|
|
0
|
$a->{Application} = $config{app}; |
77
|
0
|
|
|
|
|
0
|
Storable::lock_nstore($a,"$config{dir}/$config{app}"); |
78
|
0
|
|
|
|
|
0
|
return; |
79
|
|
|
|
|
|
|
} |
80
|
4
|
50
|
|
|
|
22720
|
unless ($a->{Sessions}) { |
81
|
0
|
|
|
|
|
0
|
return; |
82
|
|
|
|
|
|
|
} |
83
|
4
|
|
|
|
|
540
|
my $tim = time(); |
84
|
4
|
|
|
|
|
8
|
my $t; |
85
|
4
|
|
|
|
|
10
|
foreach $t (keys %{$a->{Sessions}}) { |
|
4
|
|
|
|
|
22
|
|
86
|
6
|
100
|
|
|
|
584
|
if ($a->{Sessions}->{$t} < $tim) { |
87
|
2
|
50
|
|
|
|
903
|
unlink("$config{dir}/$t.sess") || die "Can't delete Session"; |
88
|
2
|
|
|
|
|
12
|
delete $a->{Sessions}->{$t}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
4
|
|
|
|
|
37
|
Storable::lock_nstore($a,"$config{dir}/$config{app}"); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub expires { |
95
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
96
|
0
|
|
|
|
|
0
|
return $self->{___expires}; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub expires_www { |
100
|
1
|
|
|
1
|
1
|
403
|
my $self = shift; |
101
|
1
|
|
|
|
|
21
|
my @t = gmtime($self->{___expires}); |
102
|
1
|
|
|
|
|
19
|
return sprintf('%3.3s, %02d-%3.3s-%04d %02d:%02d:%02d GMT',("Sun","Mon","Tue","Wed","Thu","Fri","Sut","Sun")[$t[6]],$t[3],("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")[$t[4]],$t[5]+1900,$t[2],$t[1],$t[0]); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _set_expiration_2_app { |
106
|
4
|
|
|
4
|
|
19
|
my ($id,$tim,%config) = @_; |
107
|
4
|
|
|
|
|
9
|
my $a = undef; |
108
|
4
|
50
|
|
|
|
78
|
if (-e "$config{dir}/$config{app}") { |
109
|
4
|
|
|
|
|
27
|
$a = Storable::lock_retrieve("$config{dir}/$config{app}"); |
110
|
|
|
|
|
|
|
} |
111
|
4
|
|
|
|
|
348
|
$a->{Sessions}->{$id} = $tim; |
112
|
4
|
|
|
|
|
27
|
Storable::lock_nstore($a,"$config{dir}/$config{app}"); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
DESTROY { |
116
|
4
|
|
|
4
|
|
6470
|
my $self = shift; |
117
|
4
|
|
|
|
|
31
|
my(%s) = (%$self); |
118
|
4
|
|
|
|
|
59
|
Storable::lock_store(\%s,"$s{___config}->{dir}/$s{___config}->{id}.sess"); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
__END__ |