package PageSession; use vars qw($NEXTID $MAXSESSIONS %SESSIONS); $MAX_SESSIONS = 100; $NEXTID = 0 if $NEXTID eq ''; # Find a new ID to use by the simple expedient of cycling # through a numeric list. In a real application, the ID # should be unique, and maintained in a most-frequently-used cache. sub new { my($package) = @_; $NEXTID=0 if $NEXTID > $MAX_SESSIONS; my $self = bless { name => '', article => '', page => 0, id => $NEXTID++ },$package; return $self; } sub fetch { my ($package,$id) = @_; return undef if $id eq ''; return $SESSIONS{$id}; } sub save { my $self = shift; $SESSIONS{$self->{id}} = $self; } sub id { $_[0]->{id}; } sub name { $_[0]->{name} = $_[1] if defined($_[1]); $_[0]->{name}; } sub article { $_[0]->{article} = $_[1] if defined($_[1]); $_[0]->{article}; } sub page { $_[0]->{page} = $_[1] if defined($_[1]); $_[0]->{page} = 0 if $_[0]->{page} < 0; $_[0]->{page}; } 1;