| 1 | package Data::Stream::Bulk::DoneFlag; | ||||||||||
| 2 | 15 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 15 | $Data::Stream::Bulk::DoneFlag::AUTHORITY = 'cpan:NUFFIN'; | |||||||||
| 4 | } | ||||||||||
| 5 | { | ||||||||||
| 6 | 15 | $Data::Stream::Bulk::DoneFlag::VERSION = '0.11'; | |||||||||
| 7 | } | ||||||||||
| 8 | 15 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | # ABSTRACT: Implement the C<is_done> method in terms of a flag | ||||||||||
| 10 | |||||||||||
| 11 | 15 | ▶ | use namespace::clean -except => 'meta'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 15 | with qw(Data::Stream::Bulk); | |||||||||
| 14 | |||||||||||
| 15 | 15 | requires "get_more"; | |||||||||
| 16 | |||||||||||
| 17 | 0 | ▶ | sub is_done {} | ||||||||
|
Subroutine
is_done: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 18 | 15 | has done => ( | |||||||||
| 19 | isa => "Bool", | ||||||||||
| 20 | init_arg => undef, | ||||||||||
| 21 | reader => "is_done", | ||||||||||
| 22 | writer => "_done", | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | 2 | ▶ | sub finished {} | ||||||||
|
Subroutine
finished: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 26 | |||||||||||
| 27 | 10 | ▶ | sub _set_done { | ||||||||
|
Subroutine
_set_done: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 10 | my $self = shift; | |||||||||
| 29 | 10 | $self->_done(1); | |||||||||
| 30 | 10 | $self->finished; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 38 | ▶ | sub next { | ||||||||
|
Subroutine
next: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 34 | 38 | my $self = shift; | |||||||||
| 35 | |||||||||||
| 36 | 38 | ▶ | unless ( $self->is_done ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 36 | ▶ | if ( my $more = $self->get_more ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 26 | return $more; | |||||||||
| 39 | } else { | ||||||||||
| 40 | 10 | $self->_set_done; | |||||||||
| 41 | 10 | return; | |||||||||
| 42 | } | ||||||||||
| 43 | } else { | ||||||||||
| 44 | 2 | return; | |||||||||
| 45 | } | ||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 15 | __PACKAGE__; | |||||||||
| 49 | |||||||||||
| 50 | |||||||||||
| 51 | |||||||||||
| 52 | =pod | ||||||||||
| 53 | |||||||||||
| 54 | =head1 NAME | ||||||||||
| 55 | |||||||||||
| 56 | Data::Stream::Bulk::DoneFlag - Implement the C<is_done> method in terms of a flag | ||||||||||
| 57 | |||||||||||
| 58 | =head1 VERSION | ||||||||||
| 59 | |||||||||||
| 60 | version 0.11 | ||||||||||
| 61 | |||||||||||
| 62 | =head1 SYNOPSIS | ||||||||||
| 63 | |||||||||||
| 64 | package Data::Stream::Bulk::Blah; | ||||||||||
| 65 | use Moose; | ||||||||||
| 66 | |||||||||||
| 67 | with qw(Data::Stream::Bulk::DoneFlag); | ||||||||||
| 68 | |||||||||||
| 69 | sub get_more { | ||||||||||
| 70 | if ( my @more = more() ) { | ||||||||||
| 71 | return \@more; | ||||||||||
| 72 | } else { | ||||||||||
| 73 | return; | ||||||||||
| 74 | } | ||||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | =head1 DESCRIPTION | ||||||||||
| 78 | |||||||||||
| 79 | This role implements the C<Data::Stream::Bulk> core API in terms of one method | ||||||||||
| 80 | (C<get_more>). | ||||||||||
| 81 | |||||||||||
| 82 | As a convenience it calls C<finished> when the stream is exhausted, so that | ||||||||||
| 83 | cleanup may be done. | ||||||||||
| 84 | |||||||||||
| 85 | This is used by classes like L<Data::Stream::Bulk::DBI>, | ||||||||||
| 86 | L<Data::Stream::Bulk::Callback>. | ||||||||||
| 87 | |||||||||||
| 88 | =head1 METHODS | ||||||||||
| 89 | |||||||||||
| 90 | =over 4 | ||||||||||
| 91 | |||||||||||
| 92 | =item is_done | ||||||||||
| 93 | |||||||||||
| 94 | Returns the state of the iterator. | ||||||||||
| 95 | |||||||||||
| 96 | =item next | ||||||||||
| 97 | |||||||||||
| 98 | As long as the iterator is not yet done, calls C<get_more>. | ||||||||||
| 99 | |||||||||||
| 100 | If C<get_more> returned a false value instead of an array reference then | ||||||||||
| 101 | C<done> is set, C<finished> is called, and this C<next> does nothing on | ||||||||||
| 102 | subsequent calls. | ||||||||||
| 103 | |||||||||||
| 104 | =item finished | ||||||||||
| 105 | |||||||||||
| 106 | A noop by default. Can be overridden if so desired. | ||||||||||
| 107 | |||||||||||
| 108 | =back | ||||||||||
| 109 | |||||||||||
| 110 | =head1 REQUIRED_METHODS | ||||||||||
| 111 | |||||||||||
| 112 | =over 4 | ||||||||||
| 113 | |||||||||||
| 114 | =item get_more | ||||||||||
| 115 | |||||||||||
| 116 | Returns the next block of data as an array ref, or a false value if no items | ||||||||||
| 117 | are left. | ||||||||||
| 118 | |||||||||||
| 119 | =back | ||||||||||
| 120 | |||||||||||
| 121 | =head1 AUTHOR | ||||||||||
| 122 | |||||||||||
| 123 | Yuval Kogman <nothingmuch@woobling.org> | ||||||||||
| 124 | |||||||||||
| 125 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 126 | |||||||||||
| 127 | This software is copyright (c) 2012 by Yuval Kogman. | ||||||||||
| 128 | |||||||||||
| 129 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 130 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 131 | |||||||||||
| 132 | =cut | ||||||||||
| 133 | |||||||||||
| 134 | |||||||||||
| 135 | __END__ | ||||||||||