Tk::Event - ToolKit for Events
=for category Implementation
Tk::Event->fileevent(\*FH, 'readable' => callback);
Tk::Event->lineavail(\*FH, callback);
use Tk::Event::Signal qw(INT);
Tk::Event->proc($pid, callback);
QueueEvent(callback [, position])
That is better than nothing but still hard to use. Most scripts want higher
level result (a line, a "block" of data etc.)
So it has occured to me that we could use new-ish TIEHANDLE thus:
my $obj = tie SOMEHANDLE,Tk::Event::IO;
Then the READLINE routine registers a callback and looks something like:
Event->io(*$obj,'readable',sub { sysread(*$obj,${*$obj},1,length(${*$obj}) });
while (($pos = index(${*$obj},$/) < 0)
Event->io(*$obj,'readable',''); # unregister
my $result = substr(${*$obj},0,$pos);
substr(${*$obj},0,$pos) = '';
This is using the scalar part of the glob representing the _inner_ IO
as a buffer in which to accumulate chars.