Eventloop(3pm)
π Eventloop β Tk::Event π
okay so bestie, this is the manual page for Tk::Event (it lives in the perl manual pages, section 3pm, user contributed). The whole vibe is ToolKit for Events. yes that's the actual name. it's giving "we named it in a hurry but it slaps." π
β¨ SYNOPSIS β¨
here's the whole thing, verbatim, no notes:
use Tk::Event;
Tk::Event->fileevent(\*FH, 'readable' => callback);
Tk::Event->lineavail(\*FH, callback);
use Tk::Event::Signal qw(INT);
$SIG{'INT'} = callback;
use Tk::Event::process;
Tk::Event->proc($pid, callback);
QueueEvent(callback [, position])
QueueEventtakes acallbackand an optionalpositionin that bracket situation, and yeah the brackets are literal, that's how it's written, i don't make the rules. π
πΈ DESCRIPTION πΈ
so the tea is: that whole thing up there? better than nothing. but honestly bestie it's still hard to use. π like, lowkey painful. most scripts don't want raw events, they want the higher level result β a line, a "block" of data, etc. that's the dream. that's the goal.
so it has occured to me (yes, "occured", i'm quoting the original spelling, no cap, leave it alone π«Ά) that we could use the new-ish TIEHANDLE thus:
my $obj = tie SOMEHANDLE,Tk::Event::IO;
while (<SOMEHANDLE>)
{
}
then the READLINE routine registers a callback and looks something like:
sub READLINE
{
my $obj = shift;
Event->io(*$obj,'readable',sub { sysread(*$obj,${*$obj},1,length(${*$obj}) });
my $pos;
while (($pos = index(${*$obj},$/) < 0)
{
DoOneEvent();
}
Event->io(*$obj,'readable',''); # unregister
$pos += length($/);
my $result = substr(${*$obj},0,$pos);
substr(${*$obj},0,$pos) = '';
return $result;
}
and this is the iconic part, the main character move β¨: it's using the scalar part of the glob representing the _inner_ IO as a buffer in which to accumulate chars. that's it. that's the whole trick. obsessed. π
π a lil sign-off π
this page is from perl v5.40.1, dated 2025-04-13, and it's filed under User Contributed Perl Documentation β which is exactly where all the fun stuff lives tbh. π¦ go forth and event-loop, bestie. periodt. π
π¦ where this page comes from
- debian trixie: perl-tk 1:804.036+dfsg1-5
- ubuntu questing: perl-tk 1:804.036+dfsg1-5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms