| 1 | package Data::Stream::Bulk::Filter; | ||||||||||||||||||||||||
| 2 | 15 | ▶ | BEGIN { | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 3 | 15 | $Data::Stream::Bulk::Filter::AUTHORITY = 'cpan:NUFFIN'; | |||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||
| 5 | { | ||||||||||||||||||||||||
| 6 | 15 | $Data::Stream::Bulk::Filter::VERSION = '0.11'; | |||||||||||||||||||||||
| 7 | } | ||||||||||||||||||||||||
| 8 | 15 | ▶ | use Moose; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 9 | # ABSTRACT: Streamed filtering (block oriented) | ||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||
| 11 | 15 | ▶ | use Data::Stream::Bulk; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||
| 13 | 15 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||
| 15 | 15 | has filter => ( | |||||||||||||||||||||||
| 16 | isa => "CodeRef", | ||||||||||||||||||||||||
| 17 | reader => "filter_body", | ||||||||||||||||||||||||
| 18 | required => 1, | ||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||
| 21 | 15 | has stream => ( | |||||||||||||||||||||||
| 22 | does => "Data::Stream::Bulk", | ||||||||||||||||||||||||
| 23 | is => "ro", | ||||||||||||||||||||||||
| 24 | required => 1, | ||||||||||||||||||||||||
| 25 | handles => [qw(is_done loaded)], | ||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||
| 28 | 15 | with qw(Data::Stream::Bulk) => { -excludes => 'loaded' }; | |||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||
| 30 | 284 | ▶ | sub next { | ||||||||||||||||||||||
|
Subroutine
next: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||
| 31 | 284 | my $self = shift; | |||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||
| 33 | 284 | local $_ = $self->stream->next; | |||||||||||||||||||||||
| 34 | 284 | ▶ | return $_ && ( $self->filter_body->($_) || [] ); | ||||||||||||||||||||||
|
Condition60%3/5
$_ && ($self->filter_body->($_) || [])
$self->filter_body->($_) or []
MC/DC50%1/2
$_ && ($self->filter_body->($_) || [])
$_
$self->filter_body->($_)
Truth table66%2/3
A && B
A= $_B= $self->filter_body->($_)
| |||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||
| 37 | 15 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||
| 39 | 15 | __PACKAGE__; | |||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||
| 43 | =pod | ||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||
| 45 | =head1 NAME | ||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||
| 47 | Data::Stream::Bulk::Filter - Streamed filtering (block oriented) | ||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||
| 49 | =head1 VERSION | ||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||
| 51 | version 0.11 | ||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||
| 53 | =head1 SYNOPSIS | ||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||
| 55 | use Data::Stream::Bulk::Filter; | ||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||
| 57 | Data::Stream::Bulk::Filter->new( | ||||||||||||||||||||||||
| 58 | filter => sub { ... }, | ||||||||||||||||||||||||
| 59 | stream => $stream, | ||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||
| 62 | =head1 DESCRIPTION | ||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||
| 64 | This class implements filtering of streams. | ||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||
| 66 | =head1 ATTRIBUTES | ||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||
| 68 | =over 4 | ||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||
| 70 | =item filter | ||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||
| 72 | The code reference to apply to each block. | ||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||
| 74 | The block is passed to the filter both in C<$_> and as the first argument. | ||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||
| 76 | The return value should be an array reference. If no true value is returned the | ||||||||||||||||||||||||
| 77 | output stream does B<not> end, but instead an empty block is substituted (the | ||||||||||||||||||||||||
| 78 | parent stream controls when the stream is depleted). | ||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||
| 80 | =item stream | ||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||
| 82 | The stream to be filtered | ||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||
| 84 | =back | ||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||
| 86 | =head1 METHODS | ||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||
| 88 | =over 4 | ||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||
| 90 | =item is_done | ||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||
| 92 | =item loaded | ||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||
| 94 | Delegated to C<stream> | ||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||
| 96 | =item next | ||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||
| 98 | Calls C<next> on C<stream> and applies C<filter> if a block was returned. | ||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||
| 100 | =back | ||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||
| 102 | =head1 AUTHOR | ||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||
| 104 | Yuval Kogman <nothingmuch@woobling.org> | ||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||
| 106 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||
| 108 | This software is copyright (c) 2012 by Yuval Kogman. | ||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||
| 110 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||
| 111 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||
| 113 | =cut | ||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||
| 116 | __END__ | ||||||||||||||||||||||||