NAME

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

VERSION

version 0.011

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".

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.

AUTHOR

Michael Conrad <mike@nrdvana.net>

COPYRIGHT AND LICENSE

This software is copyright (c) 2019 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.