IO-Async-Loop-Glib-0.22000755001750001750 013654310672 13331 5ustar00leoleo000000000000IO-Async-Loop-Glib-0.22/Build.PL000444001750001750 101513654310672 14757 0ustar00leoleo000000000000use strict; use warnings; use Module::Build; my $build = Module::Build->new( module_name => 'IO::Async::Loop::Glib', requires => { 'Glib' => 0, 'IO::Async::Loop' => '0.49', 'Time::HiRes' => 0, }, test_requires => { 'IO::Async::LoopTests' => '0.76', 'Test::More' => '0.88', # done_testing }, configure_requires => { 'Module::Build' => '0.4004', # test_requires }, license => 'perl', create_license => 1, create_readme => 1, ); $build->create_build_script; IO-Async-Loop-Glib-0.22/Changes000444001750001750 324113654310672 14761 0ustar00leoleo000000000000Revision history for IO-Async-Loop-Glib 0.22 2020-05-05 [CHANGES] * Support IO::Async 0.76 + ->watch_child API is now called ->watch_process 0.21 CHANGES: * Implement the iO::Async 0.49 Loop API - watch_time/unwatch_time * Implement watch_child on specific PIDs using native GLib child watches * Bugfixes for pipe HUP and $context->iteration early returns 0.20 CHANGES: * Optionally implement watch_io on_hangup (only on Linux) * Fix use of Time::HiRes::time() - Loop has a ->time method directly * Added some IO::Async + Glib sharing unit tests 0.19 CHANGES: * Updated for IO::Async 0.33 0.18 CHANGES: * Use Time::HiRes for timing accuracy * Added two small Gtk2-based examples BUGFIXES: * Clamp negative timer intervals to 0 - fixes RT 53281 0.17 CHANGES: * Updated for IO-Async 0.24 * Use shared acceptance testing provided by IO::Async::LoopTests BUGFIXES: * Fixed a reference leak bug in enqueue_timer 0.16 CHANGES: * Various small updates to keep CPANTS happy 0.15 CHANGES: * Added 'use warnings' BUGFIXES: * Account for timing inaccuracies and race condition in timing tests 0.14 CHANGES: * Updated for IO-Async 0.20 0.13: CHANGES: * Implement interfaces required for IO::Async 0.17 * Deprecated class IO::Async::Set::GMainLoop now dies instantly BUGFIXES: * Be sure to watch for error conditions in Notifiers as well as normal IO 0.12 First version split out from IO-Async dist IO-Async-Loop-Glib-0.22/LICENSE000444001750001750 4376213654310672 14527 0ustar00leoleo000000000000This software is copyright (c) 2020 by Paul Evans . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2020 by Paul Evans . This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2020 by Paul Evans . This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End IO-Async-Loop-Glib-0.22/MANIFEST000444001750001750 47713654310672 14607 0ustar00leoleo000000000000Build.PL Changes examples/hello.pl examples/timer.pl lib/IO/Async/Loop/Glib.pm LICENSE MANIFEST This list of files META.json META.yml README t/00use.t t/01loop-io.t t/02loop-timer.t t/03loop-signal.t t/04loop-idle.t t/05loop-process.t t/06loop-control.t t/11share-io.t t/12share-timer.t t/15share-process.t t/99pod.t IO-Async-Loop-Glib-0.22/META.json000444001750001750 221213654310672 15104 0ustar00leoleo000000000000{ "abstract" : "use C with F or F", "author" : [ "Paul Evans " ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.4224", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "IO-Async-Loop-Glib", "prereqs" : { "configure" : { "requires" : { "Module::Build" : "0.4004" } }, "runtime" : { "requires" : { "Glib" : "0", "IO::Async::Loop" : "0.49", "Time::HiRes" : "0" } }, "test" : { "requires" : { "IO::Async::LoopTests" : "0.76", "Test::More" : "0.88" } } }, "provides" : { "IO::Async::Loop::Glib" : { "file" : "lib/IO/Async/Loop/Glib.pm", "version" : "0.22" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ] }, "version" : "0.22", "x_serialization_backend" : "JSON::PP version 4.04" } IO-Async-Loop-Glib-0.22/META.yml000444001750001750 134113654310672 14736 0ustar00leoleo000000000000--- abstract: 'use C with F or F' author: - 'Paul Evans ' build_requires: IO::Async::LoopTests: '0.76' Test::More: '0.88' configure_requires: Module::Build: '0.4004' dynamic_config: 1 generated_by: 'Module::Build version 0.4224, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: IO-Async-Loop-Glib provides: IO::Async::Loop::Glib: file: lib/IO/Async/Loop/Glib.pm version: '0.22' requires: Glib: '0' IO::Async::Loop: '0.49' Time::HiRes: '0' resources: license: http://dev.perl.org/licenses/ version: '0.22' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' IO-Async-Loop-Glib-0.22/README000444001750001750 346413654310672 14355 0ustar00leoleo000000000000NAME IO::Async::Loop::Glib - use IO::Async with Glib or GTK SYNOPSIS use IO::Async::Loop::Glib; my $loop = IO::Async::Loop::Glib->new(); $loop->add( ... ); ... # Rest of GLib/Gtk program that uses GLib Glib::MainLoop->new->run(); Or $loop->run; Or while(1) { $loop->loop_once(); } DESCRIPTION This subclass of IO::Async::Loop uses the Glib::MainLoop to perform read-ready and write-ready tests. The appropriate Glib::IO sources are added or removed from the Glib::MainLoop when notifiers are added or removed from the set, or when they change their want_writeready status. The callbacks are called automatically by Glib itself; no special methods on this loop object are required. CONSTRUCTOR new $loop = IO::Async::Loop::Glib->new() This function returns a new instance of a IO::Async::Loop::Glib object. It takes no special arguments. METHODS There are no special methods in this subclass, other than those provided by the IO::Async::Loop base class. loop_once $loop->loop_once( $timeout ) This method calls the iteration() method on the underlying Glib::MainContext. If a timeout value is supplied, then a Glib timeout will be installed, to interrupt the loop at that time. If Glib indicates that any callbacks were fired, then this method will return 1 (however, it does not mean that any IO::Async callbacks were invoked, as there may be other parts of code sharing the Glib main context. Otherwise, it will return 0. SEE ALSO * Glib - Perl wrappers for the GLib utility and Object libraries * Gtk2 - Perl interface to the 2.x series of the Gimp Toolkit library AUTHOR Paul Evans IO-Async-Loop-Glib-0.22/examples000755001750001750 013654310672 15147 5ustar00leoleo000000000000IO-Async-Loop-Glib-0.22/examples/hello.pl000444001750001750 60213654310672 16722 0ustar00leoleo000000000000#!/usr/bin/perl use strict; use warnings; use IO::Async::Loop::Glib; use IO::Async::Timer::Periodic; use Gtk2 -init; my $loop = IO::Async::Loop::Glib->new; my $dialog = Gtk2::MessageDialog->new( undef, 'destroy-with-parent', 'info', 'ok', "Hello world!" ); $dialog->signal_connect( response => sub { $loop->loop_stop; } ); $dialog->show_all; $loop->loop_forever; IO-Async-Loop-Glib-0.22/examples/timer.pl000444001750001750 155513654310672 16767 0ustar00leoleo000000000000#!/usr/bin/perl use strict; use warnings; use IO::Async::Loop::Glib; use IO::Async::Timer::Periodic; use Gtk2 -init; my $loop = IO::Async::Loop::Glib->new; my $dialog = Gtk2::MessageDialog->new( undef, 'destroy-with-parent', 'info', 'none', "Hello world!" ); $dialog->get_content_area->add( my $message = Gtk2::Label->new ); $loop->add( my $timer = IO::Async::Timer::Periodic->new( interval => 1, on_tick => sub { $message->set_text( "Time is now " . scalar localtime ) }, ) ); $dialog->add_button( "Start", 1 )->signal_connect( clicked => sub { $timer->start; } ); $dialog->add_button( "Stop", 2 )->signal_connect( clicked => sub { $timer->stop; $message->set_text( "" ); } ); $dialog->add_button( "Quit", 'close' )->signal_connect( clicked => sub { $loop->loop_stop } ); $dialog->show_all; $loop->loop_forever; IO-Async-Loop-Glib-0.22/lib000755001750001750 013654310672 14077 5ustar00leoleo000000000000IO-Async-Loop-Glib-0.22/lib/IO000755001750001750 013654310672 14406 5ustar00leoleo000000000000IO-Async-Loop-Glib-0.22/lib/IO/Async000755001750001750 013654310672 15463 5ustar00leoleo000000000000IO-Async-Loop-Glib-0.22/lib/IO/Async/Loop000755001750001750 013654310672 16374 5ustar00leoleo000000000000IO-Async-Loop-Glib-0.22/lib/IO/Async/Loop/Glib.pm000444001750001750 1726613654310672 20000 0ustar00leoleo000000000000# You may distribute under the terms of either the GNU General Public License # or the Artistic License (the same terms as Perl itself) # # (C) Paul Evans, 2007-2020 -- leonerd@leonerd.org.uk package IO::Async::Loop::Glib; use strict; use warnings; our $VERSION = '0.22'; use constant API_VERSION => '0.76'; use base qw( IO::Async::Loop ); IO::Async::Loop->VERSION( '0.49' ); use Carp; use Glib; =head1 NAME C - use C with F or F =head1 SYNOPSIS use IO::Async::Loop::Glib; my $loop = IO::Async::Loop::Glib->new(); $loop->add( ... ); ... # Rest of GLib/Gtk program that uses GLib Glib::MainLoop->new->run(); Or $loop->run; Or while(1) { $loop->loop_once(); } =head1 DESCRIPTION This subclass of C uses the C to perform read-ready and write-ready tests. The appropriate C sources are added or removed from the C when notifiers are added or removed from the set, or when they change their C status. The callbacks are called automatically by Glib itself; no special methods on this loop object are required. =cut =head1 CONSTRUCTOR =cut =head2 new $loop = IO::Async::Loop::Glib->new() This function returns a new instance of a C object. It takes no special arguments. =cut sub new { my $class = shift; my ( %args ) = @_; my $self = $class->__new( %args ); $self->{sourceid} = {}; # {$fd} -> [ $readid, $writeid, $hangupid ] return $self; } sub __new_feature { my $self = shift; my ( $classname ) = @_; # veto IO::Async::TimeQueue since we implement its methods locally die __PACKAGE__." implements $classname internally" if grep { $_ eq $classname } qw( IO::Async::TimeQueue ); return $self->SUPER::__new_feature( $classname ); } =head1 METHODS There are no special methods in this subclass, other than those provided by the C base class. =cut sub watch_io { my $self = shift; my %params = @_; my $handle = $params{handle} or croak "Expected 'handle'"; my $fd = $handle->fileno; # TODO: Investigate if the following can be made more efficient by # installing just one source on all the masks, and detecting the particular # event bits within the callback my $sourceids = ( $self->{sourceid}->{$fd} ||= [] ); if( my $on_read_ready = $params{on_read_ready} ) { Glib::Source->remove( $sourceids->[0] ) if defined $sourceids->[0]; $sourceids->[0] = Glib::IO->add_watch( $fd, ['in', 'hup', 'err'], sub { $on_read_ready->(); # Must yield true value or else GLib will remove this IO source return 1; } ); } if( my $on_write_ready = $params{on_write_ready} ) { Glib::Source->remove( $sourceids->[1] ) if defined $sourceids->[1]; $sourceids->[1] = Glib::IO->add_watch( $fd, ['out', 'hup', 'err'], sub { $on_write_ready->(); # Must yield true value or else GLib will remove this IO source return 1; } ); } if( my $on_hangup = $params{on_hangup} ) { $self->_CAN_ON_HANGUP or croak "Cannot watch_io for 'on_hangup' in ".ref($self); Glib::Source->remove( $sourceids->[2] ) if defined $sourceids->[2]; $sourceids->[2] = Glib::IO->add_watch( $fd, ['hup'], sub { $on_hangup->(); # Must yield true value or else GLib will remove this IO source return 1; } ); } } sub unwatch_io { my $self = shift; my %params = @_; my $handle = $params{handle} or croak "Expected 'handle'"; my $fd = $handle->fileno; my $sourceids = $self->{sourceid}->{$fd} or return; if( $params{on_read_ready} ) { Glib::Source->remove( $sourceids->[0] ) if defined $sourceids->[0]; undef $sourceids->[0]; } if( $params{on_write_ready} ) { Glib::Source->remove( $sourceids->[1] ) if defined $sourceids->[1]; undef $sourceids->[1]; } if( $params{on_hangup} ) { $self->_CAN_ON_HANGUP or croak "Cannot watch_io for 'on_hangup' in ".ref($self); Glib::Source->remove( $sourceids->[2] ) if defined $sourceids->[2]; undef $sourceids->[2]; } delete $self->{sourceids}->{$fd} if not $sourceids->[0] and not $sourceids->[1] and not $sourceids->[2]; } sub watch_time { my $self = shift; my ( %params ) = @_; # Just let GLib handle all these timer events my $delay; if( exists $params{at} ) { my $now = exists $params{now} ? $params{now} : $self->time; $delay = delete($params{at}) - $now; } elsif( exists $params{after} ) { $delay = delete $params{after}; } else { croak "Expected either 'at' or 'after' keys"; } my $interval = $delay * 1000; # miliseconds $interval = 0 if $interval < 0; # clamp or Glib gets upset my $code = delete $params{code}; ref $code eq "CODE" or croak "Expected 'code' to be a CODE reference"; my $id; my $callback = sub { $code->(); return 0; }; return Glib::Timeout->add( $interval, $callback ); } sub unwatch_time { my $self = shift; my ( $id ) = @_; Glib::Source->remove( $id ); return; } sub watch_process { my $self = shift; my ( $pid, $code ) = @_; if( $pid == 0 ) { return $self->SUPER::watch_process( @_ ); } my $processwatches = $self->{processwatches}; $processwatches->{$pid} = Glib::Child->watch_add( $pid, sub { $code->( $_[0], $_[1] ); delete $processwatches->{$pid}; return 0; }, ); } sub unwatch_process { my $self = shift; my ( $pid ) = @_; if( $pid == 0 ) { return $self->SUPER::unwatch_process( @_ ); } Glib::Source->remove( delete $self->{processwatches}{$pid} ); } sub watch_idle { my $self = shift; my %params = @_; my $code = delete $params{code}; ref $code eq "CODE" or croak "Expected 'code' to be a CODE reference"; my $when = delete $params{when} or croak "Expected 'when'"; $when eq "later" or croak "Expected 'when' to be 'later'"; return Glib::Idle->add( sub { $code->(); return 0 } ); } sub unwatch_idle { my $self = shift; my ( $id ) = @_; Glib::Source->remove( $id ); } =head2 loop_once $loop->loop_once( $timeout ) This method calls the C method on the underlying C. If a timeout value is supplied, then a Glib timeout will be installed, to interrupt the loop at that time. If Glib indicates that any callbacks were fired, then this method will return 1 (however, it does not mean that any C callbacks were invoked, as there may be other parts of code sharing the Glib main context. Otherwise, it will return 0. =cut sub loop_once { my $self = shift; my ( $timeout ) = @_; $self->_adjust_timeout( \$timeout, no_sigwait => 1 ); my $timed_out = 0; my $timerid; if( defined $timeout ) { my $interval = $timeout * 1000; # miliseconds $timerid = Glib::Timeout->add( $interval, sub { $timed_out = 1; return 0; } ); } my $context = Glib::MainContext->default; 1 until $context->iteration( 1 ); if( defined $timerid ) { Glib::Source->remove( $timerid ) unless $timed_out; } } sub loop_forever { my $self = shift; my $mainloop = $self->{mainloop} = Glib::MainLoop->new(); $mainloop->run; undef $self->{mainloop}; } sub loop_stop { my $self = shift; $self->{mainloop}->quit; } =head1 SEE ALSO =over 4 =item * L - Perl wrappers for the GLib utility and Object libraries =item * L - Perl interface to the 2.x series of the Gimp Toolkit library =back =head1 AUTHOR Paul Evans =cut 0x55AA; IO-Async-Loop-Glib-0.22/t000755001750001750 013654310672 13574 5ustar00leoleo000000000000IO-Async-Loop-Glib-0.22/t/00use.t000444001750001750 15713654310672 15035 0ustar00leoleo000000000000#!/usr/bin/perl use strict; use warnings; use Test::More; use_ok( "IO::Async::Loop::Glib" ); done_testing; IO-Async-Loop-Glib-0.22/t/01loop-io.t000444001750001750 16713654310672 15621 0ustar00leoleo000000000000#!/usr/bin/perl use strict; use warnings; use IO::Async::LoopTests 0.24; run_tests( 'IO::Async::Loop::Glib', 'io' ); IO-Async-Loop-Glib-0.22/t/02loop-timer.t000444001750001750 17213654310672 16327 0ustar00leoleo000000000000#!/usr/bin/perl use strict; use warnings; use IO::Async::LoopTests 0.24; run_tests( 'IO::Async::Loop::Glib', 'timer' ); IO-Async-Loop-Glib-0.22/t/03loop-signal.t000444001750001750 17313654310672 16466 0ustar00leoleo000000000000#!/usr/bin/perl use strict; use warnings; use IO::Async::LoopTests 0.24; run_tests( 'IO::Async::Loop::Glib', 'signal' ); IO-Async-Loop-Glib-0.22/t/04loop-idle.t000444001750001750 17113654310672 16125 0ustar00leoleo000000000000#!/usr/bin/perl use strict; use warnings; use IO::Async::LoopTests 0.24; run_tests( 'IO::Async::Loop::Glib', 'idle' ); IO-Async-Loop-Glib-0.22/t/05loop-process.t000444001750001750 17413654310672 16672 0ustar00leoleo000000000000#!/usr/bin/perl use strict; use warnings; use IO::Async::LoopTests 0.76; run_tests( 'IO::Async::Loop::Glib', 'process' ); IO-Async-Loop-Glib-0.22/t/06loop-control.t000444001750001750 17413654310672 16675 0ustar00leoleo000000000000#!/usr/bin/perl use strict; use warnings; use IO::Async::LoopTests 0.24; run_tests( 'IO::Async::Loop::Glib', 'control' ); IO-Async-Loop-Glib-0.22/t/11share-io.t000444001750001750 214313654310672 15767 0ustar00leoleo000000000000#!/usr/bin/perl use strict; use warnings; use Test::More; use Glib; use IO::Async::Loop::Glib; use IO::Async::Stream; sub make_readable_handle { pipe( my $reader, my $writer ) or die "Cannot pipe() - $!"; syswrite $writer, "Hello world!\n" or die "Cannot syswrite - $!"; return $reader; } my $loop = IO::Async::Loop::Glib->new; my $glib_line; my $glib_buffer = ""; my $glib_handle = make_readable_handle; Glib::IO->add_watch( $glib_handle->fileno, in => sub { sysread $glib_handle, $glib_buffer, 8192, length $glib_buffer; $glib_line = $1 if $glib_buffer =~ s/^(.*)\n//; } ); my $ioasync_line; $loop->add( IO::Async::Stream->new( read_handle => make_readable_handle, on_read => sub { my ( $self, $buffref, $closed ) = @_; return if $closed; return 0 unless $$buffref =~ s/^(.*)\n//; $ioasync_line = $1; return 1; }, ) ); $loop->loop_once until defined $glib_line and defined $ioasync_line; is( $glib_line, "Hello world!", 'Glib read' ); is( $ioasync_line, "Hello world!", 'IO::Async read' ); done_testing; IO-Async-Loop-Glib-0.22/t/12share-timer.t000444001750001750 105713654310672 16504 0ustar00leoleo000000000000#!/usr/bin/perl use strict; use warnings; use Test::More; use Glib; use IO::Async::Loop::Glib; use IO::Async::Timer::Countdown; my $loop = IO::Async::Loop::Glib->new; my $glib_timer; Glib::Timeout->add( 1000, sub { $glib_timer++ } ); my $ioasync_timer; $loop->add( IO::Async::Timer::Countdown->new( delay => 1, on_expire => sub { $ioasync_timer++ }, )->start ); $loop->loop_once until defined $glib_timer and defined $ioasync_timer; is( $glib_timer, 1, 'Glib timer' ); is( $ioasync_timer, 1, 'IO::Async timer' ); done_testing; IO-Async-Loop-Glib-0.22/t/15share-process.t000444001750001750 133713654310672 17046 0ustar00leoleo000000000000#!/usr/bin/perl use strict; use warnings; use Test::More; use Glib; use IO::Async::Loop::Glib; use IO::Async::PID; sub make_child { defined( my $kid = fork ) or die "Cannot fork - $!"; $kid or exec( $^X, "-e", "exit 5" ) or die "Cannot exec $^X - $!"; return $kid; } my $loop = IO::Async::Loop::Glib->new; my $glib_status; Glib::Child->watch_add( make_child, sub { $glib_status = $_[1] } ); my $ioasync_status; $loop->add( IO::Async::PID->new( pid => make_child, on_exit => sub { $ioasync_status = $_[1] }, ) ); $loop->loop_once until defined $glib_status and defined $ioasync_status; is( $glib_status, 5 << 8, 'Glib child' ); is( $ioasync_status, 5 << 8, 'IO::Async process' ); done_testing; IO-Async-Loop-Glib-0.22/t/99pod.t000444001750001750 25713654310672 15046 0ustar00leoleo000000000000#!/usr/bin/perl use strict; use warnings; use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok();