home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / SIDs.pm < prev    next >
Encoding:
Perl POD Document  |  2004-01-21  |  2.5 KB  |  119 lines

  1. # $Id: SIDs.pm,v 1.9 2004/01/21 05:28:15 rcaputo Exp $
  2.  
  3. # Session IDs: The data to maintain them, and accessors to get at them
  4. # sanely from other files.
  5.  
  6. package POE::Resources::SIDs;
  7.  
  8. use vars qw($VERSION);
  9. $VERSION = do {my@r=(q$Revision: 1.9 $=~/\d+/g);sprintf"%d."."%04d"x$#r,@r};
  10.  
  11. # These methods are folded into POE::Kernel;
  12. package POE::Kernel;
  13.  
  14. use strict;
  15.  
  16. ### Map session IDs to sessions.  Map sessions to session IDs.
  17. ### Maintain a sequence number for determining the next session ID.
  18.  
  19. my %kr_session_ids;
  20. #  ( $session_id => $session_reference,
  21. #    ...,
  22. #  );
  23.  
  24. my %kr_session_to_id;
  25. #  ( $session_ref => $session_id,
  26. #    ...,
  27. #  );
  28.  
  29. my $kr_sid_seq = 1;
  30.  
  31. sub _data_sid_initialize {
  32.   $poe_kernel->[KR_SESSION_IDS] = \%kr_session_ids;
  33.   $poe_kernel->[KR_SID_SEQ] = \$kr_sid_seq;
  34. }
  35. use POE::API::ResLoader \&_data_sid_initialize;
  36.  
  37. ### End-run leak checking.
  38.  
  39. sub _data_sid_finalize {
  40.   my $finalized_ok = 1;
  41.   while (my ($sid, $ses) = each(%kr_session_ids)) {
  42.     _warn "!!! Leaked session ID: $sid = $ses\n";
  43.     $finalized_ok = 0;
  44.   }
  45.   while (my ($ses, $sid) = each(%kr_session_to_id)) {
  46.     _warn "!!! Leak sid cross-reference: $ses = $sid\n";
  47.     $finalized_ok = 0;
  48.   }
  49.   return $finalized_ok;
  50. }
  51.  
  52. ### Allocate a new session ID.
  53.  
  54. sub _data_sid_allocate {
  55.   my $self = shift;
  56.   1 while exists $kr_session_ids{++$kr_sid_seq};
  57.   return $kr_sid_seq;
  58. }
  59.  
  60. ### Set a session ID.
  61.  
  62. sub _data_sid_set {
  63.   my ($self, $sid, $session) = @_;
  64.   $kr_session_ids{$sid} = $session;
  65.   $kr_session_to_id{$session} = $sid;
  66. }
  67.  
  68. ### Clear a session ID.
  69.  
  70. sub _data_sid_clear {
  71.   my ($self, $session) = @_;
  72.   my $sid = delete $kr_session_to_id{$session};
  73.   if (ASSERT_DATA) {
  74.     _trap("SID not defined") unless defined $sid;
  75.   }
  76.   delete $kr_session_ids{$sid};
  77. }
  78.  
  79. ### Resolve a session ID into its session.
  80.  
  81. sub _data_sid_resolve {
  82.   my ($self, $sid) = @_;
  83.   return $kr_session_ids{$sid};
  84. }
  85.  
  86. 1;
  87.  
  88. __END__
  89.  
  90. =head1 NAME
  91.  
  92. POE::Resources::SIDs - session ID management for POE::Kernel
  93.  
  94. =head1 SYNOPSIS
  95.  
  96. Used internally by POE::Kernel.  Better documentation will be
  97. forthcoming.
  98.  
  99. =head1 DESCRIPTION
  100.  
  101. This module encapsulates and provides accessors for POE::Kernel's data
  102. structures that manage session IDs.  It is used internally by
  103. POE::Kernel and has no public interface.
  104.  
  105. =head1 SEE ALSO
  106.  
  107. See L<POE::Kernel> and L<POE::Session> for documentation about session
  108. IDs.
  109.  
  110. =head1 BUGS
  111.  
  112. Probably.
  113.  
  114. =head1 AUTHORS & COPYRIGHTS
  115.  
  116. Please see L<POE> for more information about authors and contributors.
  117.  
  118. =cut
  119.