package DBIx::Data::Stream::STH;

use strictures 1;

sub new {
  my $proto = shift;
  bless({ %{$_[0]} }, ref($proto)||$proto);
}

sub _sth { shift->{sth} }

sub _clear_sth { delete shift->{sth} }

sub next {
  my $sth = (my $self = shift)->_sth;
  return unless $sth;
  # {Active} only means that there *may* be more results to fetch
  if ($sth->{Active} and my @next = $self->sth->fetchrow_array) {
    my %next; @next{@{$self->_column_order}} = @next;
    return \%next;
  }
  $sth->finish;
  # prepare_cached might recycle it now we're finished so get rid of it
  $self->_clear_sth;
  return;
}

1;
