GT::IPC::Filter::Line - Implements line based filtering for output streams.
use GT::IPC::Filter::Line;
my $filter = new GT::IPC::Filter::Line( sub { my $line = shift ... } ); # -or- my $filter = new GT::IPC::Filter::Line( output => sub { my $out = shift; .. }, regex => '\r?\n' );
$filter->put(\$data);
$filter->flush;
Implements line based filtering to an output code reference. Used mainly in GT::IPC::Run, the GT::IPC::Run manpage for details.
There are three methods (as with all filters in this class).
Takes either a single argument, which is a code reference to call output with, or a hash of options.
This is the code reference you would like called with each line of output. The lines are stripped of there ending before this is called.
Specify the regex to use in order to determine the end of line sequence. This regex is used in a split on the input stream. If you capture in this regex it will break the output.
Specifies a literal new line sequence. The only difference between this option
and the regex
option is it is quotemeta
, See perlfunc/quotemeta.
This method takes a stream of data, it converted it into line based data and
passes each line to the code reference specified by new()
, see new.
There is buffering that happens here because we have no way of knowing if the
output stream does not end with a new line, also streams almost always get
partial lines.
This method should be called last, when the data stream is over. It flushes the remaining buffer out to the code reference.
Scott Beck
Copyright (c) 2004 Gossamer Threads Inc. All Rights Reserved. http://www.gossamer-threads.com/
Revision: $Id: Line.pm,v 1.7 2004/01/13 01:35:17 jagerman Exp $