1 package HTML::Zoom::StreamUtils;
4 use warnings FATAL => 'all';
5 use base qw(HTML::Zoom::SubObject);
7 use HTML::Zoom::CodeStream;
8 use HTML::Zoom::FilterStream;
10 sub stream_from_code {
11 my ($self, $code) = @_;
12 HTML::Zoom::CodeStream->new({
14 zconfig => $self->_zconfig,
18 sub stream_from_array {
21 $self->stream_from_code(sub {
28 shift->stream_from_array(@_)->flatten;
31 sub stream_from_proto {
32 my ($self, $proto) = @_;
35 return $self->stream_from_array({
37 raw => $self->_zconfig->parser->html_escape($proto)
39 } elsif ($ref eq 'ARRAY') {
40 return $self->stream_from_array(@$proto);
41 } elsif ($ref eq 'CODE') {
43 } elsif ($ref eq 'SCALAR') {
44 return $self->_zconfig->parser->html_to_stream($$proto);
46 die "Don't know how to turn $proto (ref $ref) into a stream";
49 sub wrap_with_filter {
50 my ($self, $stream, $match, $filter) = @_;
51 HTML::Zoom::FilterStream->new({
55 zconfig => $self->_zconfig,