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

NAME

6       POE::Filter::Block - filter between streams and blocks
7

SYNOPSIS

9         $filter = POE::Filter::Block->new( BlockSize => 1024 );
10         $filter = POE::Filter::Block->new(
11           LengthCodec => [ \&encoder, \&decoder ]
12         );
13         $arrayref_of_blocks =
14           $filter->get($arrayref_of_raw_chunks_from_driver);
15         $arrayref_of_streamable_chunks_for_driver =
16           $filter->put($arrayref_of_blocks);
17         $arrayref_of_leftovers =
18           $filter->get_pending();
19

DESCRIPTION

21       The Block filter translates data between serial streams and blocks.  It
22       can handle two kinds of block: fixed-length and length-prepended.
23
24       Fixed-length blocks are used when Block's constructor is called with a
25       BlockSize value.  Otherwise the Block filter uses length-prepended
26       blocks.
27
28       Users who specify block sizes less than one deserve to be soundly
29       spanked.
30
31       In variable-length mode, a LengthCodec parameter is valid.  The Length‐
32       Codec should be a list reference of two functions: The length encoder,
33       and the length decoder:
34
35         LengthCodec => [ \&encoder, \&decoder ]
36
37       The encoder takes a reference to a buffer and prepends the buffer's
38       length to it.  The default encoder prepends the ASCII representation of
39       the buffer's length.  The length is separated from the buffer by an
40       ASCII NUL ("\0") character.
41
42         sub _default_encoder {
43           my $stuff = shift;
44           substr($$stuff, 0, 0) = length($$stuff) . "\0";
45           return;
46         }
47
48       Sensibly enough, the corresponding decoder removes the prepended length
49       and separator, returning its numeric value.  It returns nothing if no
50       length can be determined.
51
52         sub _default_decoder {
53           my $stuff = shift;
54           unless ($$stuff =~ s/^(\d+)\0//s) {
55             warn length($1), " strange bytes removed from stream"
56               if $$stuff =~ s/^(\D+)//s;
57             return;
58           }
59           return $1;
60         }
61
62       This filter holds onto incomplete blocks until they are completed.
63

PUBLIC FILTER METHODS

65       Please see POE::Filter.
66

SEE ALSO

68       POE::Filter.
69
70       The SEE ALSO section in POE contains a table of contents covering the
71       entire POE distribution.
72

BUGS

74       The put() method doesn't verify block sizes.
75

AUTHORS & COPYRIGHTS

77       The Block filter was contributed by Dieter Pearcey, with changes by
78       Rocco Caputo.
79
80       Please see POE for more information about authors and contributors.
81
82
83
84perl v5.8.8                       2006-09-01             POE::Filter::Block(3)
Impressum