X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FHTML%2FZoom%2FStreamUtils.pm;h=16a029fa65800a14e054782a4e085c83931ab6bb;hb=6d0f20a655ed2cb8581f7ab27433febba6c44cbd;hp=cdfa430d1be98ce8b58fa42254655dca85218cbc;hpb=bf5a23d02e1ab37136d70e736014a81ecfcfe15c;p=catagits%2FHTML-Zoom.git diff --git a/lib/HTML/Zoom/StreamUtils.pm b/lib/HTML/Zoom/StreamUtils.pm index cdfa430..16a029f 100644 --- a/lib/HTML/Zoom/StreamUtils.pm +++ b/lib/HTML/Zoom/StreamUtils.pm @@ -44,8 +44,9 @@ sub stream_from_proto { return $proto->(); } elsif ($ref eq 'SCALAR') { return $self->_zconfig->parser->html_to_stream($$proto); - } elsif (blessed($proto) && $proto->can('as_stream')) { - return $proto->as_stream; + } elsif (Scalar::Util::blessed($proto) && $proto->can('as_stream')) { + my $stream = $proto->as_stream; + return $self->stream_from_code(sub { $stream->next }); } die "Don't know how to turn $proto (ref $ref) into a stream"; } @@ -67,4 +68,21 @@ sub stream_to_array { return @array; } +sub flatten_stream_of_streams { + my ($self, $source_stream) = @_; + my $cur_stream; + HTML::Zoom::CodeStream->new({ + code => sub { + return unless $source_stream; + my $next; + until (($next) = ($cur_stream ? $cur_stream->next : ())) { + unless (($cur_stream) = $source_stream->next) { + undef $source_stream; return; + } + } + return $next; + } + }); +} + 1;