r25585 - in /trunk/libproc-fork-perl: Build.PL Changes MANIFEST META.yml Makefile.PL debian/changelog debian/compat debian/control debian/copyright debian/libproc-fork-perl.examples debian/rules debian/watch eg/ lib/Proc/Fork.pm lib/Proc/Fork/

ansgar-guest at users.alioth.debian.org ansgar-guest at users.alioth.debian.org
Wed Sep 24 17:05:36 UTC 2008


Author: ansgar-guest
Date: Wed Sep 24 17:05:28 2008
New Revision: 25585

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=25585
Log:
* New upstream release.
  + add dependency on libexporter-tidy-perl
* Refresh debian/rules for debhelper 7
* debian/watch: Add uversionmangle in case upstream uses single digit minor
  versions again
* Add myself to Uploaders
* Bump Standards Version to 3.8.0 (no changes)
* debian/control: Drop build-deps for POD testing, the test are never run
  anyway

Added:
    trunk/libproc-fork-perl/debian/libproc-fork-perl.examples
    trunk/libproc-fork-perl/eg/
      - copied from r25584, branches/upstream/libproc-fork-perl/current/eg/
    trunk/libproc-fork-perl/lib/Proc/Fork/
      - copied from r25584, branches/upstream/libproc-fork-perl/current/lib/Proc/Fork/
Modified:
    trunk/libproc-fork-perl/Build.PL
    trunk/libproc-fork-perl/Changes
    trunk/libproc-fork-perl/MANIFEST
    trunk/libproc-fork-perl/META.yml
    trunk/libproc-fork-perl/Makefile.PL
    trunk/libproc-fork-perl/debian/changelog
    trunk/libproc-fork-perl/debian/compat
    trunk/libproc-fork-perl/debian/control
    trunk/libproc-fork-perl/debian/copyright
    trunk/libproc-fork-perl/debian/rules
    trunk/libproc-fork-perl/debian/watch
    trunk/libproc-fork-perl/lib/Proc/Fork.pm

Modified: trunk/libproc-fork-perl/Build.PL
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-fork-perl/Build.PL?rev=25585&op=diff
==============================================================================
--- trunk/libproc-fork-perl/Build.PL (original)
+++ trunk/libproc-fork-perl/Build.PL Wed Sep 24 17:05:28 2008
@@ -6,7 +6,8 @@
 	module_name         => 'Proc::Fork',
 	license             => 'perl',
 	dist_author         => 'Aristotle Pagaltzis <pagaltzis at gmx.de>',
-	build_requires      => { 'Test::More' => 0 },
+	requires            => { 'Exporter::Tidy' => 0 },
+	build_requires      => { 'Test::More'     => 0 },
 	add_to_cleanup      => [ 'Proc-Fork-*' ],
 	create_makefile_pl  => 'traditional',
 );

Modified: trunk/libproc-fork-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-fork-perl/Changes?rev=25585&op=diff
==============================================================================
--- trunk/libproc-fork-perl/Changes (original)
+++ trunk/libproc-fork-perl/Changes Wed Sep 24 17:05:28 2008
@@ -1,4 +1,34 @@
 =head1 Revision history for Proc-Fork
+
+
+=head2 0.71 (2008-09-22T03:09:02+0200)
+
+=over 4
+
+=item * Brown paper bag release.
+
+Forgot some mandatory parens. No idea why 5.8.8 didn't give me the syntax error that 5.10 detected.
+
+=back
+
+
+=head2 0.7 (2008-09-20 16:54:09+0200)
+
+=over 4
+
+=item * Completely new internal structure; modified API, now with a C<run_fork> wrapper.
+
+This should address both the semicolon problem and the context sensitivity problem pointed out on AnnoCPAN by dmcbride. Code written against the previous API design will continue to work unchanged.
+
+=item * L<Exporter::Tidy> replaces some local code.
+
+It's a very small pure-Perl module that shouldn't be a dependency burden, and it's a good design that deserves some advertisement.
+
+=item * POD examples extracted and provided as files in an F<eg/> directory.
+
+Yes, this is Kwalitee whoring. Hopefully I won't make changes to the docs that I then forget to update in the F<eg/> copies. Yay for CPANTS.
+
+=back
 
 
 =head2 0.61 (2007-12-23 12:06:22+0100)

