1# Session IDs: The data to maintain them, and accessors to get at them 2# sanely from other files. 3 4package POE::Resource::SIDs; 5 6use vars qw($VERSION); 7$VERSION = '1.368'; # NOTE - Should be #.### (three decimal places) 8 9# These methods are folded into POE::Kernel; 10package POE::Kernel; 11 12use strict; 13 14### Map session IDs to sessions. Map sessions to session IDs. 15### Maintain a sequence number for determining the next session ID. 16 17my %kr_session_ids; 18# ( $session_id => $session_reference, 19# ..., 20# ); 21 22my $kr_sid_seq = 0; 23 24sub _data_sid_initialize { 25 $poe_kernel->[KR_SESSION_IDS] = \%kr_session_ids; 26 $poe_kernel->[KR_SID_SEQ] = \$kr_sid_seq; 27} 28 29sub _data_sid_relocate_kernel_id { 30 my ($self, $old_id, $new_id) = @_; 31 $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 37sub _data_sid_finalize { 38 my $finalized_ok = 1; 39 while (my ($sid, $ses) = each(%kr_session_ids)) { 40 _warn "!!! Leaked session ID: $sid = $ses\n"; 41 $finalized_ok = 0; 42 } 43 return $finalized_ok; 44} 45 46### Allocate a new session ID. 47 48sub _data_sid_allocate { 49 my $self = shift; 50 1 while exists $kr_session_ids{++$kr_sid_seq}; 51 return $kr_sid_seq; 52} 53 54### Set a session ID. 55 56sub _data_sid_set { 57 my ($self, $sid, $session) = @_; 58 $kr_session_ids{$sid} = $session; 59} 60 61### Clear a session ID. 62 63sub _data_sid_clear { 64 my ($self, $sid) = @_; 65 66 return delete $kr_session_ids{$sid} unless ASSERT_DATA; 67 68 my $removed = delete $kr_session_ids{$sid}; 69 _trap("unknown SID '$sid'") unless defined $removed; 70 $removed; 71} 72 73### Resolve a session ID into its session. 74 75sub _data_sid_resolve { 76 my ($self, $sid) = @_; 77 return $kr_session_ids{$sid}; 78} 79 801; 81 82__END__ 83 84=head1 NAME 85 86POE::Resource::SIDs - internal session ID manager for POE::Kernel 87 88=head1 SYNOPSIS 89 90There is no public API. 91 92=head1 DESCRIPTION 93 94POE::Resource::SIDs is a mix-in class for POE::Kernel. It provides 95the features necessary to manage session IDs. It is used internally 96by POE::Kernel, so it has no public interface. 97 98=head1 SEE ALSO 99 100See L<POE::Kernel/Session Identifiers (IDs and Aliases)> for more 101information about session IDs. 102 103See L<POE::Kernel/Resources> for public information about POE 104resources. 105 106See L<POE::Resource> for general discussion about resources and the 107classes that manage them. 108 109=head1 BUGS 110 111None known. 112 113=head1 AUTHORS & COPYRIGHTS 114 115Please see L<POE> for more information about authors and contributors. 116 117=cut 118 119# rocco // vim: ts=2 sw=2 expandtab 120# TODO - Edit. 121