| 1 | package TaskPipe::Iterator; | ||
| 2 | |||
| 3 | 38 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 38 | with 'MooseX::ConfigCascade'; | |
| 5 | |||
| 6 | |||
| 7 | 38 | has 'next' => (is => 'rw', isa => 'CodeRef'); | |
| 8 | 38 | has 'reset' => (is => 'rw', isa => 'CodeRef'); | |
| 9 | 0 | ▶ | has 'count' => (is => 'rw', isa => 'CodeRef', default => sub{sub{return -1}}); |
|
Subroutine
__ANON__: not called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.4
| |||
| 10 | |||
| 11 | |||
| 12 | =head1 NAME | ||
| 13 | |||
| 14 | TaskPipe::Iterator - generic class for TaskPipe Iterators | ||
| 15 | |||
| 16 | =head1 DESCRIPTION | ||
| 17 | |||
| 18 | If you are creating an iterator, you can either get a new instance | ||
| 19 | of a generic iterator and then supply the subs: | ||
| 20 | |||
| 21 | my $iterator = TaskPipe::Iterator->new( | ||
| 22 | |||
| 23 | next => sub{ | ||
| 24 | #... | ||
| 25 | }, | ||
| 26 | |||
| 27 | count => sub { | ||
| 28 | #... | ||
| 29 | }, | ||
| 30 | |||
| 31 | reset => sub { | ||
| 32 | # ... | ||
| 33 | } | ||
| 34 | |||
| 35 | ); | ||
| 36 | |||
| 37 | or you can inherit from L<TaskPipe::Iterator> and override the subs. All 3 subs must be provided - however | ||
| 38 | |||
| 39 | =head1 SUBS | ||
| 40 | |||
| 41 | =head2 next | ||
| 42 | |||
| 43 | This sub should iterate the record pointer and return the next record | ||
| 44 | |||
| 45 | =head2 reset | ||
| 46 | |||
| 47 | This sub should reset the record pointer to the first record. | ||
| 48 | |||
| 49 | =head2 count | ||
| 50 | |||
| 51 | Optional. If you know how many records you are expecting, then this sub should return this value. Including C<count> offers a small performance boost by using the parent thread to execute the last record instead of idling. If the total number of records is not known in advance (often the case with iterators) then this sub should return -1. A sub that returns -1 is the default - so you can just omit this attribute if you don't have a way to calculate the total number of results. | ||
| 52 | |||
| 53 | =head1 AUTHOR | ||
| 54 | |||
| 55 | Tom Gracey <tomgracey@gmail.com> | ||
| 56 | |||
| 57 | =head1 COPYRIGHT AND LICENSE | ||
| 58 | |||
| 59 | Copyright (c) Tom Gracey 2018 | ||
| 60 | |||
| 61 | TaskPipe is free software, licensed under | ||
| 62 | |||
| 63 | The GNU Public License Version 3 | ||
| 64 | |||
| 65 | =cut | ||
| 66 | |||
| 67 | |||
| 68 | 38 | __PACKAGE__->meta->make_immutable; | |
| 69 | 38 | 1; | |
| 70 | |||