File Coverage

lib/Flux/Mapper/MappedIn.pm
Criterion Covered Total %
statement 10 22 45.4
branch 2 10 20.0
condition n/a
subroutine 2 5 40.0
pod 0 4 0.0
total 14 41 34.1


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