use AnyEvent; use Tk;
# this module gets loaded automatically as required
Tk is buggy. Tk is extremely buggy. Tk is so unbelievably buggy that for each bug reported and fixed, you get one new bug followed by reintroduction of the old bug in a later revision. I regularly run out of words to describe how bad it really is.
To work around the many, many bugs in Tk that don't get fixed, this adaptor dup()'s all filehandles that get passed into its I/O watchers, so if you register a read and a write watcher for one fh, AnyEvent will create two additional file descriptors (and handles).
This creates a high overhead and is slow, but seems to work around all known bugs in Tk::fileevent.
To be able to access the Tk event loop, this module creates a main window and withdraws it immediately. This might cause flickering on some platforms, but Tk perversely requires a window to be able to wait for file handle readyness notifications. This window is always created (in this version of AnyEvent) and can be accessed as $AnyEvent::Impl::Tk::mw.
Marc Lehmann <firstname.lastname@example.org> http://home.schmorp.de/