1 package HTML::Zoom::StreamBase;
4 use warnings FATAL => 'all';
8 if (exists $self->{_peeked}) {
9 return ($self->{_peeked});
11 if (my ($peeked) = $self->next) {
12 return ($self->{_peeked} = $peeked);
18 my $source_stream = shift;
19 require HTML::Zoom::CodeStream;
21 HTML::Zoom::CodeStream->new({
23 return unless $source_stream;
25 until (($next) = ($cur_stream ? $cur_stream->next : ())) {
26 unless (($cur_stream) = $source_stream->next) {
27 undef $source_stream; return;
36 my ($source_stream, $map_func) = @_;
37 require HTML::Zoom::CodeStream;
38 HTML::Zoom::CodeStream->new({
40 return unless $source_stream;
41 # If we were aiming for a "true" perl-like map then we should
42 # elegantly handle the case where the map function returns 0 events
43 # and the case where it returns >1 - if you're reading this comment
44 # because you wanted it to do that, now would be the time to fix it :)
45 if (my ($next) = $source_stream->next) {
46 #### XXXX collapsing this into a return doesn't work. what the
47 #### flying fornication ... -- mst
48 my $mapped = do { local $_ = $next; $map_func->($next) };
51 undef $source_stream; return;