1POE::Filter::Line(3)  User Contributed Perl Documentation POE::Filter::Line(3)
2
3
4

NAME

6       POE::Filter::Line - serialize and parse terminated records (lines)
7

SYNOPSIS

9         #!perl
10
11         use POE qw(Wheel::FollowTail Filter::Line);
12
13         POE::Session->create(
14           inline_states => {
15             _start => sub {
16               $_[HEAP]{tailor} = POE::Wheel::FollowTail->new(
17                 Filename => "/var/log/system.log",
18                 InputEvent => "got_log_line",
19                 Filter => POE::Filter::Line->new(),
20               );
21             },
22             got_log_line => sub {
23               print "Log: $_[ARG0]\n";
24             }
25           }
26         );
27
28         POE::Kernel->run();
29         exit;
30

DESCRIPTION

32       POE::Filter::Line parses stream data into terminated records.  The
33       default parser interprets newlines as the record terminator, and the
34       default serializer appends network newlines (CR/LF, or "\x0D\x0A") to
35       outbound records.
36
37       Record terminators are removed from the data POE::Filter::Line returns.
38
39       POE::Filter::Line supports a number of other ways to parse lines.
40       Constructor parameters may specify literal newlines, regular
41       expressions, or that the filter should detect newlines on its own.
42

PUBLIC FILTER METHODS

44       POE::Filter::Line's new() method has some interesting parameters.
45
46   new
47       new() accepts a list of named parameters.
48
49       In all cases, the data interpreted as the record terminator is stripped
50       from the data POE::Filter::Line returns.
51
52       "InputLiteral" may be used to parse records that are terminated by some
53       literal string.  For example, POE::Filter::Line may be used to parse
54       and emit C-style lines, which are terminated with an ASCII NUL:
55
56         my $c_line_filter = POE::Filter::Line->new(
57           InputLiteral => chr(0),
58           OutputLiteral => chr(0),
59         );
60
61       "OutputLiteral" allows a filter to put() records with a different
62       record terminator than it parses.  This can be useful in applications
63       that must translate record terminators.
64
65       "Literal" is a shorthand for the common case where the input and output
66       literals are identical.  The previous example may be written as:
67
68         my $c_line_filter = POE::Filter::Line->new(
69           Literal => chr(0),
70         );
71
72       An application can also allow POE::Filter::Line to figure out which
73       newline to use.  This is done by specifying "InputLiteral" to be undef:
74
75         my $whichever_line_filter = POE::Filter::Line->new(
76           InputLiteral => undef,
77           OutputLiteral => "\n",
78         );
79
80       "InputRegexp" may be used in place of "InputLiteral" to recognize line
81       terminators based on a regular expression.  In this example, input is
82       terminated by two or more consecutive newlines.  On output, the
83       paragraph separator is "---" on a line by itself.
84
85         my $paragraph_filter = POE::Filter::Line->new(
86           InputRegexp => "([\x0D\x0A]{2,})",
87           OutputLiteral => "\n---\n",
88         );
89
90       "MaxBuffer" sets the maximum amount of data that the filter will hold
91       onto while trying to find a line ending.  Defaults to 512 MB.
92
93       "MaxLength" sets the maximum length of a line.  Defaults to 64 MB.
94
95       If either the "MaxLength" or "MaxBuffer" constraint is exceeded,
96       "POE::Filter::Line" will throw an exception.
97

PUBLIC FILTER METHODS

99       POE::Filter::Line has no additional public methods.
100

SUBCLASSING

102       POE::Filter::Line exports the FIRST_UNUSED constant.  This points to
103       the first unused element in the $self array reference.  Subclasses
104       should store their own data beginning here, and they should export
105       their own FIRST_UNUSED constants to help future subclassers.
106

SEE ALSO

108       Please see POE::Filter for documentation regarding the base interface.
109
110       The SEE ALSO section in POE contains a table of contents covering the
111       entire POE distribution.
112

BUGS

114       The default input newline parser is a regexp that has an unfortunate
115       race condition.  First the regular expression:
116
117         /(\x0D\x0A?|\x0A\x0D?)/
118
119       While it quickly recognizes most forms of newline, it can sometimes
120       detect an extra blank line.  This happens when a two-byte newline
121       character is broken between two reads.  Consider this situation:
122
123         some stream dataCR
124         LFother stream data
125
126       The regular expression will see the first CR without its corresponding
127       LF.  The filter will properly return "some stream data" as a line.
128       When the next packet arrives, the leading "LF" will be treated as the
129       terminator for a 0-byte line.  The filter will faithfully return this
130       empty line.
131
132       It is advised to specify literal newlines or use the autodetect feature
133       in applications where blank lines are significant.
134

AUTHORS & COPYRIGHTS

136       Please see POE for more information about authors and contributors.
137
138
139
140perl v5.38.0                      2023-07-21              POE::Filter::Line(3)
Impressum