1
package CGI::Session::ID::incr;
3
# $Id: incr.pm 447 2008-11-01 03:46:08Z markstos $
8
use Fcntl qw( :DEFAULT :flock );
9
use CGI::Session::ErrorHandler;
11
$CGI::Session::ID::incr::VERSION = '4.38';
12
@CGI::Session::ID::incr::ISA = qw( CGI::Session::ErrorHandler );
16
my ($self, $args) = @_;
18
my $IDFile = $args->{IDFile} or croak "Don't know where to store the id";
19
my $IDIncr = $args->{IDIncr} || 1;
20
my $IDInit = $args->{IDInit} || 0;
22
sysopen(FH, $IDFile, O_RDWR|O_CREAT, 0666) or return $self->set_error("Couldn't open IDFile=>$IDFile: $!");
23
flock(FH, LOCK_EX) or return $self->set_error("Couldn't lock IDFile=>$IDFile: $!");
24
my $ID = <FH> || $IDInit;
25
seek(FH, 0, 0) or return $self->set_error("Couldn't seek IDFile=>$IDFile: $!");
26
truncate(FH, 0) or return $self->set_error("Couldn't truncate IDFile=>$IDFile: $!");
29
close(FH) or return $self->set_error("Couldn't close IDFile=>$IDFile: $!");
42
CGI::Session::ID::incr - CGI::Session ID driver
47
$session = new CGI::Session("id:Incr", undef, {
49
IDFile => '/tmp/cgisession.id',
55
CGI::Session::ID::incr is to generate auto incrementing Session IDs. Compare it with L<CGI::Session::ID::md5|CGI::Session::ID::md5>, where session ids are truly random 32 character long strings. CGI::Session::ID::incr expects the following arguments passed to CGI::Session->new() as the third argument.
61
Location where auto incremented IDs are stored. This attribute is required.
65
Initial value of the ID if it's the first ID to be generated. For example, if you want the ID numbers to start with 1000 as opposed to 0, that's where you should set your value. Default is C<0>.
69
How many digits each number should increment by. For example, if you want the first generated id to start with 1000, and each subsequent id to increment by 10, set I<IDIncr> to 10 and I<IDInit> to 1000. Default is C<1>.
75
For support and licensing information see L<CGI::Session|CGI::Session>