Parallel-Iterator-1.002/000755 000765 000024 00000000000 14274560520 014607 5ustar00apstaff000000 000000 Parallel-Iterator-1.002/inc/000755 000765 000024 00000000000 14274560520 015360 5ustar00apstaff000000 000000 Parallel-Iterator-1.002/LICENSE000644 000765 000024 00000043662 14274560520 015627 0ustar00apstaff000000 000000 This software is copyright (c) 2007 by Andy Armstrong. 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) 2007 by Andy Armstrong. 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) 2007 by Andy Armstrong. 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 Parallel-Iterator-1.002/Changes000644 000765 000024 00000002674 14274560227 016117 0ustar00apstaff000000 000000 Release history for Parallel-Iterator 1.002 Tue 09 Aug 2022 - No functional changes - Packaging fix to stop installing boilerplate.pl 1.001 Fri 15 Jul 2022 - No more subclassing of Exporter - Documentation fixes (including RT#67597; thanks to Richard Ganski) - Working tests in absence of . in @INC (RT#120543; thanks to Kent Fredric) - Packaging improvements 1.00 Thu 15 Nov 2007 - Use CORE::exit for mod_perl compatibility. Thanks to Michael Lackhoff for the fix. - Switched to n.nn version numbering. 0.8.0 Mon 15 Oct 2007 - Only execute END blocks in parent process. Thanks to Aristotle Pagaltzis for the suggestion and patch. 0.7.0 Thu 04 Oct 2007 - Added batch and adaptive options. - Fixed load balancing inequality. 0.6.0 Thu 04 Oct 2007 - Fixed MANIFEST 0.5.0 Thu 04 Oct 2007 - Made 0 worker option (non-forked) dclone its input data to achieve the same cloning effect that the forked version exhibits. 0.4.0 Wed 03 Oct 2007 - Fixed tests on Windows. 0.3.0 Tue 02 Oct 2007 - Made job output and result collection run in sync. Formally job output from the master process ran as quickly as possible. This results in better scheduling and eliminates the possibility of blocking with overlarge data (see t/030-block.t). - Added support for iterators throwing errors. 0.2.0 Thu 20 Sep 2007 - Renamed Parallel-Iterator. Didn't check Parallel-Workers was available. Duh. 0.1.0 Thu 20 Sep 2007 - Initial release. Parallel-Iterator-1.002/MANIFEST000644 000765 000024 00000000721 14274560520 015740 0ustar00apstaff000000 000000 Changes Makefile.PL examples/cpan-faces.pl examples/speedy.pl inc/boilerplate.pl lib/Parallel/Iterator.pm t/000-load.t t/010-basic.t t/020-data.t t/030-block.t t/040-batch.t t/050-nofork-basic.t t/060-nofork-data.t t/070-nofork-block.t t/080-nofork-batch.t t/lib/NoFork.pm MANIFEST META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) LICENSE README Parallel-Iterator-1.002/t/000755 000765 000024 00000000000 14274560520 015052 5ustar00apstaff000000 000000 Parallel-Iterator-1.002/README000644 000765 000024 00000002204 14274560520 015465 0ustar00apstaff000000 000000 Parallel::Iterator This module provides a 'parallel map'. Multiple worker processes are forked so that many instances of the transformation function may be executed simultaneously. For time consuming operations, particularly operations that spend most of their time waiting for I/O, this is a big performance win. It also provides a simple idiom to make effective use of multi CPU systems. There is, however, a considerable overhead associated with forking, so the example in the synopsis (doubling a list of numbers) is *not* a sensible use of this module. INSTALLATION This is a Perl module distribution. It should be installed with whichever tool you use to manage your installation of Perl, e.g. any of cpanm . cpan . cpanp -i . Consult http://www.cpan.org/modules/INSTALL.html for further instruction. Should you wish to install this module manually, the procedure is perl Makefile.PL make make test make install COPYRIGHT AND LICENSE This software is copyright (c) 2007 by Andy Armstrong. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Parallel-Iterator-1.002/examples/000755 000765 000024 00000000000 14274560520 016425 5ustar00apstaff000000 000000 Parallel-Iterator-1.002/META.yml000644 000765 000024 00000001454 14274560520 016064 0ustar00apstaff000000 000000 --- abstract: 'Simple parallel execution' author: - 'Andy Armstrong ' build_requires: Test::More: '0' dynamic_config: 0 generated_by: 'ExtUtils::MakeMaker version 7.34, 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: Parallel-Iterator no_index: directory: - t - inc requires: Config: '0' IO::Handle: '0' IO::Select: '0' Storable: '0' perl: '5.008' resources: bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=Parallel-Iterator license: http://dev.perl.org/licenses/ repository: https://github.com/ap/Parallel-Iterator.git version: '1.002' x_copyright: holder: 'Andy Armstrong' year: 2007 x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Parallel-Iterator-1.002/lib/000755 000765 000024 00000000000 14274560520 015355 5ustar00apstaff000000 000000 Parallel-Iterator-1.002/Makefile.PL000644 000765 000024 00000005436 14274556567 016611 0ustar00apstaff000000 000000 use 5.008; use strict; use warnings; my $sc = q; my $bt = q; my %META = ( name => 'Parallel-Iterator', author => 'Andy Armstrong ', x_copyright => { holder => 'Andy Armstrong', year => 2007 }, license => 'perl_5', resources => { license => [ 'http://dev.perl.org/licenses/' ], repository => { type => 'git', url => "$sc.git", web => $sc }, bugtracker => { web => $bt }, }, dynamic_config => 0, prereqs => { test => { requires => {qw( Test::More 0 )}, }, runtime => { requires => {qw( perl 5.008 Config 0 IO::Handle 0 IO::Select 0 Storable 0 )}, }, }, ); sub MY::postamble { -f 'META.yml' ? return : <<'' } create_distdir : MANIFEST distdir : MANIFEST MANIFEST : ( git ls-files ':!README.pod' ; echo MANIFEST ) > MANIFEST distdir : boilerplate .PHONY : boilerplate boilerplate : distmeta $(PERL) -Ilib inc/boilerplate.pl $(DISTVNAME) ## BOILERPLATE ############################################################### require ExtUtils::MakeMaker; my %MM_ARGS; # have to do this since old EUMM dev releases miss the eval $VERSION line my $eumm_version = eval $ExtUtils::MakeMaker::VERSION; my $mymeta = $eumm_version >= 6.57_02; my $mymeta_broken = $mymeta && $eumm_version < 6.57_07; (my $basepath = (-d 'lib' && 'lib/') . $META{name}) =~ s{-}{/}g; ($MM_ARGS{NAME} = $META{name}) =~ s/-/::/g; $MM_ARGS{VERSION_FROM} = "$basepath.pm"; $MM_ARGS{ABSTRACT_FROM} = -f "$basepath.pod" ? "$basepath.pod" : "$basepath.pm"; $META{license} = [ $META{license} ] if $META{license} && !ref $META{license}; $MM_ARGS{LICENSE} = $META{license}[0] if $META{license} && $eumm_version >= 6.30; $MM_ARGS{NO_MYMETA} = 1 if $mymeta_broken; $MM_ARGS{META_ADD} = { 'meta-spec' => { version => 2 }, %META } unless -f 'META.yml'; $MM_ARGS{PL_FILES} ||= {}; $MM_ARGS{NORECURS} = 1 if not exists $MM_ARGS{NORECURS}; for (qw(configure build test runtime)) { my $key = $_ eq 'runtime' ? 'PREREQ_PM' : uc $_.'_REQUIRES'; my $r = $MM_ARGS{$key} = { %{$META{prereqs}{$_}{requires} || {}}, %{delete $MM_ARGS{$key} || {}}, }; defined $r->{$_} or delete $r->{$_} for keys %$r; } $MM_ARGS{MIN_PERL_VERSION} = eval delete $MM_ARGS{PREREQ_PM}{perl} || 0; delete $MM_ARGS{MIN_PERL_VERSION} if $eumm_version < 6.47_01; $MM_ARGS{BUILD_REQUIRES} = {%{$MM_ARGS{BUILD_REQUIRES}}, %{delete $MM_ARGS{TEST_REQUIRES}}} if $eumm_version < 6.63_03; $MM_ARGS{PREREQ_PM} = {%{$MM_ARGS{PREREQ_PM}}, %{delete $MM_ARGS{BUILD_REQUIRES}}} if $eumm_version < 6.55_01; delete $MM_ARGS{CONFIGURE_REQUIRES} if $eumm_version < 6.51_03; ExtUtils::MakeMaker::WriteMakefile(%MM_ARGS); ## END BOILERPLATE ########################################################### Parallel-Iterator-1.002/META.json000644 000765 000024 00000002660 14274560520 016234 0ustar00apstaff000000 000000 { "abstract" : "Simple parallel execution", "author" : [ "Andy Armstrong " ], "dynamic_config" : 0, "generated_by" : "ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Parallel-Iterator", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : {}, "configure" : {}, "runtime" : { "requires" : { "Config" : "0", "IO::Handle" : "0", "IO::Select" : "0", "Storable" : "0", "perl" : "5.008" } }, "test" : { "requires" : { "Test::More" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://rt.cpan.org/Public/Dist/Display.html?Name=Parallel-Iterator" }, "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "type" : "git", "url" : "https://github.com/ap/Parallel-Iterator.git", "web" : "https://github.com/ap/Parallel-Iterator" } }, "version" : "1.002", "x_copyright" : { "holder" : "Andy Armstrong", "year" : 2007 }, "x_serialization_backend" : "JSON::PP version 4.02" } Parallel-Iterator-1.002/lib/Parallel/000755 000765 000024 00000000000 14274560520 017111 5ustar00apstaff000000 000000 Parallel-Iterator-1.002/lib/Parallel/Iterator.pm000644 000765 000024 00000050074 14274560520 021246 0ustar00apstaff000000 000000 use 5.008; use warnings; use strict; package Parallel::Iterator; use Carp; use Storable qw( store_fd fd_retrieve dclone ); use IO::Handle; use IO::Select; use Config; our $VERSION = '1.002'; use Exporter (); *import = \&Exporter::import; our @EXPORT_OK = qw( iterate iterate_as_array iterate_as_hash ); use constant IS_WIN32 => ( $^O =~ /^(MS)?Win32$/ ); my %DEFAULTS = ( workers => ( ( $Config{d_fork} && !IS_WIN32 ) ? 10 : 0 ), onerror => 'die', nowarn => 0, batch => 1, adaptive => 0, ); =head1 NAME Parallel::Iterator - Simple parallel execution =head1 SYNOPSIS use Parallel::Iterator qw( iterate ); # A very expensive way to double 100 numbers... my @nums = ( 1 .. 100 ); my $iter = iterate( sub { my ( $id, $job ) = @_; return $job * 2; }, \@nums ); my @out = (); while ( my ( $index, $value ) = $iter->() ) { $out[$index] = $value; } The C function applies a user supplied transformation function to each element in a list, returning a new list containing the transformed elements. =head1 DESCRIPTION This module provides a 'parallel map'. Multiple worker processes are forked so that many instances of the transformation function may be executed simultaneously. For time consuming operations, particularly operations that spend most of their time waiting for I/O, this is a big performance win. It also provides a simple idiom to make effective use of multi CPU systems. There is, however, a considerable overhead associated with forking, so the example in the synopsis (doubling a list of numbers) is I a sensible use of this module. =head1 MANUAL =head2 Basic Usage Imagine you have an array of URLs to fetch: my @urls = qw( http://google.com/ http://hexten.net/ http://search.cpan.org/ ... and lots more ... ); Write a function that retrieves a URL and returns its contents or undef if it can't be fetched: sub fetch { my ($id, $url) = @_; my $resp = $ua->get($url); return unless $resp->is_success; return $resp->content; }; Now write a function to synthesize a special kind of iterator: sub list_iter { my @ar = @_; my $pos = 0; return sub { return if $pos >= @ar; my @r = ( $pos, $ar[$pos] ); # Note: returns ( index, value ) $pos++; return @r; }; } The returned iterator will return each element of the array in turn and then undef. Actually it returns both the index I the value of each element in the array. Because multiple instances of the transformation function execute in parallel the results won't necessarily come back in order. The array index will later allow us to put completed items in the correct place in an output array. Get an iterator for the list of URLs: my $url_iter = list_iter( @urls ); Then wrap it in another iterator which will return the transformed results: my $page_iter = iterate( \&fetch, $url_iter ); Finally loop over the returned iterator storing results: my @out = ( ); while ( my ( $index, $value ) = $page_iter->() ) { $out[$index] = $value; } Behind the scenes your program forked into ten (by default) instances of itself and executed the page requests in parallel. =head2 Simpler interfaces Having to construct an iterator is a pain so C is smart enough to do that for you. Instead of passing an iterator just pass a reference to the array: my $page_iter = iterate( \&fetch, \@urls ); If you pass a hash reference the iterator you get back will return key, value pairs: my $some_iter = iterate( \&fetch, \%some_hash ); If the returned iterator is inconvenient you can get back a hash or array instead: my @done = iterate_as_array( \&fetch, \@urls ); my %done = iterate_as_hash( \&worker, \%jobs ); =head2 How It Works The current process is forked once for each worker. Each forked child is connected to the parent by a pair of pipes. The child's STDIN, STDOUT and STDERR are unaffected. Input values are serialised (using Storable) and passed to the workers. Completed work items are serialised and returned. =head2 Caveats Parallel::Iterator is designed to be simple to use - but the underlying forking of the main process can cause mystifying problems unless you have an understanding of what is going on behind the scenes. =head3 Worker execution enviroment All code apart from the worker subroutine executes in the parent process as normal. The worker executes in a forked instance of the parent process. That means that things like this won't work as expected: my %tally = (); my @r = iterate_as_array( sub { my ($id, $name) = @_; $tally{$name}++; # might not do what you think it does return reverse $name; }, \@names ); # Now print out the tally... while ( my ( $name, $count ) = each %tally ) { printf("%5d : %s\n", $count, $name); } Because the worker is a closure it can see the C<%tally> hash from its enclosing scope; but because it's running in a forked clone of the parent process it modifies its own copy of C<%tally> rather than the copy for the parent process. That means that after the job terminates the C<%tally> in the parent process will be empty. In general you should avoid side effects in your worker subroutines. =head3 Serialization Values are serialised using L to pass to the worker subroutine and results from the worker are again serialised before being passed back. Be careful what your values refer to: everything has to be serialised. If there's an indirect way to reach a large object graph Storable will find it and performance will suffer. To find out how large your serialised values are serialise one of them and check its size: use Storable qw( freeze ); my $serialized = freeze $some_obj; print length($serialized), " bytes\n"; In your tests you may wish to guard against the possibility of a change to the structure of your values resulting in a sudden increase in serialized size: ok length(freeze $some_obj) < 1000, "Object too bulky?"; See the documetation for L for other caveats. =head3 Performance Process forking is expensive. Only use Parallel::Iterator in cases where: =over =item the worker waits for I/O The case of fetching web pages is a good example of this. Fetching a page with LWP::UserAgent may take as long as a few seconds but probably consumes only a few milliseconds of processor time. Running many requests in parallel is a huge win - but be kind to the server you're talking to: don't launch a lot of parallel requests unless it's your server or you know it can handle the load. =item the worker is CPU intensive and you have multiple cores / CPUs If the worker is doing an expensive calculation you can parallelise that across multiple CPU cores. Benchmark first though. There's a considerable overhead associated with Parallel::Iterator; unless your calculations are time consuming that overhead will dwarf whatever time they take. =back =head1 INTERFACE =head2 C<< iterate( [ $options ], $worker, $iterator ) >> Get an iterator that applies the supplied transformation function to each value returned by the input iterator. Instead of an iterator you may pass an array or hash reference and C will convert it internally into a suitable iterator. If you are doing this you may wish to investigate C and C. =head3 Options A reference to a hash of options may be supplied as the first argument. The following options are supported: =over =item C The number of concurrent processes to launch. Set this to 0 to disable forking. Defaults to 10 on systems that support fork and 0 (disable forking) on those that do not. =item C Normally C will issue a warning and fall back to single process mode on systems on which fork is not available. This option supresses that warning. =item C Ordinarily items are passed to the worker one at a time. If you are processing a large number of items it may be more efficient to process them in batches. Specify the batch size using this option. Batching is transparent from the caller's perspective. Internally it modifies the iterators and worker (by wrapping them in additional closures) so that they pack, process and unpack chunks of work. =item C Extending the idea of batching a number of work items to amortize the overhead of passing work to and from parallel workers you may also ask C to heuristically determine the batch size by setting the C option to a numeric value. The batch size will be computed as / / A larger value for C will reduce the rate at which the batch size increases. Good values tend to be in the range 1 to 2. You can also specify lower and, optionally, upper bounds on the batch size by passing an reference to an array containing ( lower bound, growth ratio, upper bound ). The upper bound may be omitted. my $iter = iterate( { adaptive => [ 5, 2, 100 ] }, $worker, \@stuff ); =item C The action to take when an error is thrown in the iterator. Possible values are 'die', 'warn' or a reference to a subroutine that will be called with the index of the job that threw the exception and the value of C<$@> thrown. iterate( { onerror => sub { my ($id, $err) = @_; $self->log( "Error for index $id: $err" ); }, $worker, \@jobs ); The default is 'die'. =back =cut sub _massage_iterator { my $iter = shift; if ( 'ARRAY' eq ref $iter ) { my @ar = @$iter; my $pos = 0; return sub { return if $pos >= @ar; my @r = ( $pos, $ar[$pos] ); $pos++; return @r; }; } elsif ( 'HASH' eq ref $iter ) { my %h = %$iter; my @k = keys %h; return sub { return unless @k; my $k = shift @k; return ( $k, $h{$k} ); }; } elsif ( 'CODE' eq ref $iter ) { return $iter; } else { croak "Iterator must be a code, array or hash ref"; } } sub _nonfork { my ( $options, $worker, $iter ) = @_; return sub { while ( 1 ) { if ( my @next = $iter->() ) { my ( $id, $work ) = @next; # dclone so that we have the same semantics as the # forked version. $work = dclone $work if defined $work && ref $work; my $result = eval { $worker->( $id, $work ) }; if ( my $err = $@ ) { $options->{onerror}->( $id, $err ); } else { return ( $id, $result ); } } else { return; } } }; } # Does this sub look a bit long to you? :) sub _fork { my ( $options, $worker, $iter ) = @_; my @workers = (); my @result_queue = (); my $select = IO::Select->new; my $rotate = 0; return sub { LOOP: { # Make new workers while ( @workers < $options->{workers} && ( my @next = $iter->() ) ) { my ( $my_rdr, $my_wtr, $child_rdr, $child_wtr ) = map IO::Handle->new, 1 .. 4; pipe $child_rdr, $my_wtr or croak "Can't open write pipe ($!)\n"; pipe $my_rdr, $child_wtr or croak "Can't open read pipe ($!)\n"; if ( my $pid = fork ) { # Parent close $_ for $child_rdr, $child_wtr; push @workers, $pid; $select->add( [ $my_rdr, $my_wtr, 0 ] ); _put_obj( \@next, $my_wtr ); } else { # Child close $_ for $my_rdr, $my_wtr; # Don't execute any END blocks use POSIX '_exit'; eval q{END { _exit 0 }}; # Worker loop while ( defined( my $job = _get_obj( $child_rdr ) ) ) { my $result = eval { $worker->( @$job ) }; my $err = $@; _put_obj( [ $err ? ( 'E', $job->[0], $err ) : ( 'R', $job->[0], $result ) ], $child_wtr ); } # End of stream _put_obj( undef, $child_wtr ); close $_ for $child_rdr, $child_wtr; # We use CORE::exit for MP compatibility CORE::exit; } } return @{ shift @result_queue } if @result_queue; if ( $select->count ) { eval { my @rdr = $select->can_read; # Anybody got completed work? for my $r ( @rdr ) { my ( $rh, $wh, $eof ) = @$r; if ( defined( my $results = _get_obj( $rh ) ) ) { my $type = shift @$results; if ( $type eq 'R' ) { push @result_queue, $results; } elsif ( $type eq 'E' ) { $options->{onerror}->( @$results ); } else { die "Bad result type: $type"; } # We operate a strict one in, one out policy # - which avoids deadlocks. Having received # the previous result send a new work value. unless ( $eof ) { if ( my @next = $iter->() ) { _put_obj( \@next, $wh ); } else { _put_obj( undef, $wh ); close $wh; @{$r}[ 1, 2 ] = ( undef, 1 ); } } } else { $select->remove( $r ); close $rh; } } }; if ( my $err = $@ ) { # Finish all the workers _put_obj( undef, $_->[1] ) for $select->handles; # And wait for them to exit waitpid( $_, 0 ) for @workers; # Rethrow die $err; } redo LOOP; } waitpid( $_, 0 ) for @workers; return; } }; } sub _batch_input_iter { my ( $code, $options ) = @_; if ( my $adapt = $options->{adaptive} ) { my $workers = $options->{workers} || 1; my $count = 0; $adapt = [ 1, $adapt, undef ] unless 'ARRAY' eq ref $adapt; my ( $min, $ratio, $max ) = @$adapt; $min = 1 unless defined $min && $min > 1; return sub { my @chunk = (); # Adapt batch size my $batch = $count / $workers / $ratio; $batch = $min if $batch < $min; $batch = $max if defined $max && $batch > $max; while ( @chunk < $batch && ( my @next = $code->() ) ) { push @chunk, \@next; $count++; } return @chunk ? ( 0, \@chunk ) : (); }; } else { my $batch = $options->{batch}; return sub { my @chunk = (); while ( @chunk < $batch && ( my @next = $code->() ) ) { push @chunk, \@next; } return @chunk ? ( 0, \@chunk ) : (); }; } } sub _batch_output_iter { my $code = shift; my @queue = (); return sub { unless ( @queue ) { if ( my ( undef, $chunk ) = $code->() ) { @queue = @$chunk; } else { return; } } return @{ shift @queue }; }; return $code; } sub _batch_worker { my $code = shift; return sub { my ( undef, $chunk ) = @_; for my $item ( @$chunk ) { $item->[1] = $code->( @$item ); } return $chunk; }; } sub iterate { my %options = ( %DEFAULTS, %{ 'HASH' eq ref $_[0] ? shift : {} } ); croak "iterate takes 2 or 3 args" unless @_ == 2; my @bad_opt = grep { !exists $DEFAULTS{$_} } keys %options; croak "Unknown option(s): ", join( ', ', sort @bad_opt ), "\n" if @bad_opt; my $worker = shift; croak "Worker must be a coderef" unless 'CODE' eq ref $worker; my $iter = _massage_iterator( shift ); if ( $options{onerror} =~ /^(die|warn)$/ ) { $options{onerror} = eval "sub { shift; $1 shift }"; } croak "onerror option must be 'die', 'warn' or a code reference" unless 'CODE' eq ref $options{onerror}; if ( $options{workers} > 0 && $DEFAULTS{workers} == 0 ) { warn "Fork not available; falling back to single process mode\n" unless $options{nowarn}; $options{workers} = 0; } my $factory = $options{workers} == 0 ? \&_nonfork : \&_fork; if ( $options{batch} > 1 || $options{adaptive} ) { return _batch_output_iter( $factory->( \%options, _batch_worker( $worker ), _batch_input_iter( $iter, \%options ) ) ); } else { # OK. Ready. Let's do it. return $factory->( \%options, $worker, $iter ); } } =head2 C<< iterate_as_array >> As C but instead of returning an iterator returns an array containing the collected output from the iterator. In a scalar context returns a reference to the same array. For this to work properly the input iterator must return (index, value) pairs. This allows the results to be placed in the correct slots in the output array. The simplest way to do this is to pass an array reference as the input iterator: my @output = iterate_as_array( \&some_handler, \@input ); =cut sub iterate_as_array { my $iter = iterate( @_ ); my @out = (); while ( my ( $index, $value ) = $iter->() ) { $out[$index] = $value; } return wantarray ? @out : \@out; } =head2 C<< iterate_as_hash >> As C but instead of returning an iterator returns a hash containing the collected output from the iterator. In a scalar context returns a reference to the same hash. For this to work properly the input iterator must return (key, value) pairs. This allows the results to be placed in the correct slots in the output hash. The simplest way to do this is to pass a hash reference as the input iterator: my %output = iterate_as_hash( \&some_handler, \%input ); =cut sub iterate_as_hash { my $iter = iterate( @_ ); my %out = (); while ( my ( $key, $value ) = $iter->() ) { $out{$key} = $value; } return wantarray ? %out : \%out; } sub _get_obj { my $fd = shift; my $r = fd_retrieve $fd; return $r->[0]; } sub _put_obj { my ( $obj, $fd ) = @_; store_fd [$obj], $fd; $fd->flush; } 1; __END__ =pod =encoding UTF-8 =head1 BUGS AND LIMITATIONS No bugs have been reported. Please report any bugs or feature requests to C, or through the web interface at L. =head1 THANKS Aristotle Pagaltzis for the END handling suggestion and patch. =head1 AUTHOR Andy Armstrong =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2007 by Andy Armstrong. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Parallel-Iterator-1.002/examples/speedy.pl000644 000765 000024 00000001207 14263314504 020250 0ustar00apstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use Inline 'C'; use Parallel::Iterator qw( iterate_as_array ); # Demonstrates a simple way to run multiple instances of a C function in # parallel. You'll need it to be a fairly time consuming function # otherwise the overhead of forking and marshalling arguments will # overwhelm the execution time. my @ar = qw( This Pork Bubble ); @ar = ( @ar, @ar ) for 1 .. 5; my @got = iterate_as_array( sub { calc( $_[1] ) }, \@ar ); print join( ', ', @got ), "\n"; __END__ __C__ int calc(char *str) { int sum = 0; int c; while (c = *str++) { sum = sum << 3 | c; } return sum; } Parallel-Iterator-1.002/examples/cpan-faces.pl000755 000765 000024 00000012340 14264064624 020770 0ustar00apstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use HTML::Tiny; use LWP::UserAgent; use File::Spec; use File::Path; use PerlIO::gzip; use YAML qw; use Getopt::Long; use Parallel::Iterator qw( iterate ); $| = 1; use constant MAIL_RC => 'http://cpan.perl.org/authors/01mailrc.txt.gz'; use constant ICON_BASE => 'http://search.cpan.org/gravatar'; use constant AUTHOR => 'http://search.cpan.org/~'; use constant OUTPUT => 'cpan-faces'; use constant STATE => File::Spec->catfile( OUTPUT, 'work.yml' ); use constant SIZE => 80; my $UPDATE = 0; GetOptions( 'update' => \$UPDATE ) or die "cpan-gravatar.pl [--update]\n"; my $ua = LWP::UserAgent->new; mkpath( OUTPUT ); my $icons = -f STATE ? LoadFile( STATE ) : {}; $SIG{INT} = sub { print "Got SIGINT, stopping\n"; exit; }; my $pid = $$; END { if ( $$ == $pid ) { print "Saving ", STATE, "\n"; DumpFile( STATE, $icons ); my $index = File::Spec->catfile( OUTPUT, 'index.html' ); open my $ih, '>', $index or die "Can't write $index ($!)\n"; print $ih build_page( $icons ); close $ih; } } update( $icons, $UPDATE ? sub { my ( $icons, $id ) = @_; return 0; } : sub { my ( $icons, $id ) = @_; return exists $icons->{$id} && $icons->{$id}->{state} eq 'done'; } ); sub update { my ( $icons, $skip_if ) = @_; print "Getting ", MAIL_RC, "\n"; my $authors = get_authors( MAIL_RC ); open my $ah, '<:gzip', $authors or die "Can't read $authors ($!)\n"; my $iter = iterate( { workers => 20 }, sub { my ( $id, undef ) = @_; print "Checking $id\n"; return save_icon( lc( $id ) ); }, sub { while ( defined( my $line = <$ah> ) ) { next unless $line =~ /^alias\s+(\S+)/; return $1; } return; } ); while ( my ( $id, $icon ) = $iter->() ) { $icons->{$id} = $icon; print "Icon saved as ", $icon->{name}, "\n" if $icon && $icon->{name}; } } sub build_page { my $icons = shift; my $h = HTML::Tiny->new; my @pic = (); for my $id ( sort keys %$icons ) { my $icon = $icons->{$id}; if ( my $img = $icon->{name} ) { push @pic, ( $h->div( { class => 'icon' }, $h->a( { href => user_home( $id ) }, $h->img( { src => File::Spec->abs2rel( $img, OUTPUT ), width => SIZE, height => SIZE, alt => $id } ), ), ) ); } } return $h->html( [ $h->head( [ $h->title( 'The Faces of CPAN' ), $h->link( { rel => 'stylesheet', href => 'style.css', type => 'text/css', media => 'screen' } ) ] ), $h->body( [@pic] ) ] ); } sub get_authors { my $url = shift; my $resp = $ua->get( $url ); if ( $resp->is_success ) { my $name = File::Spec->catfile( OUTPUT, '01mailrc.txt.gz' ); open my $ah, '>', $name or die "Can't write $name ($!)\n"; binmode $ah; print $ah $resp->content; close $ah; return $name; } else { die $resp->status_line; } } sub user_home { my $id = shift; return AUTHOR . lc( $id ); } sub save_icon { my $id = shift; my %ext_map = ( jpeg => 'jpg' ); my ( $data, $type ) = eval { get_icon( $id ) }; if ( $@ ) { return { error => $@, state => 'error' }; } # if ( $data && $data ne $default_image && $type =~ m{ ^image/(\S+) }x ) { if ( $data && $type =~ m{ ^image/(\S+) }x ) { my $ext = $ext_map{$1} || $1; my $name = make_name( $id, $ext ); open my $ih, '>', $name or die "Can't write $name ($!)\n"; binmode $ih; print $ih $data; close $ih; return { name => $name, state => 'done' }; } return { state => 'done' }; } sub make_name { my ( $email, $ext ) = @_; my %enc = ( '@' => '-AT-', '.' => '-DOT-' ); $email =~ s/([@.])/$enc{$1}||$1/eg; return File::Spec->catfile( OUTPUT, "$email.$ext" ); } sub get_icon { my $id = shift; $id =~ s{^(((.).).*)$}{$3/$2/$1}; TRY: for my $ext ( qw( jpg png ) ) { my $url = ICON_BASE . '/' . $id . '.' . $ext; my $resp = $ua->get( $url ); if ( $resp->is_success ) { return ( $resp->content, $resp->header( 'Content-Type' ) ); } elsif ( $resp->code == 404 ) { next TRY; } else { die join ' ', $resp->code, $resp->message; } } return; } Parallel-Iterator-1.002/t/070-nofork-block.t000644 000765 000024 00000000124 14266417023 020126 0ustar00apstaff000000 000000 use strict; use warnings; use lib 't/lib'; use NoFork; require './t/030-block.t'; Parallel-Iterator-1.002/t/040-batch.t000644 000765 000024 00000001060 14266417023 016616 0ustar00apstaff000000 000000 use strict; use warnings; use Test::More; use Parallel::Iterator qw( iterate_as_array ); my @spec = ( { batch => 97 }, { batch => 100 }, { adaptive => 1 }, { adaptive => 2 }, { adaptive => [ 10, 1, 20 ] } ); plan tests => @spec * 1; for my $spec ( @spec ) { my @in = ( 1 .. 5000 ); my @want = map { $_ * 2 } @in; my @got = iterate_as_array( $spec, sub { my ( $id, $job ) = @_; return $job * 2; }, \@in ); is_deeply \@got, \@want, "processed OK"; } 1; Parallel-Iterator-1.002/t/010-basic.t000644 000765 000024 00000010456 14266417023 016624 0ustar00apstaff000000 000000 use strict; use warnings; use Test::More tests => 13; use Parallel::Iterator qw( iterate iterate_as_array iterate_as_hash ); sub array_iter { my @ar = @_; my $pos = 0; return sub { return if $pos >= @ar; my @r = ( $pos, $ar[$pos] ); $pos++; return @r; }; } sub fill_array_from_iter { my $iter = shift; my @ar = (); while ( my ( $pos, $value ) = $iter->() ) { # die "Value for $pos is undef!\n" unless defined $value; $ar[$pos] = $value; } return @ar; } { my @ar = ( 1 .. 5 ); my $iter = array_iter( @ar ); my @got = fill_array_from_iter( $iter ); is_deeply \@got, \@ar, 'iterators'; } for my $workers ( 0, 1, 2, 10 ) { my @nums = ( 1 .. 100 ); my @double = map $_ * 2, @nums; my $done = 0; my $double_iter = iterate( { workers => $workers, nowarn => 1 }, sub { my ( $id, $job ) = @_; return $job * 2; }, array_iter( @nums ) ); my @got = fill_array_from_iter( $double_iter ); is_deeply \@got, \@double, "double, $workers workers"; } # Array iterator { my @input = ( 1 .. 5 ); my @quad = map $_ * 4, @input; my $quad_iter = iterate( { workers => 1, nowarn => 1 }, sub { my ( $id, $job ) = @_; return $job * 4; }, \@input ); my @got = fill_array_from_iter( $quad_iter ); is_deeply \@got, \@quad, "array iterator"; } # iterate_as_array { my @input = ( 1 .. 5 ); my @quad = map $_ * 4, @input; my @got = iterate_as_array( { workers => 1, nowarn => 1 }, sub { my ( $id, $job ) = @_; return $job * 4; }, \@input ); is_deeply \@got, \@quad, "array iterator"; } # Hash iterator { my %input = ( one => 1, three => 3, five => 5, seven => 7, nine => 9 ); my $treble_iter = iterate( { workers => 1, nowarn => 1 }, sub { my ( $key, $job ) = @_; return $job * 3; }, \%input ); my %expect = %input; $_ *= 3 for values %expect; my %output; while ( my ( $k, $v ) = $treble_iter->() ) { $output{$k} = $v; } is_deeply \%output, \%expect, "iterate_as_array"; } # iterate_as_hash { my %input = ( one => 1, three => 3, five => 5, seven => 7, nine => 9 ); my %output = iterate_as_hash( { workers => 1, nowarn => 1 }, sub { my ( $key, $job ) = @_; return $job * 3; }, \%input ); my %expect = %input; $_ *= 3 for values %expect; is_deeply \%output, \%expect, "iterate_as_hash"; } # Empty input { my @input = (); my @got = iterate_as_array( { workers => 1, nowarn => 1 }, sub { my ( $id, $job ) = @_; return $job * 5; }, \@input ); is_deeply \@got, \@input, "array iterator"; } # Die { my @input = ( 1 .. 5 ); my $iter = iterate( { workers => 1, nowarn => 1 }, sub { my ( $id, $job ) = @_; die "Oops"; }, \@input ); eval { $iter->() }; like $@, qr{Oops}, "died OK"; } # Warn { my @input = ( 1 .. 5 ); my $iter = iterate( { workers => 1, onerror => 'warn', nowarn => 1 }, sub { my ( $id, $job ) = @_; die "Oops"; }, \@input ); my @warning; local $SIG{__WARN__} = sub { push @warning, @_; }; $iter->(); like $warning[0], qr{Oops}, "warned OK"; } # Callback { my @input = ( 1 .. 5 ); my @warning; my $iter = iterate( { workers => 1, onerror => sub { push @warning, @_ }, nowarn => 1 }, sub { my ( $id, $job ) = @_; die "Oops"; }, \@input ); $iter->(); like $warning[1], qr{Oops}, "warned OK"; } 1; Parallel-Iterator-1.002/t/080-nofork-batch.t000644 000765 000024 00000000106 14266417023 020116 0ustar00apstaff000000 000000 use strict; use lib 't/lib'; use NoFork; require './t/040-batch.t'; Parallel-Iterator-1.002/t/020-data.t000644 000765 000024 00000001701 14266417023 016446 0ustar00apstaff000000 000000 use strict; use warnings; use Test::More tests => 1; use Parallel::Iterator qw( iterate_as_array ); { my @input = ( { type => 'hash', value => 2 }, [ 1, 2, 3 ], "Hello" ); my @want = ( { type => 'hash', value => 10 }, [ 4, 5, 6, 7, 8, 9 ], "HelloHello" ); my @got = iterate_as_array( { workers => 1, nowarn => 1 }, sub { my ( $id, $job ) = @_; if ( ref $job ) { if ( 'HASH' eq ref $job ) { $job->{value} *= 5; return $job; } elsif ( 'ARRAY' eq ref $job ) { return [ 4, 5, 6, 7, 8, 9 ]; } } else { return $job . $job; } }, \@input ); is_deeply \@got, \@want, "data structure"; } 1; Parallel-Iterator-1.002/t/060-nofork-data.t000644 000765 000024 00000000123 14266417023 017743 0ustar00apstaff000000 000000 use strict; use warnings; use lib 't/lib'; use NoFork; require './t/020-data.t'; Parallel-Iterator-1.002/t/lib/000755 000765 000024 00000000000 14274560520 015620 5ustar00apstaff000000 000000 Parallel-Iterator-1.002/t/000-load.t000644 000765 000024 00000001033 14274556410 016453 0ustar00apstaff000000 000000 use strict; use warnings; use Test::More; BEGIN { # compat shim for old Test::More defined &BAIL_OUT or *BAIL_OUT = sub { my $t = Test::Builder->new; $t->no_ending(1); # needed before Test::Builder 0.61 $t->BAILOUT(@_); # added in Test::Builder 0.40 }; } my @module = qw( Parallel::Iterator ); plan tests => 0+@module; diag "Testing on Perl $] at $^X"; for my $module ( @module ) { use_ok( $module ) or BAIL_OUT "Cannot load module '$module'"; no warnings 'uninitialized'; diag "Testing $module @ " . $module->VERSION; } Parallel-Iterator-1.002/t/030-block.t000644 000765 000024 00000004311 14266417023 016630 0ustar00apstaff000000 000000 use strict; use warnings; use Test::More; use Parallel::Iterator qw( iterate_as_array ); use IO::Handle; use POSIX qw(:errno_h); my $buffer_size = get_pipe_buffer_size(); plan 'skip_all' => "Can't calculate buffer size" unless defined $buffer_size; plan tests => 1; # diag "I/O buffer size: $buffer_size\n"; { # Random data my $data = join '', map chr rand 256, ( 1 .. $buffer_size * 2 ); # Just in case someone decides to generate data by some other # means... die "Not enough data!" unless length $data > $buffer_size; my @input = ( { type => 'hash', value => $data, }, [ 1, $data, 3 ], $data, ); my @want = ( { type => 'hash', value => "$data!", }, [ $data, $data ], $data . $data, ); for ( 1 .. 4 ) { @input = ( @input, @input ); @want = ( @want, @want ); } my @got = iterate_as_array( { workers => 5, nowarn => 1 }, sub { my ( $id, $job ) = @_; # Just munge the data in a predictable, detectable way... if ( ref $job ) { if ( 'HASH' eq ref $job ) { $job->{value} .= '!'; return $job; } elsif ( 'ARRAY' eq ref $job ) { return [ $data, $data ]; } } else { return $job . $job; } }, \@input ); is_deeply \@got, \@want, "big data structure"; } # Find out how much data we can write to a pipe... sub get_pipe_buffer_size { my ( $in, $out ) = map IO::Handle->new, 1 .. 2; unless ( pipe $in, $out ) { diag "Can't make pipe ($!)\n"; return; } unless ( defined $out->blocking( 0 ) ) { diag "Can't turn off blocking ($!)\n"; return; } my $chunk = ' ' x ( 1024 * 4 ); my $wrote = 0; CHUNK: while ( 1 ) { my $rc = $out->syswrite( $chunk, length $chunk ); last CHUNK if !defined $rc && $! == EAGAIN; $wrote += $rc; last CHUNK if $rc != length $chunk; } close $_ for $in, $out; return $wrote; } 1; Parallel-Iterator-1.002/t/050-nofork-basic.t000644 000765 000024 00000000123 14266417023 020112 0ustar00apstaff000000 000000 use strict; use warnings; use lib 't/lib'; use NoFork; require './t/020-data.t'; Parallel-Iterator-1.002/t/lib/NoFork.pm000644 000765 000024 00000000607 14264067110 017353 0ustar00apstaff000000 000000 package NoFork; # This code originally written by Eric Wilhelm for the Test::Harness # project. Thanks Eric - it's just what I needed :) BEGIN { *CORE::GLOBAL::fork = sub { die "you should not fork" }; } use Config; tied( %Config )->{d_fork} = 0; # blatant lie =begin TEST Assuming not too much chdir: PERL5OPT='-It/lib -MNoFork' perl -Ilib bin/prove -r t =end TEST =cut 1; Parallel-Iterator-1.002/inc/boilerplate.pl000644 000765 000024 00000003315 14274016452 020221 0ustar00apstaff000000 000000 use strict; use warnings; use CPAN::Meta; use Software::LicenseUtils 0.103011; use Pod::Readme::Brief 1.001; sub slurp { open my $fh, '<', $_[0] or die "Couldn't open $_[0] to read: $!\n"; local $/; readline $fh } sub trimnl { s/\A\s*\n//, s/\s*\z/\n/ for @_; wantarray ? @_ : $_[-1] } sub mkparentdirs { my @dir = do { my %seen; sort grep s!/[^/]+\z!! && !$seen{ $_ }++, my @copy = @_ }; if ( @dir ) { mkparentdirs( @dir ); mkdir for @dir } } chdir $ARGV[0] or die "Cannot chdir to $ARGV[0]: $!\n"; my %file; my $meta = CPAN::Meta->load_file( 'META.json' ); my $license = do { my @key = ( $meta->license, $meta->meta_spec_version ); my ( $class, @ambiguous ) = Software::LicenseUtils->guess_license_from_meta_key( @key ); die if @ambiguous or not $class; $class->new( $meta->custom( 'x_copyright' ) ); }; $file{'LICENSE'} = trimnl $license->fulltext; my ( $main_module ) = map { s!-!/!g; s!^!lib/! if -d 'lib'; -f "$_.pod" ? "$_.pod" : "$_.pm" } $meta->name; ( $file{ $main_module } = slurp $main_module ) =~ s{(^=cut\s*\z)}{ join "\n", ( "=head1 AUTHOR\n", trimnl( $meta->authors ), "=head1 COPYRIGHT AND LICENSE\n", trimnl( $license->notice ), "=cut\n", ) }me; die unless -e 'Makefile.PL'; $file{'README'} = Pod::Readme::Brief->new( $file{ $main_module } )->render( installer => 'eumm' ); my @manifest = split /\n/, slurp 'MANIFEST'; my %manifest = map /\A([^\s#]+)()/, @manifest; $file{'MANIFEST'} = join "\n", @manifest, ( sort grep !exists $manifest{ $_ }, keys %file ), ''; mkparentdirs sort keys %file; for my $fn ( sort keys %file ) { unlink $fn if -e $fn; open my $fh, '>', $fn or die "Couldn't open $fn to write: $!\n"; print $fh $file{ $fn }; close $fh or die "Couldn't close $fn after writing: $!\n"; }