line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package POE::XUL::SessionManager; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1368
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
5
|
1
|
|
|
1
|
|
10
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
80
|
|
6
|
1
|
|
|
1
|
|
7
|
use Digest::MD5 qw(md5_base64); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
7
|
1
|
|
|
1
|
|
637
|
use POE::XUL::Session; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use base 'Exporter'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw(BOOT_REQUEST_TYPE EVENT_REQUEST_TYPE); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use constant { |
14
|
|
|
|
|
|
|
BOOT_REQUEST_TYPE => 'boot', |
15
|
|
|
|
|
|
|
EVENT_REQUEST_TYPE => 'event', |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# public ---------------------------------------------------------------------- |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
|
|
|
|
|
|
my $class = shift; |
22
|
|
|
|
|
|
|
my $self = bless({ |
23
|
|
|
|
|
|
|
sessions => {}, |
24
|
|
|
|
|
|
|
@_, |
25
|
|
|
|
|
|
|
}, $class); |
26
|
|
|
|
|
|
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub handle_request { |
30
|
|
|
|
|
|
|
my ($self, $request) = @_; |
31
|
|
|
|
|
|
|
my $type = delete $request->{type} || croak "no request type"; |
32
|
|
|
|
|
|
|
my $method = 'handle_request_'.( |
33
|
|
|
|
|
|
|
$type eq BOOT_REQUEST_TYPE ? 'boot' : |
34
|
|
|
|
|
|
|
$type eq EVENT_REQUEST_TYPE? 'event': |
35
|
|
|
|
|
|
|
croak "unknown request type: $type" |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
return $self->$method($request); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub timeout_session { |
41
|
|
|
|
|
|
|
my ($self, $session_id) = @_; |
42
|
|
|
|
|
|
|
my $session = $self->get_session($session_id) || |
43
|
|
|
|
|
|
|
croak "session not found: [$session_id]"; |
44
|
|
|
|
|
|
|
$session->destroy; |
45
|
|
|
|
|
|
|
delete $self->sessions->{$session_id}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# request handling ------------------------------------------------------------ |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub handle_request_boot { |
51
|
|
|
|
|
|
|
my ($self, $request) = @_; |
52
|
|
|
|
|
|
|
my $session = POE::XUL::Session->new(apps => $self->{apps}); |
53
|
|
|
|
|
|
|
my $session_id = $self->make_session_id; |
54
|
|
|
|
|
|
|
$request->{session} = $session_id; |
55
|
|
|
|
|
|
|
# we 1st boot, so in case of error session is not registered |
56
|
|
|
|
|
|
|
my $response = "$session_id\n". $session->handle_boot($request); |
57
|
|
|
|
|
|
|
# now we can register session |
58
|
|
|
|
|
|
|
$self->sessions->{$session_id} = $session; |
59
|
|
|
|
|
|
|
return $response; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub handle_request_event { |
63
|
|
|
|
|
|
|
my ($self, $request) = @_; |
64
|
|
|
|
|
|
|
my $session_id = $request->{session} || croak "no session ID"; |
65
|
|
|
|
|
|
|
my $session = $self->get_session($session_id) || |
66
|
|
|
|
|
|
|
croak "session not found: [$session_id]"; |
67
|
|
|
|
|
|
|
return $session->handle_event($request,$self); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# private --------------------------------------------------------------------- |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# stolen from CGI::Session::ID::MD5 |
73
|
|
|
|
|
|
|
sub make_session_id { |
74
|
|
|
|
|
|
|
my $self = shift; |
75
|
|
|
|
|
|
|
my $id = md5_base64($$, time, rand(9999)); |
76
|
|
|
|
|
|
|
return $id; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub sessions { shift->{sessions} } |
80
|
|
|
|
|
|
|
sub get_session { shift->sessions->{pop()} } |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|