add basic inflation wrapper and simple inflator
[dbsrgits/DBIx-Data-Store.git] / lib / DBIx / Data / Stream / Mapped.pm
1 package DBIx::Data::Stream::Mapped;
2
3 use strictures 1;
4
5 sub new {
6   my $proto = shift;
7   bless({ %{$_[0]} }, ref($proto)||$proto);
8 }
9
10 sub _inner { shift->{inner} }
11 sub _clear_inner { delete shift->{inner} }
12 sub _mapper { shift->{mapper} }
13
14 sub next {
15   return unless my $inner = (my $self = shift)->_inner;
16   # If we were aiming for a "true" perl-like map then we should
17   # elegantly handle the case where the map function returns 0 events
18   # and the case where it returns >1 - if you're reading this comment
19   # because you wanted it to do that, now would be the time to fix it :)
20   my $mapper = $self->_mapper;
21   if (my ($next) = $inner->next) {
22     local $_ = $next;
23     return $mapper->($next);
24   }
25   $self->_clear_inner;
26   return
27 }
28
29 1;