POE::Filter::Line - serialize and parse terminated records (lines)
Contents
Bugs
The default input newline parser is a regexp that has an unfortunate race condition. First the regular
expression:
/(\x0D\x0A?|\x0A\x0D?)/
While it quickly recognizes most forms of newline, it can sometimes detect an extra blank line. This
happens when a two-byte newline character is broken between two reads. Consider this situation:
some stream dataCR
LFother stream data
The regular expression will see the first CR without its corresponding LF. The filter will properly
return "some stream data" as a line. When the next packet arrives, the leading "LF" will be treated as
the terminator for a 0-byte line. The filter will faithfully return this empty line.
Itisadvisedtospecifyliteralnewlinesorusetheautodetectfeatureinapplicationswhereblanklinesaresignificant.Description
POE::Filter::Line parses stream data into terminated records. The default parser interprets newlines as
the record terminator, and the default serializer appends network newlines (CR/LF, or "\x0D\x0A") to
outbound records.
Record terminators are removed from the data POE::Filter::Line returns.
POE::Filter::Line supports a number of other ways to parse lines. Constructor parameters may specify
literal newlines, regular expressions, or that the filter should detect newlines on its own.
Name
POE::Filter::Line - serialize and parse terminated records (lines)
Public Filter Methods
POE::Filter::Line has no additional public methods.
See Also
Please see POE::Filter for documentation regarding the base interface.
The SEE ALSO section in POE contains a table of contents covering the entire POE distribution.
Subclassing
POE::Filter::Line exports the FIRST_UNUSED constant. This points to the first unused element in the
$self array reference. Subclasses should store their own data beginning here, and they should export
their own FIRST_UNUSED constants to help future subclassers.
Synopsis
#!perl
use POE qw(Wheel::FollowTail Filter::Line);
POE::Session->create(
inline_states => {
_start => sub {
$_[HEAP]{tailor} = POE::Wheel::FollowTail->new(
Filename => "/var/log/system.log",
InputEvent => "got_log_line",
Filter => POE::Filter::Line->new(),
);
},
got_log_line => sub {
print "Log: $_[ARG0]\n";
}
}
);
POE::Kernel->run();
exit;
