--- /dev/null
+package HTML::Zoom::ArrayStream;
+
+use strict;
+use warnings FATAL => 'all';
+use base qw(HTML::Zoom::StreamBase);
+
+sub new {
+ my ($class, $args) = @_;
+ bless(
+ { _zconfig => $args->{zconfig}, _array => [ @{$args->{array}} ] },
+ $class
+ );
+}
+
+sub _next {
+ my $ary = $_[0]->{_array};
+ return unless @$ary;
+ return shift @$ary;
+}
+
+1;
use warnings FATAL => 'all';
use base qw(HTML::Zoom::StreamBase);
-sub from_array {
- my ($class, @array) = @_;
- $class->new({ code => sub {
- return unless @array;
- return shift @array;
- }});
-}
-
sub new {
my ($class, $args) = @_;
bless({ _code => $args->{code}, _zconfig => $args->{zconfig} }, $class);
}
-sub next {
- my ($self) = @_;
-
- # peeked entry so return that
-
- if (exists $self->{_peeked}) {
- return (delete $self->{_peeked});
- }
-
- $self->{_code}->();
+sub _next {
+ $_[0]->{_code}->();
}
1;
);
}
-sub next {
+sub _next {
my ($self) = @_;
- # peeked entry so return that
-
- if (exists $self->{_peeked}) {
- return (delete $self->{_peeked});
- }
-
# if our main stream is already gone then we can short-circuit
# straight out - there's no way for an alternate stream to be there
bless({ _source => $args->{source}, _zconfig => $args->{zconfig} }, $class);
}
-sub next {
+sub _next {
+
return unless (my $self = shift)->{_source};
my ($next, $s);
until (($next) = ($s = $self->{_cur}) ? $s->next : ()) {
}, $class);
}
-sub next {
+sub _next {
return unless (my $self = shift)->{_source};
# If we were aiming for a "true" perl-like map then we should
# elegantly handle the case where the map function returns 0 events
if (exists $self->{_peeked}) {
return ($self->{_peeked});
}
- if (my ($peeked) = $self->next) {
+ if (my ($peeked) = $self->_next) {
return ($self->{_peeked} = $peeked);
}
return;
}
+sub next {
+ my ($self) = @_;
+
+ # peeked entry so return that
+
+ if (exists $self->{_peeked}) {
+ return (delete $self->{_peeked});
+ }
+
+ $self->_next;
+}
+
+
sub flatten {
my $self = shift;
require HTML::Zoom::FlattenedStream;
use HTML::Zoom::CodeStream;
use HTML::Zoom::FilterStream;
+use HTML::Zoom::ArrayStream;
sub stream_from_code {
my ($self, $code) = @_;
sub stream_from_array {
my $self = shift;
my @array = @_;
- $self->stream_from_code(sub {
- return unless @array;
- return shift @array;
- });
+ HTML::Zoom::ArrayStream->new({
+ array => \@array,
+ zconfig => $self->_zconfig,
+ })
}
sub stream_concat {
$_->repeat_content(
[
sub {
- HTML::Zoom::CodeStream->from_array(
+ HTML::Zoom::ArrayStream->new({ array => [
(filter
filter($_ => '.name' => $r_content->('mst'))
=> '.career' => $r_content->('Chainsaw Wielder')),
- HTML::Zoom::CodeStream->from_array(@between)
- )->flatten
+ HTML::Zoom::ArrayStream->new({ array => \@between })
+ ] })->flatten
},
sub {
filter