home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _8f25c6c8889ce213439e77d9985bd5f4 < prev    next >
Encoding:
Text File  |  2004-06-01  |  1.2 KB  |  65 lines

  1.  
  2. =head1 NAME
  3.  
  4. Tk::Event - ToolKit for Events
  5.  
  6. =for category Implementation
  7.  
  8. =head1 SYNOPSIS
  9.  
  10.  use Tk::Event;
  11.  
  12.  Tk::Event->fileevent(\*FH, 'readable' => callback);
  13.  
  14.  Tk::Event->lineavail(\*FH, callback);
  15.  
  16.  use Tk::Event::Signal qw(INT);
  17.  
  18.  $SIG{'INT'} = callback;
  19.  
  20.  use Tk::Event::process;
  21.  
  22.  Tk::Event->proc($pid, callback);
  23.  
  24.  QueueEvent(callback [, position])
  25.  
  26.  
  27. =head1 DESCRIPTION
  28.  
  29.  
  30. That is better than nothing but still hard to use. Most scripts want higher
  31. level result (a line, a "block" of data etc.)
  32.  
  33. So it has occured to me that we could use new-ish TIEHANDLE thus:
  34.  
  35. my $obj = tie SOMEHANDLE,Tk::Event::IO;
  36.  
  37. while (<SOMEHANDLE>)
  38.  {
  39.  }
  40.  
  41. Then the READLINE routine registers a callback and looks something like:
  42.  
  43. sub READLINE
  44.  {
  45.   my $obj = shift;
  46.   Event->io(*$obj,'readable',sub { sysread(*$obj,${*$obj},1,length(${*$obj}) });
  47.   my $pos;
  48.   while (($pos = index(${*$obj},$/) < 0)
  49.    {
  50.     DoOneEvent();
  51.    }
  52.   Event->io(*$obj,'readable',''); # unregister
  53.   $pos += length($/);
  54.   my $result = substr(${*$obj},0,$pos);
  55.   substr(${*$obj},0,$pos) = '';
  56.   return $result;
  57.  }
  58.  
  59. This is using the scalar part of the glob representing the _inner_ IO
  60. as a buffer in which to accumulate chars.
  61.  
  62.  
  63.  
  64.  
  65.