Commit | Line | Data |
8a1c87d1 |
1 | package HTML::Zoom::MappedStream; |
2 | |
3 | use strict; |
4 | use warnings FATAL => 'all'; |
5 | use base qw(HTML::Zoom::StreamBase); |
6 | |
7 | sub new { |
8 | my ($class, $args) = @_; |
9 | bless({ |
10 | _source => $args->{source}, _mapper => $args->{mapper}, |
11 | _zconfig => $args->{zconfig} |
12 | }, $class); |
13 | } |
14 | |
b5a48c47 |
15 | sub _next { |
8a1c87d1 |
16 | return unless (my $self = shift)->{_source}; |
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 :) |
21 | if (my ($next) = $self->{_source}->next) { |
22 | local $_ = $next; |
23 | return $self->{_mapper}->($next); |
24 | } |
25 | delete $self->{_source}; |
26 | return |
27 | } |
28 | |
29 | 1; |