Apache-Session-Generate-AutoIncrement

 view release on metacpan or  search on metacpan

AutoIncrement.pm  view on Meta::CPAN

    if (exists $session->{args}->{IDLength}) {
        $length = $session->{args}->{IDLength};
    }
    
	 my $cntstr = '0' x $length . "$count";
    $session->{data}->{_session_id} = substr($cntstr, length($cntstr)-$length);
    

}

sub validate {
    #This routine checks to ensure that the session ID is in the form
    #we expect.  This must be called before we start diddling around
    #in the database or the disk.

    my $session = shift;
    # Check content
    if ($session->{data}->{_session_id} !~ /^[0-9]+$/) {
        die;
    }
	 #check length

test.pl  view on Meta::CPAN

eval {
  $value = Apache::Session::Generate::AutoIncrement::generate($session);
  print "ok 3\n";
};
print "not ok 3 : $@\n" if $@;

$value = Apache::Session::Generate::AutoIncrement::generate($session);
$session->{data}->{_session_id} = $value;
if ( $value == 2
	  && $value eq "0000000002"
	  && Apache::Session::Generate::AutoIncrement::validate($session) ) {
  print "ok 4\n";
} else {
  print "not ok 4: $value\n";
}

$value = Apache::Session::Generate::AutoIncrement::generate($session);
$session->{data}->{_session_id} = $value;
if ( $value == 3
	  && $value eq "0000000003"
	  && Apache::Session::Generate::AutoIncrement::validate($session) ) {
  print "ok 5\n";
} else {
  print "not ok 5: $value\n";
}

$session->{args}->{IDLength} = 5;
eval {
  $value = Apache::Session::Generate::AutoIncrement::generate($session);
  print "ok 6\n";
};
print "not ok 6\n" if $@;

$value = Apache::Session::Generate::AutoIncrement::generate($session);
$session->{data}->{_session_id} = $value;
if ( $value == 5
	  && $value eq "00005"
	  && Apache::Session::Generate::AutoIncrement::validate($session) ) {
  print "ok 7\n";
} else {
  print "not ok 7\n";
}


# Cleanup
unlink $testfile;



( run in 0.498 second using v1.01-cache-2.11-cpan-a5abf4f5562 )