NAME

Data::TableReader::Iterator - Base class for iterators (blessed coderefs)

VERSION

version 0.021

SYNOPSIS

my $iter= $record_reader->iterator;
while (my $rec= $iter->()) {
  ...
  my $position= $iter->tell;
  print "Marking position $position"; # position stringifies to human-readable
  ...
  $iter->seek($position);
}
if ($iter->next_dataset) {
  # iterate some more
  while ($rec= $iter->()) {
    ...
    printf "Have processed %3d %% of the file", $iter->progress*100;
  }
}

DESCRIPTION

This is the abstract base class for iterators used in Data::TableReader, which are blessed coderefs that return records on each call.

The coderef should support a single argument of a "slice" to extract from the record, in case not all of the record is needed.

ATTRIBUTES

position

Return a human-readable string describing the current location within the source file. This will be something like "$filename row $row" or "$filename $worksheet:$cell_id".

row

A numeric 1-based row number for the current position of the current dataset. This is not affected by which row the header was found on.

dataset_idx

A numeric 0-based dataset number. For Decoders which only support a single dataset, this is always 0.

progress

An estimate of how much of the data has already been returned. If the stream is not seekable this may return undef.

METHODS

new

$iter= Data::TableReader::Iterator->new( \&coderef, \%fields );

The iterator is a blessed coderef. The first argument is the coderef to be blessed, and the second argument is the magic hashref of fields to be made available as $iter->_fields.

tell

If seeking is supported, this will return some value that can be passed to seek to come back to this point in the stream. This value will always be true. If seeking is not supported this will return undef.

seek

$iter->seek($pos);

Seek to a point previously reported by "tell". If seeking is not supported this will die. If $pos is any false value it means to seek to the start of the stream.

next_dataset

If a file format supports more than one tabular group of data, this method allows you to jump to the next. Returns true if it moved to a new dataset, and false at the end of iteration.

AUTHOR

Michael Conrad <mike@nrdvana.net>

COPYRIGHT AND LICENSE

This software is copyright (c) 2024 by Michael Conrad.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.