|
0 package PageSession;
1
2 use vars qw($NEXTID $MAXSESSIONS %SESSIONS);
3 $MAX_SESSIONS = 100;
4
5 $NEXTID = 0 if $NEXTID eq '';
6
7 # Find a new ID to use by cycling through a numeric list.
8 # In a real application, the ID should be unique, and
9 # maintained in a most-frequently-used cache.
10 sub new {
11 my($package) = @_;
12 $NEXTID=0 if $NEXTID > $MAX_SESSIONS;
13 my $self = bless {
14 name => '',
15 article => '',
16 page => 0,
17 id => $NEXTID++
18 }, $package;
19 return $self;
20 }
21
22 sub fetch {
23 my ($package,$id) = @_;
24 return undef if $id eq '';
25 return $SESSIONS{$id};
26 }
27
28 sub save {
29 my $self = shift;
30 $SESSIONS{$self->{id}} = $self;
31 }
32
33 sub id { $_[0]->{id}; }
34 sub name { $_[0]->{name} = $_[1] if defined($_[1]);
$_[0]->{name}; }
35 sub article { $_[0]->{article} = $_[1] if defined($_[1]);
$_[0]->{article}; }
36 sub page {
37 $_[0]->{page} = $_[1] if defined($_[1]);
38 $_[0]->{page} = 0 if $_[0]->{page} < 0;
39 $_[0]->{page};
40 }
41
42 1;
|
|