| 1 | package Data::Stream::Bulk::Callback; | ||
| 2 | 2 | ▶ | BEGIN { |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 2 | $Data::Stream::Bulk::Callback::AUTHORITY = 'cpan:NUFFIN'; | |
| 4 | } | ||
| 5 | { | ||
| 6 | 2 | $Data::Stream::Bulk::Callback::VERSION = '0.11'; | |
| 7 | } | ||
| 8 | 2 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | # ABSTRACT: Callback based bulk iterator | ||
| 10 | |||
| 11 | 2 | ▶ | use namespace::clean -except => 'meta'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | |||
| 13 | 2 | with qw(Data::Stream::Bulk::DoneFlag) => { -excludes => [qw(is_done finished)] }; | |
| 14 | |||
| 15 | 2 | has callback => ( | |
| 16 | isa => "CodeRef|Str", | ||
| 17 | is => "ro", | ||
| 18 | required => 1, | ||
| 19 | clearer => "finished", | ||
| 20 | ); | ||
| 21 | |||
| 22 | 27 | ▶ | sub get_more { |
|
Subroutine
get_more: called CC=1 SCAR=0.0
Pod
documented
| |||
| 23 | 27 | my $self = shift; | |
| 24 | 27 | my $cb = $self->callback; | |
| 25 | 27 | $self->$cb; | |
| 26 | } | ||
| 27 | |||
| 28 | 2 | __PACKAGE__->meta->make_immutable; | |
| 29 | |||
| 30 | 2 | __PACKAGE__; | |
| 31 | |||
| 32 | |||
| 33 | |||
| 34 | =pod | ||
| 35 | |||
| 36 | =head1 NAME | ||
| 37 | |||
| 38 | Data::Stream::Bulk::Callback - Callback based bulk iterator | ||
| 39 | |||
| 40 | =head1 VERSION | ||
| 41 | |||
| 42 | version 0.11 | ||
| 43 | |||
| 44 | =head1 SYNOPSIS | ||
| 45 | |||
| 46 | Data::Stream::Bulk::Callback->new( | ||
| 47 | callback => sub { | ||
| 48 | if ( @more_items = get_some() ) { | ||
| 49 | return \@more_items; | ||
| 50 | } else { | ||
| 51 | return; # done | ||
| 52 | } | ||
| 53 | }, | ||
| 54 | } | ||
| 55 | |||
| 56 | =head1 DESCRIPTION | ||
| 57 | |||
| 58 | This class provides a callback based implementation of L<Data::Stream::Bulk>. | ||
| 59 | |||
| 60 | =head1 ATTRIBUTES | ||
| 61 | |||
| 62 | =over 4 | ||
| 63 | |||
| 64 | =item callback | ||
| 65 | |||
| 66 | The subroutine that is called when more items are needed. | ||
| 67 | |||
| 68 | Should return an array reference for the next block, or a false value if there | ||
| 69 | is nothing left. | ||
| 70 | |||
| 71 | =back | ||
| 72 | |||
| 73 | =head1 METHODS | ||
| 74 | |||
| 75 | =over 4 | ||
| 76 | |||
| 77 | =item get_more | ||
| 78 | |||
| 79 | See L<Data::Stream::Bulk::DoneFlag>. | ||
| 80 | |||
| 81 | Reinvokes C<callback>. | ||
| 82 | |||
| 83 | =back | ||
| 84 | |||
| 85 | =head1 AUTHOR | ||
| 86 | |||
| 87 | Yuval Kogman <nothingmuch@woobling.org> | ||
| 88 | |||
| 89 | =head1 COPYRIGHT AND LICENSE | ||
| 90 | |||
| 91 | This software is copyright (c) 2012 by Yuval Kogman. | ||
| 92 | |||
| 93 | This is free software; you can redistribute it and/or modify it under | ||
| 94 | the same terms as the Perl 5 programming language system itself. | ||
| 95 | |||
| 96 | =cut | ||
| 97 | |||
| 98 | |||
| 99 | __END__ | ||