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 #::Dwarn $source_stream;
27 unless (($cur_stream) = $source_stream->next) {
28 undef $source_stream; return;
38 my ($source_stream, $map_func) = @_;
39 require HTML::Zoom::CodeStream;
40 HTML::Zoom::CodeStream->new({
42 return unless $source_stream;
43 # If we were aiming for a "true" perl-like map then we should
44 # elegantly handle the case where the map function returns 0 events
45 # and the case where it returns >1 - if you're reading this comment
46 # because you wanted it to do that, now would be the time to fix it :)
47 if (my ($next) = $source_stream->next) {
48 #### XXXX collapsing this into a return doesn't work. what the
49 #### flying fornication ... -- mst
50 my $mapped = do { local $_ = $next; $map_func->($next) };
53 undef $source_stream; return;