line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Session::ID::incr; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: incr.pm 216 2005-09-01 10:52:26Z sherzodr $ |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
93
|
|
6
|
2
|
|
|
2
|
|
12
|
use File::Spec; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
56
|
|
7
|
2
|
|
|
2
|
|
12
|
use Carp "croak"; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
126
|
|
8
|
2
|
|
|
2
|
|
14
|
use Fcntl qw( :DEFAULT :flock ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1215
|
|
9
|
2
|
|
|
2
|
|
14
|
use CGI::Session::ErrorHandler; |
|
2
|
|
|
|
|
41
|
|
|
2
|
|
|
|
|
582
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$CGI::Session::ID::incr::VERSION = '1.5'; |
12
|
|
|
|
|
|
|
@CGI::Session::ID::incr::ISA = qw( CGI::Session::ErrorHandler ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub generate_id { |
16
|
2
|
|
|
2
|
0
|
5
|
my ($self, $args) = @_; |
17
|
|
|
|
|
|
|
|
18
|
2
|
50
|
|
|
|
8
|
my $IDFile = $args->{IDFile} or croak "Don't know where to store the id"; |
19
|
2
|
|
50
|
|
|
10
|
my $IDIncr = $args->{IDIncr} || 1; |
20
|
2
|
|
50
|
|
|
10
|
my $IDInit = $args->{IDInit} || 0; |
21
|
|
|
|
|
|
|
|
22
|
2
|
50
|
|
|
|
65
|
sysopen(FH, $IDFile, O_RDWR|O_CREAT, 0666) or return $self->set_error("Couldn't open IDFile=>$IDFile: $!"); |
23
|
2
|
50
|
|
|
|
15
|
flock(FH, LOCK_EX) or return $self->set_error("Couldn't lock IDFile=>$IDFile: $!"); |
24
|
2
|
|
33
|
|
|
23
|
my $ID = || $IDInit; |
25
|
2
|
50
|
|
|
|
9
|
seek(FH, 0, 0) or return $self->set_error("Couldn't seek IDFile=>$IDFile: $!"); |
26
|
2
|
50
|
|
|
|
116
|
truncate(FH, 0) or return $self->set_error("Couldn't truncate IDFile=>$IDFile: $!"); |
27
|
2
|
|
|
|
|
6
|
$ID += $IDIncr; |
28
|
2
|
|
|
|
|
5
|
print FH $ID; |
29
|
2
|
50
|
|
|
|
66
|
close(FH) or return $self->set_error("Couldn't close IDFile=>$IDFile: $!"); |
30
|
2
|
|
|
|
|
12
|
return $ID; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
__END__; |