Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added flush/autoflush docs

  • Loading branch information...
commit 06df6c993187179be916cef1ae77daa8089f4368 1 parent 9bc98bf
@exodist authored
Showing with 29 additions and 1 deletion.
  1. +11 −1 lib/Child.pm
  2. +18 −0 t/Child.t
View
12 lib/Child.pm
@@ -190,6 +190,7 @@ sub autoflush {
my $write = $self->_write_handle;
my $selected = select( $write );
+ no warnings 'uninitialized';
$| = ($value || undef) if @_;
my $out = $|;
@@ -203,7 +204,7 @@ sub flush {
my $orig = $self->autoflush();
$self->autoflush(1);
my $write = $self->_write_handle;
- print $write "";
+# print $write "";
$self->autoflush($orig);
}
@@ -369,6 +370,15 @@ Send the messages to the child. works like print, you must add "\n".
Send the messages to the child. works like say, adds the seperator for you
(usually "\n").
+=item $child->autoflush( $BOOL )
+
+Turn autoflush on/off for the current processes write handle. This is on by
+default.
+
+=item $child->flush()
+
+Flush the current processes write handle.
+
=item $child->pid()
Returns the child PID (only in parent process).
View
18 t/Child.t
@@ -59,4 +59,22 @@ ok( $one->is_complete, "Complete" );
is( $one->exit_status, 2, "Exit 2" );
ok( $one->unix_exit > 2, "Real exit" );
+$one = $CLASS->new( sub {
+ my $self = shift;
+ $self->autoflush(0);
+ $self->say( "A" );
+ $self->flush;
+ $self->say( "B" );
+ sleep 5;
+ $self->flush;
+}, pipe => 1 );
+
+$one->start;
+is( $one->read(), "A\n", "A" );
+my $start = time;
+is( $one->read(), "B\n", "B" );
+my $end = time;
+
+ok( $end - $start > 2, "No autoflush" );
+
done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.