| 1 | package Brackup::ChunkIterator; | ||||||||||
| 2 | 13 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 13 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 13 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 5 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 7 | 5 | my ($class, @files) = @_; | |||||||||
| 8 | 5 | return bless { | |||||||||
| 9 | filelist => \@files, | ||||||||||
| 10 | chunkmag => [], | ||||||||||
| 11 | }, $class; | ||||||||||
| 12 | } | ||||||||||
| 13 | |||||||||||
| 14 | # returns either PositionedChunks, or, in cases of files | ||||||||||
| 15 | # without contents (like directories/symlinks), returns | ||||||||||
| 16 | # File objects... returns undef on end of files/chunks. | ||||||||||
| 17 | 87 | ▶ | sub next { | ||||||||
|
Subroutine
next: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 18 | 87 | my $self = shift; | |||||||||
| 19 | |||||||||||
| 20 | # magazine already loaded? fire. | ||||||||||
| 21 | 87 | my $next = shift @{ $self->{chunkmag} }; | |||||||||
| 22 | 87 | ▶ | return $next if $next; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | |||||||||||
| 24 | # else reload... | ||||||||||
| 25 | 75 | ▶ | my $file = shift @{ $self->{filelist} } or | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | return undef; | ||||||||||
| 27 | |||||||||||
| 28 | 70 | ($next, @{$self->{chunkmag}}) = $file->chunks; | |||||||||
| 29 | 70 | ▶ | return $next if $next; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 13 | return $file; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 0 | ▶ | sub mux_into { | ||||||||
|
Subroutine
mux_into: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 34 | 0 | my ($self, $n_copies) = @_; | |||||||||
| 35 | 0 | my @iters; | |||||||||
| 36 | 0 | for (1..$n_copies) { | |||||||||
| 37 | 0 | push @iters, Brackup::ChunkIterator::SlaveIterator->new; | |||||||||
| 38 | } | ||||||||||
| 39 | 0 | ▶ | my $on_empty = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 40 | 0 | my $next = $self->next; | |||||||||
| 41 | 0 | foreach my $peer (@iters) { | |||||||||
| 42 | 0 | push @{$peer->{mag}}, $next; | |||||||||
| 43 | } | ||||||||||
| 44 | 0 | }; | |||||||||
| 45 | 0 | foreach (@iters) { | |||||||||
| 46 | 0 | $_->{on_empty} = $on_empty; | |||||||||
| 47 | } | ||||||||||
| 48 | 0 | return @iters; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | package Brackup::ChunkIterator::SlaveIterator; | ||||||||||
| 52 | 13 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 53 | 13 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 54 | 13 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||||||||||
| 57 | 0 | my $class = shift; | |||||||||
| 58 | 0 | return bless { | |||||||||
| 59 | 'on_empty' => undef, # subref | ||||||||||
| 60 | 'mag' => [], | ||||||||||
| 61 | }, $class; | ||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 0 | ▶ | sub next { | ||||||||
|
Subroutine
next: not called CC=2 SCAR=17.9
| |||||||||||
| 65 | 0 | my $self = shift; | |||||||||
| 66 | # the magazine itself could be true, but contain only undef: (undef), | ||||||||||
| 67 | # which signals the end. | ||||||||||
| 68 | 0 | ▶ | return shift @{$self->{mag}} if @{$self->{mag}}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 0 | $self->{on_empty}->(); | |||||||||
| 70 | 0 | return shift @{$self->{mag}}; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 0 | ▶ | sub behind_by { | ||||||||
|
Subroutine
behind_by: not called CC=1 SCAR=6.9
| |||||||||||
| 74 | 0 | my $self = shift; | |||||||||
| 75 | 0 | return scalar @{$self->{mag}}; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 13 | 1; | |||||||||