CGI-MxScreen
view release on metacpan or search on metacpan
MxScreen/Session/Medium/File.pm view on Meta::CPAN
# -*- Mode: perl -*-
#
# $Id: File.pm,v 0.1 2001/04/22 17:57:04 ram Exp $
#
# Copyright (c) 1998-2001, Raphael Manfredi
# Copyright (c) 2000-2001, Christophe Dehaudt
#
# You may redistribute only under the terms of the Artistic License,
# as specified in the README file that comes with the distribution.
#
# HISTORY
# $Log: File.pm,v $
# Revision 0.1 2001/04/22 17:57:04 ram
# Baseline for first Alpha release.
#
# $EndLog$
#
use strict;
package CGI::MxScreen::Session::Medium::File;
#
# Session storage is a file, indexed by a session ID.
#
# In the generated HTML, the session is identified by two parameters:
#
# _mxscreen_session the session ID
# _mxscreen_token a random token, saved with context
#
# The random token is generated each time the context is saved to the file.
# It is used at retrieve time to validate the session ID: noone could guess
# both the session ID and the associated token at the same time.
#
# Note that since we generate a token each time we save, using "Back" from
# the browser to resubmit an old form is bound to fail, since the token
# will have changed.
#
# It is up to the user to ensure that old session files are removed from the
# file system, according to a suitable session expiring policy.
#
require CGI::MxScreen::Session::Medium;
use vars qw(@ISA);
@ISA = qw(CGI::MxScreen::Session::Medium);
use Carp::Datum;
use Getargs::Long;
use Log::Agent;
use Fcntl;
use File::Basename;
use File::Path;
require LockFile::Simple;
require CGI;
use constant MX_SESSION_ID => "_mxscreen_session";
use constant MX_TOKEN => "_mxscreen_token";
#
# ->make
#
# Creation routine.
#
# Arguments:
# -directory root directory where sessions are stored
# -nfs whether stored data are on a network filesystem
# -max_hold maximum expected lock holding time, for stale lock detection
#
sub make {
DFEATURE my $f_;
my $self = bless {}, shift;
my $MAX_HOLD = 60; # If CGI takes more than that, uh!
my ($directory, $nfs, $max) = xgetargs(@_,
-directory => 's',
-nfs => ['i', 0],
-max_hold => ['i', $MAX_HOLD],
);
$self->{directory} = $directory;
$self->{shared} = $nfs;
$self->{lockmgr} = LockFile::Simple->make(
-delay => 1,
-hold => $max,
-max => $max, # After that, will be stale
-nfs => $nfs,
-stale => 1,
);
return DVAL $self;
}
( run in 0.923 second using v1.01-cache-2.11-cpan-b16cb0d3907 )