fix bug where first event isn't passed to filter during collect w/out inside
[catagits/HTML-Zoom.git] / lib / HTML / Zoom / MappedStream.pm
CommitLineData
8a1c87d1 1package HTML::Zoom::MappedStream;
2
1cf03540 3use strictures 1;
8a1c87d1 4use base qw(HTML::Zoom::StreamBase);
5
6sub new {
7 my ($class, $args) = @_;
8 bless({
9 _source => $args->{source}, _mapper => $args->{mapper},
10 _zconfig => $args->{zconfig}
11 }, $class);
12}
13
b5a48c47 14sub _next {
12bfb3b7 15 my ($self, $am_peek) = @_;
16 return unless $self->{_source};
8a1c87d1 17 # If we were aiming for a "true" perl-like map then we should
18 # elegantly handle the case where the map function returns 0 events
19 # and the case where it returns >1 - if you're reading this comment
20 # because you wanted it to do that, now would be the time to fix it :)
12bfb3b7 21 if (my ($next) = $self->{_source}->${\($am_peek ? 'peek' : 'next')}) {
22 $self->{_peeked_from} = $next if $am_peek;
8a1c87d1 23 local $_ = $next;
24 return $self->{_mapper}->($next);
25 }
26 delete $self->{_source};
27 return
28}
29
301;