File Coverage

blib/lib/Child/Link/IPC.pm
Criterion Covered Total %
statement 39 40 97.5
branch 2 2 100.0
condition n/a
subroutine 10 11 90.9
pod 7 7 100.0
total 58 60 96.6


line stmt bran cond sub pod time code
1             package Child::Link::IPC;
2 10     10   45 use strict;
  10         10  
  10         309  
3 10     10   37 use warnings;
  10         10  
  10         172  
4              
5 10     10   28 use Child::Util;
  10         10  
  10         379  
6              
7 10     10   30 use base 'Child::Link';
  10         18  
  10         3169  
8              
9             add_accessors qw/ipc/;
10             add_abstract qw/
11             read_handle
12             write_handle
13             /;
14              
15 0     0 1 0 sub init {}
16              
17             sub new {
18 21     21 1 160 my $class = shift;
19 21         139 my ( $pid, @shared ) = @_;
20 21         474 my $self = $class->SUPER::new($pid);
21 21         412 $self->init( @shared );
22 21         92 return $self;
23             }
24              
25             sub autoflush {
26 28     28 1 79 my $self = shift;
27 28         43 my ( $value ) = @_;
28 28         216 my $write = $self->write_handle;
29              
30 28         280 my $selected = select( $write );
31 28 100       438 $| = $value if @_;
32 28         133 my $out = $|;
33              
34 28         195 select( $selected );
35              
36 28         79 return $out;
37             }
38              
39             sub flush {
40 2     2 1 5000174 my $self = shift;
41 2         15 my $orig = $self->autoflush();
42 2         131 $self->autoflush(1);
43 2         9 my $write = $self->write_handle;
44 2         5 $self->autoflush($orig);
45             }
46              
47             sub read {
48 23     23 1 619 my $self = shift;
49 23         184 my $handle = $self->read_handle;
50 23         13052584 return <$handle>;
51             }
52              
53             sub say {
54 13     13 1 1052 my $self = shift;
55 13         58 $self->write( map {$_ . $/} @_ );
  13         305  
56             }
57              
58             sub write {
59 13     13 1 22 my $self = shift;
60 13         65 my $handle = $self->write_handle;
61 13         4351 print $handle @_;
62             }
63              
64             1;
65              
66             =head1 NAME
67              
68             Child::Link::IPC - Base class for process links that provide IPC.
69              
70             =head1 SEE ALSO
71              
72             This class inherits from:
73              
74             =over 4
75              
76             =item L
77              
78             =back
79              
80             =head1 METHODS
81              
82             =over 4
83              
84             =item $proc->new( $pid. @shared )
85              
86             Constructor
87              
88             =item $proc->read()
89              
90             Read a message from the child.
91              
92             =item $proc->write( @MESSAGES )
93              
94             Send the messages to the child. works like print, you must add "\n".
95              
96             =item $proc->say( @MESSAGES )
97              
98             Send the messages to the child. works like say, adds the separator for you
99             (usually "\n").
100              
101             =item $proc->autoflush( $BOOL )
102              
103             Turn autoflush on/off for the current processes write handle. This is on by
104             default.
105              
106             =item $proc->flush()
107              
108             Flush the current processes write handle.
109              
110             =item $proc->ipc()
111              
112             =item $proc->_ipc( $new )
113              
114             Accessors for you to use or ignore.
115              
116             =back
117              
118             =head1 ABSTRACT METHODS
119              
120             =over 4
121              
122             =item $proc->read_handle()
123              
124             Should return a read handle for reading from the child.
125              
126             =item $proc->write_handle()
127              
128             Should return a write handle for writing to the child.
129              
130             =item $proc->init( @shared )
131              
132             Called by new during construction
133              
134             =back
135              
136             =head1 HISTORY
137              
138             Most of this was part of L intended for use in the L
139             project. Fennec is being broken into multiple parts, this is one such part.
140              
141             =head1 FENNEC PROJECT
142              
143             This module is part of the Fennec project. See L for more details.
144             Fennec is a project to develop an extendable and powerful testing framework.
145             Together the tools that make up the Fennec framework provide a potent testing
146             environment.
147              
148             The tools provided by Fennec are also useful on their own. Sometimes a tool
149             created for Fennec is useful outside the greater framework. Such tools are
150             turned into their own projects. This is one such project.
151              
152             =over 2
153              
154             =item L - The core framework
155              
156             The primary Fennec project that ties them all together.
157              
158             =back
159              
160             =head1 AUTHORS
161              
162             Chad Granum L
163              
164             =head1 COPYRIGHT
165              
166             Copyright (C) 2010 Chad Granum
167              
168             Child is free software; Standard perl licence.
169              
170             Child is distributed in the hope that it will be useful, but WITHOUT
171             ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
172             FOR A PARTICULAR PURPOSE. See the license for more details.