Modified: trunk/libproc-fork-perl/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-fork-perl/MANIFEST?rev=25585&op=diff
==============================================================================
--- trunk/libproc-fork-perl/MANIFEST (original)
+++ trunk/libproc-fork-perl/MANIFEST Wed Sep 24 17:05:28 2008
@@ -4,7 +4,12 @@
 t/00.mock.t
 t/01.real.t
 lib/Proc/Fork.pm
+lib/Proc/Fork/Runner.pm
 MANIFEST
 META.yml
 Makefile.PL
 t/cpants.t
+eg/daemon.pl
+eg/multichild.pl
+eg/server.pl
+eg/simple.pl

Modified: trunk/libproc-fork-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-fork-perl/META.yml?rev=25585&op=diff
==============================================================================
--- trunk/libproc-fork-perl/META.yml (original)
+++ trunk/libproc-fork-perl/META.yml Wed Sep 24 17:05:28 2008
@@ -1,18 +1,23 @@
 ---
 name: Proc-Fork
-version: 0.61
+version: 0.71
 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/
+requires:
+  Exporter::Tidy: 0
 build_requires:
   Test::More: 0
 provides:
   Proc::Fork:
     file: lib/Proc/Fork.pm
-    version: 0.61
+    version: 0.71
+  Proc::Fork::Runner:
+    file: lib/Proc/Fork/Runner.pm
+    version: 0.71
 generated_by: Module::Build version 0.2808
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.2.html

Modified: trunk/libproc-fork-perl/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-fork-perl/Makefile.PL?rev=25585&op=diff
==============================================================================
--- trunk/libproc-fork-perl/Makefile.PL (original)
+++ trunk/libproc-fork-perl/Makefile.PL Wed Sep 24 17:05:28 2008
@@ -2,13 +2,14 @@
 use ExtUtils::MakeMaker;
 WriteMakefile
 (
-          'PL_FILES' => {},
-          'INSTALLDIRS' => 'site',
           'NAME' => 'Proc::Fork',
-          'EXE_FILES' => [],
           'VERSION_FROM' => 'lib/Proc/Fork.pm',
           'PREREQ_PM' => {
-                           'Test::More' => 0
-                         }
+                           'Exporter::Tidy' => '0',
+                           'Test::More' => '0'
+                         },
+          'INSTALLDIRS' => 'site',
+          'EXE_FILES' => [],
+          'PL_FILES' => {}
         )
 ;

Modified: trunk/libproc-fork-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-fork-perl/debian/changelog?rev=25585&op=diff
==============================================================================
--- trunk/libproc-fork-perl/debian/changelog (original)
+++ trunk/libproc-fork-perl/debian/changelog Wed Sep 24 17:05:28 2008
@@ -1,3 +1,17 @@
+libproc-fork-perl (0.71-1) unstable; urgency=low
+
+  * New upstream release.
+    + add dependency on libexporter-tidy-perl
+  * Refresh debian/rules for debhelper 7
+  * debian/watch: Add uversionmangle in case upstream uses single digit minor
+    versions again
+  * Add myself to Uploaders
+  * Bump Standards Version to 3.8.0 (no changes)
+  * debian/control: Drop build-deps for POD testing, the test are never run
+    anyway
+
+ -- Ansgar Burchardt <ansgar at 43-1.org>  Wed, 24 Sep 2008 19:04:23 +0200
+
 libproc-fork-perl (0.61-1) unstable; urgency=low
 
   [ Rene Mayorga ]

