NAME

Data::Range::Compare::Stream::Iterator::Consolidate::FileAsc - iterator for Pre Consolidated/Sorted files

SYNOPSIS

use Data::Range::Compare::Stream;
use Data::Range::Compare::Stream::Iterator::Consolidate::FileAsc;

my $iterator=Data::Range::Compare::Stream::Iterator::Consolidate::FileAsc->new(
  filename=>'some_file.csv',
);

while($iterator->has_next) {
  my $result=$iterator->get_next;
  print $result,"\n";
}

DESCRIPTION

This module implements a very simple file iterator interface. This iterator interface assumes that the data is pre-sorted and pre-consolidated. The result objects returned are a container class: Result containers are constructed from $iterator->RESULT_FROM. The class objects contained within the result object are constructed from $iterator->NEW_FROM. Parsing is handled by $iterator->parse_line.

OO Methods

  • my $iterator=new Data::Range::Compare::Stream::Iterator::Consolidate::FileAsc;

    Instance Constructor Arguments:

    filename=>'source_file.csv'  
      # the file is assumed to be an absolute or relative path to the file location.

    Optional Arguments:

    factory_instance =>$obj
      
      # defines the object that implements the $obj->factory($start,$end,$data).
      # new ranges are constructed from the factory interfcae.  If a factory interface
      # is not created an instance of Data::Range::Compare::Stream is assumed.
  • if($iterator->in_error) { ... }

    Returns true if there was a problem opening the file.

  • my $class=$iterator->NEW_FROM;

    $class will contain the name of the class new ranges are to be constructed from: This will need to be overloaded if the class is not "Data::Range::Compare::Stream".

  • my $class=$iterator->RESULT_FROM;

    $class will contain the name of the class new result objects will be constructed from.

  • my $ref=$self->parss_line($line);

    This is the actual parser interface: $ref is an anonymous array representing the constructor arguments to be passed to the class referee to via $iterator->NEW_FROM.

    The parser logic is very simple and can be described as follows.

    sub parse_line {
      my ($self,$line)=@_;
      chomp $line;
      return [split /\s+/,$line];
    }

    If the data you are dealing with is not parse-able using the above code then you will need to extend this package and overload the $iterator->parse_line interface.

  • while($iterator->has_next) { ... }

    Returns true when there are more rows to fetch.

  • my $range=$iterator->get_next;

    Returns the next Consolidated Result Object from the given source file.

SEE ALSO

Data::Range::Compare::Stream::Cookbook

AUTHOR

Michael Shipper

Source-Forge Project

As of version 0.001 the Project has been moved to Source-Forge.net

Data Range Compare https://sourceforge.net/projects/data-range-comp/

COPYRIGHT

Copyright 2011 Michael Shipper. All rights reserved.

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