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

use Moose;
use Method::Signatures::Simple;

has 'sth' => (is => 'ro', required => 1, clearer => '_clear_sth');

has '_column_order' => (is => 'ro', required => 1, init_arg => 'column_order');

method next {
  my $sth = $self->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;
}

__PACKAGE__->meta->make_immutable;

1;
