| 1 | package Flux::Mapper::MappedIn; | ||||||||||
| 2 | { | ||||||||||
| 3 | 4 | $Flux::Mapper::MappedIn::VERSION = '1.03'; | |||||||||
| 4 | } | ||||||||||
| 5 | |||||||||||
| 6 | # ABSTRACT: representation of in|mapper | ||||||||||
| 7 | |||||||||||
| 8 | |||||||||||
| 9 | 4 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 4 | with 'Flux::In'; | |||||||||
| 11 | |||||||||||
| 12 | 4 | has 'mapper' => ( | |||||||||
| 13 | is => 'ro', | ||||||||||
| 14 | required => 1, | ||||||||||
| 15 | ); | ||||||||||
| 16 | |||||||||||
| 17 | 4 | has 'in' => ( | |||||||||
| 18 | is => 'ro', | ||||||||||
| 19 | required => 1, | ||||||||||
| 20 | ); | ||||||||||
| 21 | |||||||||||
| 22 | 5 | ▶ | sub read { | ||||||||
|
Subroutine
read: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||
| 23 | 5 | my $self = shift; | |||||||||
| 24 | |||||||||||
| 25 | 5 | ▶ | while (my $item = $self->in->read) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 4 | my @mapped = $self->mapper->write($item); | |||||||||
| 27 | 4 | ▶ | next unless @mapped; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 4 | ▶ | die "One-to-many not implemented in input stream mappers" unless @mapped == 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 4 | return $mapped[0]; | |||||||||
| 30 | } | ||||||||||
| 31 | 1 | return; # underlying input stream is depleted | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 0 | ▶ | sub read_chunk { | ||||||||
|
Subroutine
read_chunk: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 35 | 0 | my $self = shift; | |||||||||
| 36 | 0 | my ($limit) = @_; | |||||||||
| 37 | |||||||||||
| 38 | 0 | my $chunk = $self->in->read_chunk($limit); | |||||||||
| 39 | 0 | ▶ | return unless $chunk; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 0 | return $self->mapper->write_chunk($chunk); | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | sub commit { | ||||||||
|
Subroutine
commit: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 44 | 0 | my ($self) = @_; | |||||||||
| 45 | 0 | my @items = $self->mapper->commit; | |||||||||
| 46 | 0 | ▶ | die "flushable mappers cannot be attached to input streams" if @items; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | #FIXME: check it earlier | ||||||||||
| 48 | 0 | $self->in->commit; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | sub lag { | ||||||||
|
Subroutine
lag: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 52 | 0 | my $self = shift; | |||||||||
| 53 | 0 | ▶ | die "underlying input stream doesn't implement Lag role" unless $self->in->does('Flux::In::Role::Lag'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | return $self->in->lag; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 1 | ▶ | around 'does' => sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=16.7
| |||||||||||
| 58 | 1 | my $orig = shift; | |||||||||
| 59 | 1 | my $self = shift; | |||||||||
| 60 | 1 | ▶ | return 1 if $orig->($self, @_); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | |||||||||||
| 62 | 0 | my ($role) = @_; | |||||||||
| 63 | |||||||||||
| 64 | 0 | ▶ | if ($role eq 'Flux::In::Role::Lag') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | # Some roles depend on being implemented by the underlying input stream. | ||||||||||
| 66 | 0 | return $self->in->does($role); | |||||||||
| 67 | } | ||||||||||
| 68 | 0 | return; | |||||||||
| 69 | 4 | }; | |||||||||
| 70 | |||||||||||
| 71 | 4 | 1; | |||||||||
| 72 | |||||||||||
| 73 | __END__ | ||||||||||