line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenFrame::AppKit::Session; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2103
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings::register; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
286
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
900
|
use Cache::FileCache; |
|
1
|
|
|
|
|
81352
|
|
|
1
|
|
|
|
|
56
|
|
7
|
1
|
|
|
1
|
|
12
|
use Digest::MD5 qw(md5_hex); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
432
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION=3.03; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
1
|
|
|
1
|
1
|
11
|
my $class = shift; |
13
|
1
|
|
|
|
|
2
|
my $self = {}; |
14
|
1
|
|
|
|
|
3
|
bless $self, $class; |
15
|
1
|
|
|
|
|
6
|
$self->init(); |
16
|
1
|
|
|
|
|
7
|
return $self; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub init { |
20
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
21
|
1
|
|
|
|
|
4
|
$self->generate_id; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub id { |
25
|
3
|
|
|
3
|
1
|
379
|
my $self = shift; |
26
|
3
|
|
|
|
|
28
|
return $self->{_id}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub generate_id { |
30
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
31
|
1
|
50
|
|
|
|
7
|
return $self->{_id} if exists $self->{_id}; |
32
|
1
|
|
|
|
|
72
|
my $id = substr(md5_hex(time() . md5_hex(time(). {}. rand(). $$)), 0, 16); |
33
|
1
|
|
|
|
|
5
|
$self->{_id} = $id; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub store { |
37
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
38
|
1
|
|
|
|
|
9
|
Cache::FileCache->new()->set( $self->id, $self ); |
39
|
1
|
|
|
|
|
2035
|
return $self->id; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub fetch { |
43
|
1
|
|
|
1
|
1
|
2
|
my $class = shift; |
44
|
1
|
|
|
|
|
3
|
my $id = shift; |
45
|
1
|
|
|
|
|
6
|
return Cache::FileCache->new()->get( $id ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub get { |
49
|
2
|
|
|
2
|
1
|
2
|
my $self = shift; |
50
|
2
|
|
|
|
|
5
|
my $key = shift; |
51
|
2
|
|
|
|
|
10
|
return $self->{ $key }; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub set { |
55
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
56
|
1
|
|
|
|
|
2
|
my $key = shift; |
57
|
1
|
|
|
|
|
3
|
$self->{ $key } = shift; |
58
|
1
|
|
|
|
|
4
|
return $self; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 NAME |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
OpenFrame::AppKit::Session - sessions for OpenFrame |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 SYNOPSIS |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
use OpenFrame::AppKit::Session; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $session = OpenFrame::AppKit::Session->new(); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $id = $session->id(); |
74
|
|
|
|
|
|
|
$session->store(); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $restored = OpenFrame::AppKit::Session->fetch( $id ); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 DESCRIPTION |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
OpenFrame::AppKit::Session provides a session class that is capable of |
81
|
|
|
|
|
|
|
being stored and restored from disk. The session expects you to treat |
82
|
|
|
|
|
|
|
it as a standard HASH for all intents and purposes, but does allow you |
83
|
|
|
|
|
|
|
to encapsulate that with the methods get and set for top level keys. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 METHODS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=over 4 |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item * new |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
The C method instantiates a new OpenFrame::AppKit::Session and returns |
92
|
|
|
|
|
|
|
it. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item * init |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
The C method provides initialization routines for OpenFrame::AppKit::Session |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item * id |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
The C method returns the sessions id |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item * generate_id |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
The C method returns a new id, or the old id if it has already been generated. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item * store |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
The C method serializes the session to disk. It returns the session id that can be |
109
|
|
|
|
|
|
|
used to restore the session. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item * fetch |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
The C method takes a session id as a parameter and returns a restored session from disk. |
114
|
|
|
|
|
|
|
In the case that the session is unavailable it returns nothing. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item * get |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
The C method simply returns a key as specified by the first parameter and returns its value. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * set |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
The C method simply sets a key value pair as specified by the first two parameters. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=back |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 SEE ALSO |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
OpenFrame::AppKit::Segment::Sesssion |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 AUTHOR |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
James A. Duncan |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 COPYRIGHT |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Copyright 2002 Fotango Ltd. All Rights Reserved |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
This program is released under the same license as Perl itself. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |