3 package Data::Stream::Bulk::Filter;
6 use Data::Stream::Bulk;
8 use namespace::clean -except => 'meta';
12 reader => "filter_body",
17 does => "Data::Stream::Bulk",
20 handles => [qw(is_done loaded)],
23 with qw(Data::Stream::Bulk) => { excludes => 'loaded' };
28 local $_ = $self->stream->next;
29 return $_ && ( $self->filter_body->($_) || [] );
32 __PACKAGE__->meta->make_immutable;
42 Data::Stream::Bulk::Filter - Streamed filtering (block oriented)
46 use Data::Stream::Bulk::Filter;
48 Data::Stream::Bulk::Filter->new(
49 filter => sub { ... },
55 This class implements filtering of streams.
63 The code reference to apply to each block.
65 The block is passed to the filter both in C<$_> and as the first argument.
67 The return value should be an array reference. If no true value is returned the
68 output stream does B<not> end, but instead an empty block is substituted (the
69 parent stream controls when the stream is depleted).
73 The stream to be filtered
85 Delegated to C<stream>
89 Calls C<next> on C<stream> and applies C<filter> if a block was returned.