Michael Shipper
and 1 contributors

NAME

Data::Range::Compare::Stream::Iterator::Stack - Walk many iterators with one interface

SYNOPSIS

  use Data::Range::Compare::Stream;
  use Data::Range::Compare::Stream::Iterator::File;
  use Data::Range::Compare::Stream::Iterator::Stack;

  my $stack=new Data::Range::Compare::Stream::Iterator::Stack;

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

  $stack->stack_push($iterator_a);

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

  $stack->stack_push($iterator_b);

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

DESCRIPTION

Allows seamless iteration through multiple objects that implement: Data::Range::Compare::Stream::Iterator::Base. Data::Range::Compare::Stream::Iterator::Stack extends Data::Range::Compare::Stream::Iterator::Base and can be passed to another instance of itself.

OO Methods

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

    Instance Constructor, all arguments are optional

    Optional arguments:

       stack=>[]
         # an array ref of objects that implement Data::Range::Compare::Stream::Iterator::Base
    
       parse_line=>undef|code_ref
         # Default: undef, Sets the code ref to be used when parsing a line
         # if not set the default internals will be used
    
       result_to_line=>undef|code_ref
         # Default: undef, Sets the code ref used to convert a result to a line that can be parsed
         # if not set the default internals will be used
  • while($iterator->has_next) { ... }

    Returns true when one or more objects on the stack has_next.

  • my $result=$iterator->get_next;

    Returns the next $result from the given source file.

  • $stack->stack_push($iterator);

    This interface can be used to add an iterator onto the stack. Objects being added to the stack need to implement or extend Data::Range::Compare::Iterator::Base.

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.