r9687 - in /branches/upstream/libproc-fork-perl: ./ current/ current/lib/ current/lib/Proc/ current/t/

rmayorga-guest at users.alioth.debian.org rmayorga-guest at users.alioth.debian.org
Fri Nov 23 19:50:28 UTC 2007


Author: rmayorga-guest
Date: Fri Nov 23 19:50:27 2007
New Revision: 9687

URL: http://svn.debian.org/wsvn/?sc=1&rev=9687
Log:
[svn-inject] Installing original source of libproc-fork-perl

Added:
    branches/upstream/libproc-fork-perl/
    branches/upstream/libproc-fork-perl/current/
    branches/upstream/libproc-fork-perl/current/Build.PL
    branches/upstream/libproc-fork-perl/current/Changes
    branches/upstream/libproc-fork-perl/current/MANIFEST
    branches/upstream/libproc-fork-perl/current/META.yml
    branches/upstream/libproc-fork-perl/current/Makefile.PL
    branches/upstream/libproc-fork-perl/current/README
    branches/upstream/libproc-fork-perl/current/lib/
    branches/upstream/libproc-fork-perl/current/lib/Proc/
    branches/upstream/libproc-fork-perl/current/lib/Proc/Fork.pm
    branches/upstream/libproc-fork-perl/current/t/
    branches/upstream/libproc-fork-perl/current/t/00.mock.t
    branches/upstream/libproc-fork-perl/current/t/01.real.t
    branches/upstream/libproc-fork-perl/current/t/pod-coverage.t
    branches/upstream/libproc-fork-perl/current/t/pod.t

Added: branches/upstream/libproc-fork-perl/current/Build.PL
URL: http://svn.debian.org/wsvn/branches/upstream/libproc-fork-perl/current/Build.PL?rev=9687&op=file
==============================================================================
--- branches/upstream/libproc-fork-perl/current/Build.PL (added)
+++ branches/upstream/libproc-fork-perl/current/Build.PL Fri Nov 23 19:50:27 2007
@@ -1,0 +1,18 @@
+use strict;
+use warnings;
+use Module::Build;
+
+my $builder = Module::Build->new(
+    module_name         => 'Proc::Fork',
+    license             => 'perl',
+    dist_author         => 'Aristotle Pagaltzis <pagaltzis at gmx.de>',
+    dist_version_from   => 'lib/Proc/Fork.pm',
+    requires => { },
+	build_requires => {
+		'Test::More' => 0,
+	},
+    add_to_cleanup      => [ 'Proc-Fork-*' ],
+	create_makefile_pl => 'traditional',
+);
+
+$builder->create_build_script();

Added: branches/upstream/libproc-fork-perl/current/Changes
URL: http://svn.debian.org/wsvn/branches/upstream/libproc-fork-perl/current/Changes?rev=9687&op=file
==============================================================================
--- branches/upstream/libproc-fork-perl/current/Changes (added)
+++ branches/upstream/libproc-fork-perl/current/Changes Fri Nov 23 19:50:27 2007
@@ -1,0 +1,40 @@
+Revision history for Proc-Fork
+
+0.4   2007 Apr 01
+	- Simplify internals a bit, in hopes of fixing #17474 and #17926;
+	  unfortunately, no dice
+
+0.3   2006 May 10
+	- Add tests with real fork() call,
+	  with intent to resolve stalled bugs #17474 and #17926
+	- Add test for $pid getting passed to the parent block
+
+0.2   2006 March 4
+	- Internals refactor to fix bugs #17474 and #17926
+	- Rejig tests, add a test for the syntax error catcher
+
+0.11  2005 October 3
+	- Add tests for POD and POD coverage
+	- Switch over to Module::Build
+
+0.1   2005 April 23
+	- Minor documentation fix
+	- Complete internals refactor
+	- Add support and documentation for retry {}
+	- Create proper test suite
+
+0.05  2002 March 15
+	- Change namespace from Fork to Proc::Fork.
+
+0.04  2002 February 8
+	- Export parent, child, error by default.
+	- Add documentation examples.
+
+0.03  2002 January 31
+	- Documentation changes only.
+
+0.02  2002 January 30
+	- Bless the fork return value, for better error checking.
+
+0.01  2002 January 29
+	- original version