Modified: trunk/libproc-fork-perl/debian/compat
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-fork-perl/debian/compat?rev=25585&op=diff
==============================================================================
--- trunk/libproc-fork-perl/debian/compat (original)
+++ trunk/libproc-fork-perl/debian/compat Wed Sep 24 17:05:28 2008
@@ -1,1 +1,1 @@
-6
+7

Modified: trunk/libproc-fork-perl/debian/control
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-fork-perl/debian/control?rev=25585&op=diff
==============================================================================
--- trunk/libproc-fork-perl/debian/control (original)
+++ trunk/libproc-fork-perl/debian/control Wed Sep 24 17:05:28 2008
@@ -3,18 +3,18 @@
 Priority: optional
 Maintainer: Debian Perl Group <pkg-perl-maintainers at lists.alioth.debian.org>
 Uploaders: Rene Mayorga <rmayorga at debian.org.sv>, Gunnar Wolf <gwolf at debian.org>,
- gregor herrmann <gregor+debian at comodo.priv.at>
-Build-Depends: debhelper (>= 6)
-Build-Depends-Indep: perl (>= 5.8.1), libpod-tests-perl, libpod-coverage-perl
-Standards-Version: 3.7.3
+ gregor herrmann <gregor+debian at comodo.priv.at>,
+ Ansgar Burchardt <ansgar at 43-1.org>
+Build-Depends: debhelper (>= 7)
+Build-Depends-Indep: perl (>= 5.8.1), libexporter-tidy-perl
+Standards-Version: 3.8.0
 Vcs-Svn: svn://svn.debian.org/pkg-perl/trunk/libproc-fork-perl/
 Vcs-Browser: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-fork-perl/
 Homepage: http://search.cpan.org/dist/Proc-Fork/
 
-
 Package: libproc-fork-perl
 Architecture: all
-Depends: ${perl:Depends}, ${misc:Depends}
+Depends: ${perl:Depends}, ${misc:Depends}, libexporter-tidy-perl
 Description: Perl interface to fork() system call
  Proc::Fork module provides an intuitive, Perl-ish way to write forking 
  programs by letting you use blocks to illustrate which code section executes 

Modified: trunk/libproc-fork-perl/debian/copyright
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-fork-perl/debian/copyright?rev=25585&op=diff
==============================================================================
--- trunk/libproc-fork-perl/debian/copyright (original)
+++ trunk/libproc-fork-perl/debian/copyright Wed Sep 24 17:05:28 2008
@@ -1,31 +1,24 @@
-This package was debianized by Rene Mayorga <rmayorga at debian.org.sv> on
-Fri, 23 Nov 2007 10:03:28 -0600.
+Format-Specification: http://wiki.debian.org/Proposals/CopyrightFormat?action=recall&rev=228
+Upstream-Name: Proc-Fork
+Upstream-Maintainer: Aristotle Pagaltzis <pagaltzis at gmx.de>
+Upstream-Source: http://search.cpan.org/dist/Proc-Fork/
 
-It was downloaded from: http://search.cpan.org/dist/Proc-Fork/
+Files: *
+Copyright: © 2005-2008, Aristotle Pagaltzis <pagaltzis at gmx.de>
+License: GPL-1+ | Artistic
+ This module is free software; you can redistribute it and/or modify
+ it under the same terms as Perl itself.
+ .
+ Perl is distributed under your choice of the GNU General Public License or
+ the Artistic License.  On Debian GNU/Linux systems, the complete text of the
+ GNU General Public License can be found in `/usr/share/common-licenses/GPL'
+ and the Artistic Licence in `/usr/share/common-licenses/Artistic'.
 
