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

PUBLIC FILTER METHODS

91       POE::Filter::Line has no additional public methods.
92

SEE ALSO

94       Please see POE::Filter for documentation regarding the base interface.
95
96       The SEE ALSO section in POE contains a table of contents covering the
97       entire POE distribution.
98

BUGS

100       The default input newline parser is a regexp that has an unfortunate
101       race condition.  First the regular expression:
102
103         /(\x0D\x0A?|\x0A\x0D?)/
104
105       While it quickly recognizes most forms of newline, it can sometimes
106       detect an extra blank line.  This happens when a two-byte newline
107       character is broken between two reads.  Consider this situation:
108
109         some stream dataCR
110         LFother stream data
111
112       The regular expression will see the first CR without its corresponding
113       LF.  The filter will properly return "some stream data" as a line.
114       When the next packet arrives, the leading "LF" will be treated as the
115       terminator for a 0-byte line.  The filter will faithfully return this
116       empty line.
117
118       It is advised to specify literal newlines or use the autodetect feature
119       in applications where blank lines are significant.
120

AUTHORS & COPYRIGHTS

122       Please see POE for more information about authors and contributors.
123
124
125
126perl v5.12.1                      2010-04-03              POE::Filter::Line(3)
Impressum