File Coverage

blib/lib/POE/Resource/SIDs.pm
Criterion Covered Total %
statement 23 27 85.1
branch 3 4 75.0
condition n/a
subroutine 8 9 88.8
pod n/a
total 34 40 85.0


line stmt bran cond sub pod time code
1             # Session IDs: The data to maintain them, and accessors to get at them
2             # sanely from other files.
3              
4             package POE::Resource::SIDs;
5              
6 176     176   787 use vars qw($VERSION);
  176         245  
  176         9411  
7             $VERSION = '1.366'; # NOTE - Should be #.### (three decimal places)
8              
9             # These methods are folded into POE::Kernel;
10             package POE::Kernel;
11              
12 176     176   906 use strict;
  176         236  
  176         52622  
13              
14             ### Map session IDs to sessions. Map sessions to session IDs.
15             ### Maintain a sequence number for determining the next session ID.
16              
17             my %kr_session_ids;
18             # ( $session_id => $session_reference,
19             # ...,
20             # );
21              
22             my $kr_sid_seq = 0;
23              
24             sub _data_sid_initialize {
25 0     0   0 $poe_kernel->[KR_SESSION_IDS] = \%kr_session_ids;
26 0         0 $poe_kernel->[KR_SID_SEQ] = \$kr_sid_seq;
27             }
28              
29             sub _data_sid_relocate_kernel_id {
30 4     4   19 my ($self, $old_id, $new_id) = @_;
31 4 50       59 $kr_session_ids{$new_id} = delete $kr_session_ids{$old_id}
32             if exists $kr_session_ids{$old_id};
33             }
34              
35             ### End-run leak checking.
36              
37             sub _data_sid_finalize {
38 191     191   473 my $finalized_ok = 1;
39 191         1142 while (my ($sid, $ses) = each(%kr_session_ids)) {
40 0         0 _warn "!!! Leaked session ID: $sid = $ses\n";
41 0         0 $finalized_ok = 0;
42             }
43 191         339 return $finalized_ok;
44             }
45              
46             ### Allocate a new session ID.
47              
48             sub _data_sid_allocate {
49 821     821   2864 my $self = shift;
50 821         2833 1 while exists $kr_session_ids{++$kr_sid_seq};
51 821         2195 return $kr_sid_seq;
52             }
53              
54             ### Set a session ID.
55              
56             sub _data_sid_set {
57 1265     1265   2645 my ($self, $sid, $session) = @_;
58 1265         3396 $kr_session_ids{$sid} = $session;
59             }
60              
61             ### Clear a session ID.
62              
63             sub _data_sid_clear {
64 792     792   1628 my ($self, $sid) = @_;
65              
66 792         909 return delete $kr_session_ids{$sid} unless ASSERT_DATA;
67              
68 710         1743 my $removed = delete $kr_session_ids{$sid};
69 710 100       1613 _trap("unknown SID '$sid'") unless defined $removed;
70 709         1287 $removed;
71             }
72              
73             ### Resolve a session ID into its session.
74              
75             sub _data_sid_resolve {
76 213     213   292 my ($self, $sid) = @_;
77 213         498 return $kr_session_ids{$sid};
78             }
79              
80             1;
81              
82             __END__