Added: branches/upstream/libproc-fork-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/branches/upstream/libproc-fork-perl/current/MANIFEST?rev=9687&op=file
==============================================================================
--- branches/upstream/libproc-fork-perl/current/MANIFEST (added)
+++ branches/upstream/libproc-fork-perl/current/MANIFEST Fri Nov 23 19:50:27 2007
@@ -1,0 +1,11 @@
+README
+Changes
+Build.PL
+t/00.mock.t
+t/01.real.t
+t/pod-coverage.t
+t/pod.t
+lib/Proc/Fork.pm
+MANIFEST
+META.yml
+Makefile.PL

Added: branches/upstream/libproc-fork-perl/current/META.yml
URL: http://svn.debian.org/wsvn/branches/upstream/libproc-fork-perl/current/META.yml?rev=9687&op=file
==============================================================================
--- branches/upstream/libproc-fork-perl/current/META.yml (added)
+++ branches/upstream/libproc-fork-perl/current/META.yml Fri Nov 23 19:50:27 2007
@@ -1,0 +1,19 @@
+---
+name: Proc-Fork
+version: 0.4
+author:
+  - 'Aristotle Pagaltzis <pagaltzis at gmx.de>'
+abstract: 'Simple, intuitive interface to the fork() system call'
+license: perl
+resources:
+  license: http://dev.perl.org/licenses/
+build_requires:
+  Test::More: 0
+provides:
+  Proc::Fork:
+    file: lib/Proc/Fork.pm
+    version: 0.4
+generated_by: Module::Build version 0.2805
+meta-spec:
+  url: http://module-build.sourceforge.net/META-spec-v1.2.html
+  version: 1.2

Added: branches/upstream/libproc-fork-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/branches/upstream/libproc-fork-perl/current/Makefile.PL?rev=9687&op=file
==============================================================================
--- branches/upstream/libproc-fork-perl/current/Makefile.PL (added)
+++ branches/upstream/libproc-fork-perl/current/Makefile.PL Fri Nov 23 19:50:27 2007
@@ -1,0 +1,14 @@
+# Note: this file was auto-generated by Module::Build::Compat version 0.03
+use ExtUtils::MakeMaker;
+WriteMakefile
+(
+          'PL_FILES' => {},
+          'INSTALLDIRS' => 'site',
+          'NAME' => 'Proc::Fork',
+          'EXE_FILES' => [],
+          'VERSION_FROM' => 'lib/Proc/Fork.pm',
+          'PREREQ_PM' => {
+                           'Test::More' => 0
+                         }
+        )
+;

Added: branches/upstream/libproc-fork-perl/current/README
URL: http://svn.debian.org/wsvn/branches/upstream/libproc-fork-perl/current/README?rev=9687&op=file
==============================================================================
--- branches/upstream/libproc-fork-perl/current/README (added)
+++ branches/upstream/libproc-fork-perl/current/README Fri Nov 23 19:50:27 2007
@@ -1,0 +1,24 @@
+Proc::Fork
+
+This module provides an intuitive, Perl-ish way to write forking
+programs by letting you use blocks to illustrate which code section
+executes in which fork. The code for the parent, child, retry handler
+and error handler are grouped together in a "fork block". The clauses
+may appear in any order, but they must be consecutive (without any other
+statements in between).
+
+INSTALLATION
+
+To install this module, run the following commands:
+
+    perl Build.PL
+    ./Build
+    ./Build test
+    ./Build install
+
+COPYRIGHT AND LICENCE
+
+Copyright (C) 2005, Aristotle Pagaltzis
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.

