1Eventloop(3)          User Contributed Perl Documentation         Eventloop(3)
2
3
4

NAME

6       Tk::Event - ToolKit for Events
7

SYNOPSIS

9        use Tk::Event;
10
11        Tk::Event->fileevent(\*FH, 'readable' => callback);
12
13        Tk::Event->lineavail(\*FH, callback);
14
15        use Tk::Event::Signal qw(INT);
16
17        $SIG{'INT'} = callback;
18
19        use Tk::Event::process;
20
21        Tk::Event->proc($pid, callback);
22
23        QueueEvent(callback [, position])
24

DESCRIPTION

26       That is better than nothing but still hard to use. Most scripts want
27       higher level result (a line, a "block" of data etc.)
28
29       So it has occured to me that we could use new-ish TIEHANDLE thus:
30
31        my $obj = tie SOMEHANDLE,Tk::Event::IO;
32
33        while (<SOMEHANDLE>)
34         {
35         }
36
37       Then the READLINE routine registers a callback and looks something
38       like:
39
40        sub READLINE
41         {
42          my $obj = shift;
43          Event->io(*$obj,'readable',sub { sysread(*$obj,${*$obj},1,length(${*$obj}) });
44          my $pos;
45          while (($pos = index(${*$obj},$/) < 0)
46           {
47            DoOneEvent();
48           }
49          Event->io(*$obj,'readable',''); # unregister
50          $pos += length($/);
51          my $result = substr(${*$obj},0,$pos);
52          substr(${*$obj},0,$pos) = '';
53          return $result;
54         }
55
56       This is using the scalar part of the glob representing the _inner_ IO
57       as a buffer in which to accumulate chars.
58
59
60
61perl v5.36.0                      2022-07-22                      Eventloop(3)
Impressum