1 package HTML::Zoom::StreamUtils;
4 use warnings FATAL => 'all';
5 use base qw(HTML::Zoom::SubObject);
9 use HTML::Zoom::CodeStream;
10 use HTML::Zoom::FilterStream;
12 sub stream_from_code {
13 my ($self, $code) = @_;
14 HTML::Zoom::CodeStream->new({
16 zconfig => $self->_zconfig,
20 sub stream_from_array {
23 $self->stream_from_code(sub {
30 shift->stream_from_array(@_)->flatten;
33 sub stream_from_proto {
34 my ($self, $proto) = @_;
37 return $self->stream_from_array({
39 raw => $self->_zconfig->parser->html_escape($proto)
41 } elsif ($ref eq 'ARRAY') {
42 return $self->stream_from_array(@$proto);
43 } elsif ($ref eq 'CODE') {
45 } elsif ($ref eq 'SCALAR') {
46 return $self->_zconfig->parser->html_to_stream($$proto);
47 } elsif (blessed($proto) && $proto->can('as_stream')) {
48 return $proto->as_stream;
50 die "Don't know how to turn $proto (ref $ref) into a stream";
53 sub wrap_with_filter {
54 my ($self, $stream, $match, $filter) = @_;
55 HTML::Zoom::FilterStream->new({
59 zconfig => $self->_zconfig,
66 while (my ($evt) = $stream->next) { push @array, $evt }