Added: branches/upstream/libproc-fork-perl/current/lib/Proc/Fork.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libproc-fork-perl/current/lib/Proc/Fork.pm?rev=9687&op=file
==============================================================================
--- branches/upstream/libproc-fork-perl/current/lib/Proc/Fork.pm (added)
+++ branches/upstream/libproc-fork-perl/current/lib/Proc/Fork.pm Fri Nov 23 19:50:27 2007
@@ -1,0 +1,325 @@
+#!/usr/bin/perl
+
+=head1 NAME
+
+Proc::Fork - Simple, intuitive interface to the fork() system call
+
+=head1 VERSION
+
+This documentation describes Proc::Fork version 0.4
+
+=head1 SYNOPSIS
+
+ use Proc::Fork;
+
+ child {
+     # child code goes here.
+ }
+ parent {
+     my $child_pid = shift;
+     # parent code goes here.
+     waitpid $child_pid, 0;
+ }
+ retry {
+     my $attempts = shift;
+     # what to do if if fork() fails:
+     # return true to try again, false to abort
+     return if $attempts > 5;
+     sleep 1, return 1;
+ }
+ error {
+     # Error-handling code goes here
+     # (fork() failed and the retry block returned false)
+ };
+ # Note the semicolon at the end! Necessary in most cases
+
+=head1 DESCRIPTION
+
+This module provides an intuitive, Perl-ish way to write forking programs by letting you use blocks to illustrate which code section executes in which fork. The code for the parent, child, retry handler and error handler are grouped together in a "fork block". The clauses may appear in any order, but they must be consecutive (without any other statements in between).
+
+The semicolon after the last clause is B<mandatory>, unless the last clause is at the end of the enclosing block or file.
+
+All four clauses need not be specified. If the retry clause is omitted, only one fork will be attempted. If the error clause is omitted the program will die with a simple message if it can't retry. If the parent or child clause is omitted, the respective (parent or child) process will start execution after the final clause. So if one or the other only has to do some simple action, you need only specify that one. For example:
+
+ # spawn off a child process to do some simple processing
+ child {
+     exec '/bin/ls', '-l';
+     die "Couldn't exec ls: $!\n";
+ };
+ # Parent will continue execution from here
+ # ...
+
+If the code in any of the clauses does not die or exit, it will continue execution after the fork block.
+
+=head1 INTERFACE
+
+=head2 child
+
+ child { ... }
+
+This function executes the code reference passed to it if it discovers that it is the child process.
+
+=head2 parent
+
+ parent { ... }
+
+This function executes the code reference passed to it if it discovers that it is the parent process. It passes the child's PID to the code.
+
+=head2 retry
+
+ retry { ... }
+
+This function executes the code reference passed to it if there was an error, ie if C<fork> returned undef. If the code returns true, another C<fork> is attempted. The function passes the number of fork attempts so far to the code.
+
+This can be used to implement a wait-and-retry logic that may be essential for some applications like daemons.
+
+If a C<retry> clause is not used, no retries will be attempted and a fork failure will immediately lead to the C<error> clause being called.
+
+=head2 error
+
+ error { ... }
+
+This function executes the code reference passed to it if there was an error, ie C<fork> returned undef and the C<retry> clause returned false. The function passes the number of forks attempted to the code.
+
+If an C<error> clause is not used, errors will raise an exception using C<die>.
+
+=head1 SYNTAX NOTE
+
+B<Imporant note:> Due to the way Perl 5 parses these functions, there must be a semicolon after the close brace of the final clause, whether it be a C<parent>, C<child>, C<retry> or C<error> clause, unless that closing brace is the final token of the enclosing block or file.
+
+Proc::Fork attempts to detect missing semicolons.  How well this works remains to be seen.
+
+=head1 EXAMPLES
+
+=head2 Simple example
+
+ # example with IPC via pipe
+ use strict;
+ use IO::Pipe;
+ use Proc::Fork;
+ my $p = new IO::Pipe;
+
+ parent {
+     my $child = shift;
+     $p->reader;
+     print while ( <$p> );
+     waitpid $child,0;
+ }
+ child {
+     $p->writer;
+     print $p "Line 1\n";
+     print $p "Line 2\n";
+     exit;
+ }
+ retry {
+     if( $_[0] < 5 ) {
+		 sleep 1;
+		 return 1;
+     }
+     return 0;
+ }
+ error {
+     die "That's all folks\n";
+ };
+
+(The terminating semicolon is not strictly necessary here, because the program ends there anyway, but it is good habit.)
+
+=head2 Multi-child example
+
+ use strict;
+ use Proc::Fork;
+ use IO::Pipe;
+
+ my $num_children = 5;    # How many children we'll create
+ my @children;            # Store connections to them
+ $SIG{CHLD} = 'IGNORE';   # Don't worry about reaping zombies
+
+ # Spawn off some children
+ for my $num ( 1 .. $num_children ) {
+     # Create a pipe for parent-child communication
+     my $pipe = new IO::Pipe;
+
+     # Child simply echoes data it receives, until EOF
+     child {
+         $pipe->reader;
+         my $data;
+         while ( $data = <$pipe> ) {
+             chomp $data;
+             print STDERR "child $num: [$data]\n";
+         }
+         exit;
+     };
+
+     # Parent here
+     $pipe->writer;
+     push @children, $pipe;
+ }
+
+ # Send some data to the kids
+ for ( 1 .. 20 ) {
+     # pick a child at random
+     my $num = int rand $num_children;
+     my $child = $children[$num];
+     print $child "Hey there.\n";
+ }
+
+=head2 Daemon example
+
+ # daemon example
+ use strict;
+ use Proc::Fork ();
+ use Posix;
+
+ # One-stop shopping: fork, die on error, parent process exits.
+ Proc::Fork::parent {exit};
+
+ # Other daemon initialization activities.
+ $SIG{INT} = $SIG{TERM} = $SIG{HUP} = $SIG{PIPE} = \&some_signal_handler;
+ Posix::setsid() or die "Cannot start a new session: $!\n";
+ close $_ for *STDIN, *STDOUT, *STDERR;
+
+ # rest of daemon program follows
+
+=head2 Forking network server example
+
+ # Socket-based server example
+ use strict;
+ use IO::Socket::INET;
+ use Proc::Fork;
+
+ $SIG{CHLD} = 'IGNORE';
+
+ my $server = IO::Socket::INET->new(
+	LocalPort => 7111,
+	Type      => SOCK_STREAM,
+	Reuse     => 1,
+	Listen    => 10,
+ ) or die "Couln't start server: $!\n";
+
+ my $client;
+ while ($client = $server->accept) {
+     child {
+         # Service the socket
+         sleep(10);
+         print $client "Ooga! ", time % 1000, "\n";
+         exit; # child exits. Parent loops to accept another connection.
+     }
+ }
+
+=head1 EXPORTS
+
+This package exports the following symbols by default.
+
+=over 4
+
+=item * C<child>
+
+=item * C<parent>
+
+=item * C<retry>
+
+=item * C<error>
+
+=back
+
+=head1 DEPENDENCIES
+
+L<Carp> and L<Exporter>, which are part of the Perl distribution.
+
+=head1 BUGS AND LIMITATIONS
+
+None currently known, for what that's worth.
+
+Please report any bugs or feature requests to C<bug-proc-fork at rt.cpan.org>, or through the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Proc-Fork>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
+
+=head1 AUTHOR
+
+Aristotle Pagaltzis, L<mailto:pagaltzis at gmx.de>
+
+Original version and most of the documentation by Eric J. Roode.
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (c) 2005 by Aristotle Pagaltzis. All rights Reserved.
+
+This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L<perlartistic>.
+
+=head1 DISCLAIMER OF WARRANTY
+
+BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "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 SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
+
+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 SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (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 SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+=cut
+
+package Proc::Fork;
+
+$VERSION   = 0.4; # also change it in the docs
+ at ISA       = qw( Exporter );
+ at EXPORT    = qw( parent child error retry );
+ at EXPORT_OK = qw();
+
+use strict;
+use warnings;
+
+use Exporter;
+use Carp;
+
+sub _do_fork {
+	my ( $p, $c, $e, $r ) = @_;
+
+	my ( $pid, $retry );
+	{
+		$pid = fork;
+		redo if not defined( $pid ) and $r and $r->( ++$retry );
+	}
+
+	if ( not defined $pid ) {
+		die "Cannot fork: $!\n" if not $e;
+		$e->();
+	}
+	elsif ( $pid ) {
+		$p->( $pid ) if $p;
+	}
+	else {
+		$c->() if $c;
+	}
+
+	return;
+}
+
+BEGIN {
+
+	my %glob = (
+		child  => \*child,
+		error  => \*error,
+		retry  => \*retry,
+		parent => \*parent,
+	);
+
+	for my $key ( keys %glob ) {
+		*{ $glob{ $key } } = sub (&;$) {
+			my ( $val, $config ) = @_;
+
+			# too many arguments or not a config hash as 2nd argument?
+			# then the user has almost certainly forgotten the trailing semicolon
+			croak "Syntax error (missing semicolon after $key clause?)"
+				if @_ > 2
+				or ( @_ == 2 and not eval { $config->isa( __PACKAGE__ ) } );
+
+			$config ||= bless {}, __PACKAGE__;
+			$config->{ $key } = $val;
+
+			# if not called in void context, then we're not the final part of the call
+			# chain, so just pass the config up the chain
+			return $config if defined wantarray;
+
+			# otherwise, pull the trigger
+			@_ = @{ $config }{ qw( parent child error retry ) };
+			undef $config;
+			goto &_do_fork;
+		};
+	}
+}
+
+!!"In simplicity lies beauty.";

Added: branches/upstream/libproc-fork-perl/current/t/00.mock.t
URL: http://svn.debian.org/wsvn/branches/upstream/libproc-fork-perl/current/t/00.mock.t?rev=9687&op=file
==============================================================================
--- branches/upstream/libproc-fork-perl/current/t/00.mock.t (added)
+++ branches/upstream/libproc-fork-perl/current/t/00.mock.t Fri Nov 23 19:50:27 2007
@@ -1,0 +1,39 @@
+#!perl -T
+use strict;
+use warnings;
+
+use Test::More tests => 14;
+
+our $forkres;
+
+BEGIN { *CORE::GLOBAL::fork = sub { $forkres } }
+
+BEGIN { use_ok( 'Proc::Fork' ); }
+
+# basic functionality
+{ local $forkres = 1; parent { ok( 1, 'parent code executes' )    };          }
+{ local $forkres = 0; child  { ok( 1, 'child code executes'  )    };          }
+{                     error  { ok( 1, 'error code executes'  )    };          }
+{                     retry  { ok( 1, 'retry code executes'  ); 0 } error {}; }
+
+# pid gets passed in?
+{ local $forkres = 42; parent { is( shift, 42, 'pid is passed to parent block' ) }; }
+
+# error catching attempts
+eval { parent {} "oops" };
+like( $@, qr/^Syntax error \(missing semicolon after \w+ clause\?\)/, 'syntax error catcher fired' );
+
+# test retry logic
+my $expect_try;
+retry {
+	++$expect_try;
+	is( $_[ 0 ], $expect_try, "retry attempt $expect_try signalled" );
+	return $_[ 0 ] < 5; 
+}
+error {
+	is( $expect_try, 5, 'abort after 5th attempt' );
+};
+
+ok( 1, 'I can have a coke now' );
+
+# vim:ft=perl:

Added: branches/upstream/libproc-fork-perl/current/t/01.real.t
URL: http://svn.debian.org/wsvn/branches/upstream/libproc-fork-perl/current/t/01.real.t?rev=9687&op=file
==============================================================================
--- branches/upstream/libproc-fork-perl/current/t/01.real.t (added)
+++ branches/upstream/libproc-fork-perl/current/t/01.real.t Fri Nov 23 19:50:27 2007
@@ -1,0 +1,17 @@
+#!perl -T
+use strict;
+use warnings;
+
+# impossible to beat Test::More into submission when fork()'s involved
+
+sub say { print @_, "\n" }
+
+BEGIN { say '1..3'; }
+
+BEGIN { eval 'use Proc::Fork'; if( $@ ) { say 'not ok 1 - use Proc::Fork'; exit } say 'ok 1 - use Proc::Fork' }
+
+# parent uses waitpid to ensure order of output
+child  {                   say 'ok 2 - child code runs'  }
+parent { waitpid shift, 0; say 'ok 3 - parent code runs' }
+
+# vim:ft=perl:

Added: branches/upstream/libproc-fork-perl/current/t/pod-coverage.t
URL: http://svn.debian.org/wsvn/branches/upstream/libproc-fork-perl/current/t/pod-coverage.t?rev=9687&op=file
==============================================================================
--- branches/upstream/libproc-fork-perl/current/t/pod-coverage.t (added)
+++ branches/upstream/libproc-fork-perl/current/t/pod-coverage.t Fri Nov 23 19:50:27 2007
@@ -1,0 +1,9 @@
+#!perl -T
+
+use Test::More;
+eval "use Test::Pod::Coverage 1.04";
+plan skip_all => 'Test::Pod::Coverage 1.04 required for testing POD coverage' if $@;
+plan skip_all => 'Set the TEST_POD environment variable to run these tests' if not exists $ENV{TEST_POD};
+all_pod_coverage_ok( { also_private => [ qr/\A[[:upper:][:digit:]_]+\z/ ], trustme => [ 'new' ] } );
+
+# vim:ft=perl:

Added: branches/upstream/libproc-fork-perl/current/t/pod.t
URL: http://svn.debian.org/wsvn/branches/upstream/libproc-fork-perl/current/t/pod.t?rev=9687&op=file
==============================================================================
--- branches/upstream/libproc-fork-perl/current/t/pod.t (added)
+++ branches/upstream/libproc-fork-perl/current/t/pod.t Fri Nov 23 19:50:27 2007
@@ -1,0 +1,9 @@
+#!perl -T
+
+use Test::More;
+eval "use Test::Pod 1.14";
+plan skip_all => 'Test::Pod 1.14 required for testing POD' if $@;
+plan skip_all => 'Set the TEST_POD environment variable to run these tests' if not exists $ENV{TEST_POD};
+all_pod_files_ok();
+
+# vim:ft=perl:




More information about the Pkg-perl-cvs-commits mailing list