-Upstream Author: 
+Files: debian/*
+Copyright:
+ © 2007, Rene Mayorga <rmayorga at debian.org.sv>
+ © 2008, Ansgar Burchardt <ansgar at 43-1.org>
+License: GPL-any
+ The Debian packaging is licensed under the GPL, see
+ `/usr/share/common-licenses/GPL'.
 
-     Αριστοτέλης Παγκαλτζής <pagaltzis at gmx.de>
-     (Aristotle Pagaltzis) 
-     
-     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.
-
-Perl license is:
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of either:
-
-    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" which comes with Perl.
-
-On Debian GNU/Linux systems, the complete text of the GNU General Public
-License can be found in `/usr/share/common-licenses/GPL' and the Artistic
-Licence in `/usr/share/common-licenses/Artistic'.
-
-The Debian packaging is (C) 2007, Rene Mayorga <rmayorga at debian.org.sv> and
-is licensed under the GPL, see `/usr/share/common-licenses/GPL'.

Added: trunk/libproc-fork-perl/debian/libproc-fork-perl.examples
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-fork-perl/debian/libproc-fork-perl.examples?rev=25585&op=file
==============================================================================
--- trunk/libproc-fork-perl/debian/libproc-fork-perl.examples (added)
+++ trunk/libproc-fork-perl/debian/libproc-fork-perl.examples Wed Sep 24 17:05:28 2008
@@ -1,0 +1,1 @@
+eg/*

Modified: trunk/libproc-fork-perl/debian/rules
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-fork-perl/debian/rules?rev=25585&op=diff
==============================================================================
--- trunk/libproc-fork-perl/debian/rules (original)
+++ trunk/libproc-fork-perl/debian/rules Wed Sep 24 17:05:28 2008
@@ -1,55 +1,23 @@
 #!/usr/bin/make -f
-# -*- makefile -*-
-# debian/rules file for libnet-sip-perl
-
-
-ifndef PERL
-	PERL = /usr/bin/perl
-endif
-
-PACKAGE = $(shell dh_listpackages)
-TMP     = $(CURDIR)/debian/$(PACKAGE)
-
 
 build: build-stamp
 build-stamp:
-	dh_testdir
-	$(PERL) Makefile.PL INSTALLDIRS=vendor
-	$(MAKE)
-	TEST_POD=1 $(MAKE) test
+	TEST_POD=1 dh build
 	touch $@
 
 clean:
-	dh_testdir
-	dh_testroot
-	rm -f build-stamp install-stamp
-	dh_clean
-	[ ! -f Makefile ] || $(MAKE) distclean
+	dh $@
 
 install: install-stamp
 install-stamp: build-stamp
-	dh_testdir
-	dh_testroot
-	dh_clean -k
-	$(MAKE) install DESTDIR=$(TMP) PREFIX=/usr
-	[ ! -d $(TMP)/usr/lib/perl5 ] || rmdir --ignore-fail-on-non-empty --parents --verbose $(TMP)/usr/lib/perl5
+	dh install
 	touch $@
 
 binary-arch:
-# nothing to do
 
-binary-indep: build install
-	dh_testdir
-	dh_testroot
-	dh_installchangelogs Changes
-	dh_compress
-	dh_installdocs
-	dh_fixperms
-	dh_installdeb
-	dh_perl
-	dh_gencontrol
-	dh_md5sums
-	dh_builddeb
+binary-indep: install
+	dh $@
 
-binary: binary-indep binary-arch
-.PHONY: build clean binary-indep binary-arch binary install
+binary: binary-arch binary-indep
+
+.PHONY: binary binary-arch binary-indep install clean build

Modified: trunk/libproc-fork-perl/debian/watch
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-fork-perl/debian/watch?rev=25585&op=diff
==============================================================================
--- trunk/libproc-fork-perl/debian/watch (original)
+++ trunk/libproc-fork-perl/debian/watch Wed Sep 24 17:05:28 2008
@@ -1,3 +1,4 @@
 version=3
-http://search.cpan.org/dist/Proc-Fork/ .+/Proc-Fork-(.*)\.tar\.gz
+opts="uversionmangle=s/(\.\d)$/${1}0/" \
 http://search.cpan.org/dist/Proc-Fork/ .*/Proc-Fork-v?(\d[\d_.]+)\.(?:tar(?:\.gz|\.bz2)?|tgz|zip)
