Event-driven programs need some sort of loop which watches for events and launches the appropriate actions. Glib::MainLoop provides this functionality.
Mainloops have context, provided by the MainContext object. For the most part you can use the default context (see default), but if you want to create a subcontext for a nested loop which doesn't have the same event sources, etc, you can.
default
Event sources, attached to main contexts, watch for events to happen, and launch appropriate actions. Glib provides a few ready-made event sources, the Glib::Timeout, Glib::Idle, and io watch (Glib::IO->add_watch).
Glib::IO->add_watch
Under the hood, Gtk+ adds event sources for GdkEvents to dispatch events to your widgets. In fact, Gtk2 provides an abstraction of Glib::MainLoop (See Gtk2->main and friends), so you may rarely have cause to use Glib::MainLoop directly.
Gtk2->main
Remove an event source. $tag is the number returned by things like Glib::Timeout->add, Glib::Idle->add, and Glib::IO->add_watch.
Glib::Timeout->add
Glib::Idle->add
Run $callback every $interval milliseconds until $callback returns false. Returns a source id which may be used with Glib::Source->remove. Note that a mainloop must be active for the timeout to execute.
Glib::Source->remove
Run $callback when the mainloop is idle. If $callback returns false, it will uninstall itself, otherwise, it will run again at the next idle iteration. Returns a source id which may be used with Glib::Source->remove.
Run $callback when there is an event on $fd that matches $condition. The watch uninstalls itself if $callback returns false. Returns a source id that may be used with Glib::Source->remove.
Glib's IO channels serve the same basic purpose as Perl's file handles, so for the most part you don't see GIOChannels in Perl. The IO watch integrates IO operations with the main loop, which Perl file handles don't do. For various reasons, this function requires raw file descriptors, not full file handles. See fileno in perlfunc.
fileno
To install Glib, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Glib
CPAN shell
perl -MCPAN -e shell install Glib
For more information on module installation, please visit the detailed CPAN module installation guide.