Mojo::Reactor::Glib - Glib::MainLoop backend for Mojo
Version 0.002
I hope I need not to emphasise that this is in VERY EARLY STAGES OF DEVELOPMENT.
Mojo::Reactor::Glib is a backend for Mojo::Reactor, build on top of the Glib main loop, allowing you to use various Mojo(licious) modules within a Glib or Gtk program.
BEGIN { $ENV{MOJO_REACTOR} = 'Mojo::Reactor::Glib'; } use Gtk2 -init; use Mojo::UserAgent; my $ua = Mojo::UserAgent->new(); Glib::Timeout->add(1000, sub { $ua->get('http://example.com/' => sub { my ($ua, $tx) = @_; say $tx->res->body; }); return Glib::SOURCE_CONTINUE; }); Gtk2->main();
Just the constructor. You probably won't ever call it yourself.
Runs the timer known by $id again
$id
Assigns a callback function $cb to the IO handle $handle. This is required before you can use watch.
$cb
$handle
Returns the reactor $r so you can chain the calls.
$r
Returns true if the loop is running, otherwise returns false
Does a single Glib::MainLoop iteration. Returns true if events were dispatched during this iteration (whether or not they had been Mojo::Reactor::Glib events), false if nothing happened.
Starts a recurring timer that beats every $after_sec seconds (N.B. Glib allows for millisecond granularity), which will result in $cb being fired.
$after_sec
Returns the Glib::Timeout ID that you can use to stop the timer.
See also timer
Removes the timer identified by $id, returning true if this was successful, and a false-ish value otherwise.
Stops all timers and watches.
Starts the loop if it isn't already running.
Stops the loop.
Starts a one-shot timer that beats after $after_sec seconds (N.B. Glib allows for millisecond granularity), which will result in $cb being fired.
Returns the Glib::Timeout ID that you can use to stop or again the timer.
See also recurring.
Adds an IO watch for $read or $write (booleans) on $handle. If both $read and $write are false, it removes the watch.
$read
$write
Requires io to be run on $handle first, as that associates the callback function with the handle.
See also io.
Ralesk <ralesk at cpan.org>
<ralesk at cpan.org>
Please report issues at https://bitbucket.org/ralesk/mojo-reactor-glib/issues
Breaks on Win32, Mojo::UserAgent can't do non-blocking calls at least.
Can't latch onto an existing Gtk event loop (no API for that), not sure if we actually should be able to or if we're good here in a sub-loop.
Copyright (C) 2014 Henrik Pauli
This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License (2.0). You may obtain a copy of the full licence at:
http://www.perlfoundation.org/artistic_license_2_0
To install Mojo::Reactor::Glib, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::Reactor::Glib
CPAN shell
perl -MCPAN -e shell install Mojo::Reactor::Glib
For more information on module installation, please visit the detailed CPAN module installation guide.