File Coverage

blib/lib/RMI/Client/ForkedPipes.pm
Criterion Covered Total %
statement 38 41 92.6
branch 4 6 66.6
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 49 54 90.7


line stmt bran cond sub pod time code
1             package RMI::Client::ForkedPipes;
2              
3 21     21   190657 use strict;
  21         44  
  21         1547  
4 21     21   125 use warnings;
  21         37  
  21         1239  
5             our $VERSION = $RMI::VERSION;
6              
7 21     21   120 use base 'RMI::Client';
  21         49  
  21         14423  
8              
9 21     21   14194 use RMI::Server::ForkedPipes;
  21         59  
  21         652  
10 21     21   23665 use IO::Handle; # "thousands of lines just for autoflush" :(
  21         149250  
  21         6620  
11              
12             RMI::Node::_mk_ro_accessors(__PACKAGE__,'peer_pid');
13              
14             sub new {
15 21     21 1 15856 my $class = shift;
16            
17 21         46 my $parent_reader;
18             my $parent_writer;
19 0         0 my $child_reader;
20 0         0 my $child_writer;
21 21         751 pipe($parent_reader, $child_writer);
22 21         446 pipe($child_reader, $parent_writer);
23 21         201 $child_writer->autoflush(1);
24 21         1446 $parent_writer->autoflush(1);
25            
26 21         588 my $parent_pid = $$;
27 21         26155 my $child_pid = fork();
28 21 50       2012 die "cannot fork: $!" unless defined $child_pid;
29 21 100       865 unless ($child_pid) {
30             # child process acts as a server for this test and then exits...
31 10         826 close $child_reader; close $child_writer;
  10         241  
32            
33             # if a command was passed to the constructor, we exec() it.
34             # this allows us to use a custom server, possibly one
35             # in a different language..
36 10 50       809 if (@_) {
37 0         0 exec(@_);
38             }
39            
40             # otherwise, we do the servicing in Perl
41 10         415 $RMI::DEBUG_MSG_PREFIX = ' ';
42 10         1824 my $server = RMI::Server::ForkedPipes->new(
43             peer_pid => $parent_pid,
44             writer => $parent_writer,
45             reader => $parent_reader,
46             );
47 10         598 $server->run;
48 10         269 close $parent_reader; close $parent_writer;
  10         136  
49 10         1664 exit;
50             }
51              
52             # parent/original process is the client which does tests
53 11         381 close $parent_reader; close $parent_writer;
  11         267  
54              
55 11         1958 my $self = $class->SUPER::new(
56             peer_pid => $child_pid,
57             writer => $child_writer,
58             reader => $child_reader,
59             );
60              
61 11         840 return $self;
62             }
63              
64             1;
65              
66              
67             =pod
68              
69             =head1 NAME
70              
71             RMI::Client::ForkedPipes - an RMI::Client implementation with a private out-of-process server
72              
73             =head1 VERSION
74              
75             This document describes RMI::Clinet::ForkedPipes v0.10.
76              
77             =head1 SYNOPSIS
78              
79             $c1 = RMI::Client::ForkedPipes->new();
80             $remote_hash1 = $c1->call_eval('{}');
81             $remote_hash1{key1} = 123;
82              
83             $c2 = RMI::Client::ForkedPipes->new('some_server',$arg1,$arg2);
84              
85             =head1 DESCRIPTION
86              
87             This subclass of RMI::Client forks a child process, and starts an
88             RMI::Server::ForkedPipes in that process. It is useful for testing
89             more complex RMI, and also to do things like use two versions of
90             a module at once in the same program.
91              
92             =head1 METHODS
93              
94             =head2 peer_pid
95            
96             Both the RMI::Client::ForkedPipes and RMI::Server::ForkedPipes have a method to
97             return the process ID of their remote partner.
98              
99             =head1 BUGS AND CAVEATS
100              
101             See general bugs in B for general system limitations of proxied objects.
102              
103             =head1 SEE ALSO
104              
105             B, B, B, B, B, B
106              
107             =head1 AUTHORS
108              
109             Scott Smith
110              
111             =head1 COPYRIGHT
112              
113             Copyright (c) 2008 - 2009 Scott Smith All rights reserved.
114              
115             =head1 LICENSE
116              
117             This program is free software; you can redistribute it and/or modify it under
118             the same terms as Perl itself.
119              
120             The full text of the license can be found in the LICENSE file included with this
121             module.
122              
123             =cut
124