1POE::Filter::Block(3) User Contributed Perl DocumentationPOE::Filter::Block(3)
2
3
4

NAME

6       POE::Filter::Block - translate data between streams and blocks
7

SYNOPSIS

9         #!perl
10
11         use warnings;
12         use strict;
13         use POE::Filter::Block;
14
15         my $filter = POE::Filter::Block->new( BlockSize => 8 );
16
17         # Prints three lines: abcdefgh, ijklmnop, qrstuvwx.
18         # Bytes "y" and "z" remain in the buffer and await completion of the
19         # next 8-byte block.
20
21         $filter->get_one_start([ "abcdefghijklmnopqrstuvwxyz" ]);
22         while (1) {
23           my $block = $filter->get_one();
24           last unless @$block;
25           print $block->[0], "\n";
26         }
27
28         # Print one line: yz123456
29
30         $filter->get_one_start([ "123456" ]);
31         while (1) {
32           my $block = $filter->get_one();
33           last unless @$block;
34           print $block->[0], "\n";
35         }
36

DESCRIPTION

38       POE::Filter::Block translates data between serial streams and blocks.
39       It can handle fixed-length and length-prepended blocks, and it may be
40       extended to handle other block types.
41
42       Fixed-length blocks are used when Block's constructor is called with a
43       BlockSize value.  Otherwise the Block filter uses length-prepended
44       blocks.
45
46       Users who specify block sizes less than one deserve what they get.
47
48       In variable-length mode, a LengthCodec parameter may be specified.  The
49       LengthCodec value should be a reference to a list of two functions: the
50       length encoder, and the length decoder:
51
52         LengthCodec => [ \&encoder, \&decoder ]
53
54       The encoder takes a reference to a buffer and prepends the buffer's
55       length to it.  The default encoder prepends the ASCII representation of
56       the buffer's length and a chr(0) byte to separate the length from the
57       actual data:
58
59         sub _default_encoder {
60           my $stuff = shift;
61           substr($$stuff, 0, 0) = length($$stuff) . "\0";
62           return;
63         }
64
65       The corresponding decoder returns the block length after removing it
66       and the separator from the buffer.  It returns nothing if no length can
67       be determined.
68
69         sub _default_decoder {
70           my $stuff = shift;
71           unless ($$stuff =~ s/^(\d+)\0//s) {
72             warn length($1), " strange bytes removed from stream"
73               if $$stuff =~ s/^(\D+)//s;
74             return;
75           }
76           return $1;
77         }
78
79       This filter holds onto incomplete blocks until they are completed.
80

PUBLIC FILTER METHODS

82       POE::Filter::Block has no additional public methods.
83

SEE ALSO

85       Please see POE::Filter for documentation regarding the base interface.
86
87       The SEE ALSO section in POE contains a table of contents covering the
88       entire POE distribution.
89

BUGS

91       The put() method doesn't verify block sizes.
92

AUTHORS & COPYRIGHTS

94       The Block filter was contributed by Dieter Pearcey, with changes by
95       Rocco Caputo.
96
97       Please see POE for more information about authors and contributors.
98
99
100
101perl v5.12.1                      2010-04-03             POE::Filter::Block(3)
Impressum