factor out application of a match+filter to a stream into a Transform object
[catagits/HTML-Zoom.git] / lib / HTML / Zoom / FilterStream.pm
index 641144f..4bee41c 100644 (file)
@@ -6,36 +6,25 @@ use base qw(HTML::Zoom::StreamBase);
 
 sub new {
   my ($class, $args) = @_;
+  if ($args->{filters}) {
+    die "Single filter please (XXX FIXME)"
+      unless @{$args->{filters}} == 1;
+    $args->{filter} = $args->{filters}[0];
+  }
   bless(
     {
       _stream => $args->{stream},
       _match => $args->{match},
       _filter => $args->{filter},
+      _zconfig => $args->{zconfig},
     },
     $class
   );
 }
 
-sub peek {
-  my ($self) = @_;
-  if (exists $self->{_peeked}) {
-    return ($self->{_peeked});
-  }
-  if (my ($peeked) = $self->next) {
-    return ($self->{_peeked} = $peeked);
-  }
-  return;
-}
-
-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