Child.pl untested

filter: Statementstmt 0.0% 0 / 24 Branchbran n/a Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 42 CC 1 SCAR 6.9
CC
1
Cov
0%
init
2.0
main_loop
2.0
BEGIN
2.0
CRAP 2.0
1 ############################################################################
2 #
3 # Win32/ProcFarm/Child.pl - procedural support code for child processes in
4 # the Win32-ProcFarm system
5 #
6 # Author: Toby Everett
7 # Revision: 2.15
8 # Last Change: Namespace change
9 ############################################################################
10 # Copyright 1999, 2000, 2001 Toby Everett. All rights reserved.
11 #
12 # This file is distributed under the Artistic License. See
13 # http://www.ActiveState.com/corporate/artistic_license.htm or
14 # the license that comes with your perl distribution.
15 #
16 # For comments, questions, bugs or general interest, feel free to
17 # contact Toby Everett at teverett@alascom.att.com
18 ############################################################################
19
20 =head1 NAME
21
22 Win32/ProcFarm/Child.pl - procedural support code for child processes in
23 the Win32-ProcFarm system
24
25 =head1 SYNOPSIS
26
27 require 'Win32/ProcFarm/Child.pl';
28
29 &init;
30 while(1) {
31 &main_loop;
32 }
33
34 sub child_sub {
35 my(@params) = @_;
36
37 #do some useful work that may take a while
38 return (@return_values);
39 }
40
41 =head1 DESCRIPTION
42
43 =head2 Installation instructions
44
45 This installs with MakeMaker as part of Win32::ProcFarm.
46
47 To install via MakeMaker, it's the usual procedure - download from CPAN,
48 extract, type "perl Makefile.PL", "nmake" then "nmake install". Don't
49 do an "nmake test" because the I haven't written a test suite yet.
50
51 =head1 UTILIZATION
52
53 Simple include the top 6 lines of code in a Perl script and define a bunch of subroutines. Don't
54 use die in the subroutines.
55
56 =cut
57
58 use Data::Dumper;
59 use IO::Socket;
60
61 sub init {
62 my($port_num, $unique) = @ARGV[0,1];
63
64 $socket = new IO::Socket::INET ("localhost:$port_num") or die "Child unable to open socket.\n";
65 print $socket pack("V", $unique);
66 }
67
68 sub main_loop {
69 my($len, $cmd);
70
71 my $temp = read($socket, $len, 4);
72 $temp or exit;
73 $temp == 4 or die "Unable to completely read command length.\n";
74 $len = unpack("V", $len);
75 (read($socket, $cmd, $len) == $len) or die "Unable to completely read command.\n";
76 my($command, $ptr2params);
77 eval($cmd);
78 my(@retval) = &$command(@{$ptr2params});
79 my $retstr = Data::Dumper->Dump([\@retval], ["ptr2retval"]);
80 print $socket (pack("V", length($retstr)).$retstr);
81 }
82
83 1;