+

Modified: trunk/libproc-fork-perl/lib/Proc/Fork.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libproc-fork-perl/lib/Proc/Fork.pm?rev=25585&op=diff
==============================================================================
--- trunk/libproc-fork-perl/lib/Proc/Fork.pm (original)
+++ trunk/libproc-fork-perl/lib/Proc/Fork.pm Wed Sep 24 17:05:28 2008
@@ -2,74 +2,57 @@
 
 package Proc::Fork;
 
-$VERSION = 0.61; # also change it in the docs
+$VERSION = 0.71; # also change it in the docs and in Fork/Runner.pm
 
 use strict;
 use warnings;
+use vars '$RUN_CLASS';
+
+$RUN_CLASS ||= 'Proc::Fork::Runner';
+eval "require $RUN_CLASS" or die $@;
+
+sub run_fork(&) {
+	my ( $setup ) = @_;
+	my $runner = $setup->();
+	if ( not eval { $runner->isa( $RUN_CLASS ) } ) {
+		require Carp;
+		Carp::croak( "Syntax error (trailing garbage in block after Proc::Fork setup?)" );
+	}
+	$runner->run;
+	return;
+}
 
 my $make_forkblock = sub {
 	my ( $config_key ) = shift;
-
-	return sub (&;$) {
+	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
-		if ( @_ > 2 or ( @_ == 2 and not eval { $config->isa( __PACKAGE__ ) } ) ) {
+		if ( @_ > 2 or ( @_ == 2 and not eval { $config->isa( $RUN_CLASS ) } ) ) {
 			require Carp;
 			Carp::croak( "Syntax error (missing semicolon after $config_key clause?)" );
 		}
 
-		$config ||= bless {}, __PACKAGE__;
-		$config->{ $config_key } = $val;
+		( $config ||= $RUN_CLASS->new )->set( $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, we pull the trigger
-		my ( $p, $c, $e, $r ) = delete @{ $config }{ qw( parent child error retry ) };
-
-		my $pid;
-
-		{
-			my $retry;
-
-			do {
-				$pid = fork;
-			} while ( not defined $pid ) and ( $r and $r->( ++$retry ) );
-		}
-
-		if    ( not defined $pid ) { $e ? $e->()       : die "Cannot fork: $!\n" }
-		elsif ( $pid )             { $p ? $p->( $pid ) : 0 }
-		else                       { $c ? $c->()       : 0 }
-
-		return;
+		defined wantarray ? return $config : $config->run;
 	};
 };
 
-my %block = map { $_ => $make_forkblock->( $_ ) } qw( child error retry parent );
-
-sub import {
-	my $class = shift;
-	my $pkg = caller;
-
-	@_ = keys %block if not @_;
-
-	for my $name ( @_ ) {
-		if ( not exists $block{ $name } ) {
-			require Carp;
-			Carp::croak( qq{"$name" is not exported by the $class module} );
-		}
-
-		no strict;
-		*{ $pkg . '::' . $name } = $block{ $name };
-	}
-
-	return 1;
-}
-
-__PACKAGE__->import;
+require Exporter::Tidy;
+Exporter::Tidy->import(
+	default => [ ':all' ],
+	wrapper => [ 'run_fork' ],
+	blocks  => [ $RUN_CLASS->blocks ],
+	_map    => { map { $_ => $make_forkblock->( $_ ) } $RUN_CLASS->blocks },
+);
+
+__PACKAGE__->import( ':blocks' );
+
+1;
 
 __END__
 
@@ -79,46 +62,45 @@
 
 =head1 VERSION
 
-This documentation describes Proc::Fork version 0.61
+This documentation describes Proc::Fork version 0.71
 
 =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)
+ run_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 {
+ run_fork { child {
      exec '/bin/ls', '-l';
      die "Couldn't exec ls: $!\n";
- };
+ } };
  # Parent will continue execution from here
  # ...
 
@@ -126,23 +108,29 @@
 
 =head1 INTERFACE
 
+=head2 run_fork
+
+ run_fork { ... }
+
+Performs the fork operation configured in its block.
+
 =head2 child
 
  child { ... }
 
-This function executes the code reference passed to it if it discovers that it is the child process.
+Declares the block that should run in 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.
+Declares the block that should run in the parent process. The child's PID is passed as an argument to the block.
 
 =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.
+Declares the block that should run in case of an error, ie. if C<fork> returned C<undef>. If the code returns true, another C<fork> is attempted. The number of fork attempts so far is passed as an argument to the block.
 
 This can be used to implement a wait-and-retry logic that may be essential for some applications like daemons.
 
@@ -152,50 +140,44 @@
 
  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.
+Declares the block that should run if there was an error, ie when C<fork> returns C<undef> and the C<retry> clause returns false. The number of forks attempted is passed as an argument to the block.
 
 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
+=head2 Simple example with IPC via pipe
+
  use strict;
+ use Proc::Fork;
+
  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";
+ my $p = IO::Pipe->new;
+
+ run_fork {
+     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
 
@@ -210,10 +192,10 @@
  # Spawn off some children
  for my $num ( 1 .. $num_children ) {
      # Create a pipe for parent-child communication
-     my $pipe = new IO::Pipe;
+     my $pipe = IO::Pipe->new;
 
      # Child simply echoes data it receives, until EOF
-     child {
+     run_fork { child {
          $pipe->reader;
          my $data;
          while ( $data = <$pipe> ) {
@@ -221,7 +203,7 @@
              print STDERR "child $num: [$data]\n";
          }
          exit;
-     };
+     } };
 
      # Parent here
      $pipe->writer;
@@ -238,24 +220,22 @@
 
 =head2 Daemon example
 
- # daemon example
  use strict;
- use Proc::Fork ();
- use Posix;
+ use Proc::Fork;
+ use POSIX;
 
  # One-stop shopping: fork, die on error, parent process exits.
- Proc::Fork::parent {exit};
+ run_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";
+ 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
+=head2 Forking socket-based network server example
+
  use strict;
  use IO::Socket::INET;
  use Proc::Fork;
@@ -263,20 +243,20 @@
  $SIG{CHLD} = 'IGNORE';
 
  my $server = IO::Socket::INET->new(
-	LocalPort => 7111,
-	Type      => SOCK_STREAM,
-	Reuse     => 1,
-	Listen    => 10,
+     LocalPort => 7111,
+     Type      => SOCK_STREAM,
+     Reuse     => 1,
+     Listen    => 10,
  ) or die "Couln't start server: $!\n";
 
  my $client;
  while ($client = $server->accept) {
-     child {
+     run_fork { child {
          # Service the socket
          sleep(10);
          print $client "Ooga! ", time % 1000, "\n";
          exit; # child exits. Parent loops to accept another connection.
-     }
+     } }
  }
 
 =head1 EXPORTS
@@ -285,6 +265,8 @@
 
 =over 4
 
+=item * C<run_fork>
+
 =item * C<child>
 
 =item * C<parent>
@@ -297,7 +279,7 @@
 
 =head1 DEPENDENCIES
 
-L<Carp> and L<Exporter>, which are part of the Perl distribution.
+L<Carp>, which is part of the Perl distribution, and L<Exporter::Tidy>.
 
 =head1 BUGS AND LIMITATIONS
 
@@ -309,11 +291,11 @@
 
 Aristotle Pagaltzis, L<mailto:pagaltzis at gmx.de>
 
-Original version and most of the documentation by Eric J. Roode.
+Documentation by Eric J. Roode.
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright (c) 2005 by Aristotle Pagaltzis. All rights Reserved.
+Copyright (c) 2005-2008 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>.
 




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