in reply to MainLoop in Perl Module

Before you go down a road, it's good to look at the skeletons and gravestones by the wayside.

Also, the question of what to use instead of a mainloop remains. Of course you can (try to) use threads and messaging instead of separate mainloops, but you'll find that Gtk2 (for example) doesn't play well when run in a thread that is not the main thread, and so do other "mainloop implementors".

Replies are listed 'Best First'.
Re^2: MainLoop in Perl Module
by james2vegas (Chaplain) on Sep 01, 2009 at 11:39 UTC
    There exist modules to combine some combinations of EV, Event and Glib: EV::Glib, Glib::EV and Glib::Event.

    Also AnyEvent is a way to write event-loop neutral modules (supporting at least Tk, Glib2, POE, EV, Event, IO::Async and a pure perl event loop). This is similar to how POE::Loop works, but EV is an event-loop of its own. An ugly and hackish way of combiining multiple loops would be to single step through event loop 2's events on event loop 1's idle callback or on a timer (most event loops support processing their pending events one at a time instead of running their mainloop directly).

    Update: Another possibility for adding EV loops to other event-loop using modules is EV::Loop::Async, which lets you embed an mod:://EV loop into code using a different mainloop with Async::Interrupt, which allows asynchronous interruption of running perl code with through the signal mechanism.

Re^2: MainLoop in Perl Module
by ambrus (Abbot) on Sep 01, 2009 at 11:03 UTC

    Or, you know, Coro if you don't want to mess with event-oriented programming. Sometimes one is easier, sometimes the other.