line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#############################################################################
|
2
|
|
|
|
|
|
|
## Name: Driver.pm
|
3
|
|
|
|
|
|
|
## Purpose: AutoSession::Driver
|
4
|
|
|
|
|
|
|
## Author: Graciliano M. P.
|
5
|
|
|
|
|
|
|
## Modified by:
|
6
|
|
|
|
|
|
|
## Created: 20/5/2003
|
7
|
|
|
|
|
|
|
## RCS-ID:
|
8
|
|
|
|
|
|
|
## Copyright: (c) 2003 Graciliano M. P.
|
9
|
|
|
|
|
|
|
## Licence: This program is free software; you can redistribute it and/or
|
10
|
|
|
|
|
|
|
## modify it under the same terms as Perl itself
|
11
|
|
|
|
|
|
|
#############################################################################
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package AutoSession::Driver ;
|
14
|
|
|
|
|
|
|
our $VERSION = '1.0' ;
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
6
|
use strict qw(vars) ;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
5
|
no warnings ;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1580
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my %DRIVERS = (
|
21
|
|
|
|
|
|
|
'file' => 'AutoSession::Driver::File' ,
|
22
|
|
|
|
|
|
|
) ;
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my @LYB = qw(0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) ;
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
#######
|
27
|
|
|
|
|
|
|
# NEW #
|
28
|
|
|
|
|
|
|
#######
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub new {
|
31
|
1
|
|
|
1
|
0
|
2
|
my $class = shift ;
|
32
|
1
|
|
|
|
|
8
|
my ( %args ) = @_ ;
|
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
4
|
my $type = "\L$args{driver}\E" ;
|
35
|
1
|
|
|
|
|
4
|
$type =~ s/\s//gs ;
|
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
4
|
my $module = $DRIVERS{$type} ;
|
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
1
|
|
718
|
eval(qq`use $module ;`) ;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
20
|
|
|
1
|
|
|
|
|
88
|
|
40
|
1
|
50
|
|
|
|
6
|
if ($@) { die $@ ;}
|
|
0
|
|
|
|
|
0
|
|
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
33
|
my $this = $module->new(%args) ;
|
43
|
1
|
50
|
|
|
|
6
|
if (!$this) { return undef ;}
|
|
0
|
|
|
|
|
0
|
|
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
4
|
$this->{type} = $type ;
|
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
56
|
return( $this ) ;
|
48
|
|
|
|
|
|
|
}
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
########
|
51
|
|
|
|
|
|
|
# OPEN #
|
52
|
|
|
|
|
|
|
########
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub open {
|
55
|
0
|
|
|
0
|
0
|
0
|
my $this = shift ;
|
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
0
|
delete $this->{closed} ;
|
58
|
0
|
|
|
|
|
0
|
$this->refresh ;
|
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
return( 1 ) ;
|
61
|
|
|
|
|
|
|
}
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
#########
|
64
|
|
|
|
|
|
|
# CLOSE #
|
65
|
|
|
|
|
|
|
#########
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub close {
|
68
|
0
|
|
|
0
|
0
|
0
|
my $this = shift ;
|
69
|
0
|
|
|
|
|
0
|
$this->save ;
|
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
0
|
$this->{closed} = 1 ;
|
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
0
|
delete $this->{tree} ;
|
74
|
0
|
|
|
|
|
0
|
delete $this->{time} ;
|
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
0
|
return( 1 ) ;
|
77
|
|
|
|
|
|
|
}
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
###########
|
80
|
|
|
|
|
|
|
# REFRESH #
|
81
|
|
|
|
|
|
|
###########
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub refresh {
|
84
|
5
|
|
|
5
|
0
|
10
|
my $this = shift ;
|
85
|
|
|
|
|
|
|
|
86
|
5
|
50
|
|
|
|
14
|
if ( $this->{closed} ) { return( undef ) ;}
|
|
0
|
|
|
|
|
0
|
|
87
|
|
|
|
|
|
|
|
88
|
5
|
50
|
33
|
|
|
297
|
if ( !$this->{tree} || $this->time > $this->{time} ) {
|
89
|
0
|
|
|
|
|
0
|
$this->load ;
|
90
|
0
|
|
|
|
|
0
|
return( 1 ) ;
|
91
|
|
|
|
|
|
|
}
|
92
|
|
|
|
|
|
|
|
93
|
5
|
|
|
|
|
25
|
return( undef ) ;
|
94
|
|
|
|
|
|
|
}
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
#########
|
97
|
|
|
|
|
|
|
# CLEAR #
|
98
|
|
|
|
|
|
|
#########
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub clear {
|
101
|
1
|
|
|
1
|
0
|
3
|
my $this = shift ;
|
102
|
1
|
|
|
|
|
3
|
$this->{tree} = {} ;
|
103
|
1
|
|
|
|
|
6
|
$this->save ;
|
104
|
1
|
|
|
|
|
4
|
return( 1 ) ;
|
105
|
|
|
|
|
|
|
}
|
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
1
|
0
|
4
|
sub clean { &clear ;}
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
##########
|
110
|
|
|
|
|
|
|
# NEW_ID #
|
111
|
|
|
|
|
|
|
##########
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub new_id {
|
114
|
0
|
|
|
0
|
0
|
0
|
my $this = shift ;
|
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
0
|
my $id = $this->random_id() ;
|
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
0
|
while( $this->exist_id($id) ) { $id = $this->random_id() ;}
|
|
0
|
|
|
|
|
0
|
|
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
0
|
return( $id ) ;
|
121
|
|
|
|
|
|
|
}
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
#############
|
124
|
|
|
|
|
|
|
# RANDOM_ID #
|
125
|
|
|
|
|
|
|
#############
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub random_id {
|
128
|
0
|
|
|
0
|
0
|
0
|
my $this = shift ;
|
129
|
0
|
|
0
|
|
|
0
|
my $leng = $this->{idsize} || $_[0] || $AutoSession::DEF_IDSIZE ;
|
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
0
|
my $id ;
|
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
0
|
while( length($id) < $leng ) {
|
134
|
0
|
|
|
|
|
0
|
$id .= @LYB[ rand(@LYB) ] ;
|
135
|
|
|
|
|
|
|
}
|
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
0
|
return( $id ) ;
|
138
|
|
|
|
|
|
|
}
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
################
|
141
|
|
|
|
|
|
|
# PARSE_EXPIRE #
|
142
|
|
|
|
|
|
|
################
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub parse_expire {
|
145
|
1
|
|
|
1
|
0
|
3
|
my $this = shift ;
|
146
|
1
|
|
33
|
|
|
4
|
my $expire = $_[0] || $this->{expire} ;
|
147
|
1
|
|
|
|
|
4
|
$expire =~ s/[\W_]//gs ;
|
148
|
|
|
|
|
|
|
|
149
|
1
|
50
|
|
|
|
7
|
if ($expire !~ /^\d+$/) {
|
150
|
0
|
0
|
|
|
|
0
|
if ($expire =~ /^(\d+)s/) { $expire = $1 ;}
|
|
0
|
0
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
151
|
0
|
|
|
|
|
0
|
elsif ($expire =~ /^(\d+)m/) { $expire = $1 * 60 ;}
|
152
|
0
|
|
|
|
|
0
|
elsif ($expire =~ /^(\d+)h/) { $expire = $1 * 60*60 ;}
|
153
|
0
|
|
|
|
|
0
|
elsif ($expire =~ /^(\d+)d/) { $expire = $1 * 60*60*24 ;}
|
154
|
0
|
|
|
|
|
0
|
elsif ($expire =~ /^(\d+)w/) { $expire = $1 * 60*60*24*7 ;}
|
155
|
0
|
|
|
|
|
0
|
elsif ($expire =~ /^(\d+)mo/) { $expire = $1 * 60*60*24*30 ;}
|
156
|
0
|
|
|
|
|
0
|
elsif ($expire =~ /^(\d+)y/) { $expire = $1 * 60*60*24*365 ;}
|
157
|
|
|
|
|
|
|
}
|
158
|
|
|
|
|
|
|
|
159
|
1
|
|
|
|
|
694
|
return( $expire ) ;
|
160
|
|
|
|
|
|
|
}
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
###########
|
163
|
|
|
|
|
|
|
# DESTROY #
|
164
|
|
|
|
|
|
|
###########
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub DESTROY {
|
167
|
1
|
|
|
1
|
|
4
|
my $this = shift ;
|
168
|
1
|
|
|
|
|
6
|
$this->save ;
|
169
|
|
|
|
|
|
|
}
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
#######
|
172
|
|
|
|
|
|
|
# END #
|
173
|
|
|
|
|
|
|
#######
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
1;
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|