Unfortunately fixing ->add_before("foo") is not that easy.
sub add_before {
my ($self, $events) = @_;
sub { return $self->$self->_stream_from_proto($events), $_[0]) };
}
doesn't work, as it dies with the following error message
Can't call method "next" on unblessed reference
at HTML-Zoom/lib/HTML/Zoom/FlattenedStream.pm line 17.
The following does work, but is overly complicated; there should be
easier way to do this:
sub add_before {
my ($self, $events) = @_;
my $emit = $self->_stream_from_proto($events);
my @evts = $self->_zconfig->stream_utils->stream_to_array($emit);
sub { return $self->_stream_from_array(@evts, $_[0]) };
}
my $coll_proto = $self->collect({ passthrough => 1 });
sub {
my ($evt) = @_;
- my $emit = $self->_stream_from_array(@$events);
+ my $emit = $self->_stream_from_proto($events);
my $coll = &$coll_proto;
return ref($coll) eq 'HASH' # single event, no collect
? [ $coll, $emit ]