Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / Data / Stream / Bulk / Callback.pm
1 #!/usr/bin/perl
2
3 package Data::Stream::Bulk::Callback;
4 use Moose;
5
6 use namespace::clean -except => 'meta';
7
8 with qw(Data::Stream::Bulk::DoneFlag) => { excludes => [qw(is_done finished)] };
9
10 has callback => (
11         isa => "CodeRef|Str",
12         is  => "ro",
13         required => 1,
14         clearer  => "finished",
15 );
16
17 sub get_more {
18         my $self = shift;
19         my $cb = $self->callback;
20         $self->$cb;
21 }
22
23 __PACKAGE__->meta->make_immutable;
24
25 __PACKAGE__
26
27 __END__
28
29 =pod
30
31 =head1 NAME
32
33 Data::Stream::Bulk::Callback - Callback based bulk iterator
34
35 =head1 SYNOPSIS
36
37         Data::Stream::Bulk::Callback->new(
38                 callback => sub {
39                         if ( @more_items = get_some() ) {
40                                 return \@more_items;
41                         } else {
42                                 return; # done
43                         }
44                 },
45         }
46
47 =head1 DESCRIPTION
48
49 This class provides a callback based implementation of L<Data::Stream::Bulk>.
50
51 =head1 ATTRIBUTES
52
53 =over 4
54
55 =item callback
56
57 The subroutine that is called when more items are needed.
58
59 Should return an array reference for the next block, or a false value if there
60 is nothing left.
61
62 =back
63
64 =head1 METHODS
65
66 =over 4
67
68 =item get_more
69
70 See L<Data::Stream::Bulk::DoneFlag>.
71
72 Reinvokes C<callback>.
73
74 =back
75
76 =cut
77