The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Data::Range::Compare::Stream::Iterator::Base - Abstract class

SYNOPSIS

  package MyIterator;
  use strict;
  use warnings;
  use IO::File;
  use IO::Select;
  use base qw(Data::Range::Compare::Stream::Iterator::Base);
  use Data::Range::Compare::Stream;
  
  sub new {
    my ($class,%args)=@_;
    my $has_next;
    my $self=$class->SUPER::new(%args);
  
    if(defined($args{filename})) {
      my $fh=IO::File->new($args{filename});
      if($fh) {
         $self->{fh}=$fh;
         my $line=$fh->getline;
         $self->{next_line}=$line;
         $has_next=defined($line);
      } else {
        $self->{msg}="Error could not open $args{filename} error was: $!";
      }
  
    }
  
    $self->{has_next}=$has_next;
    return $self;
  }
  
  sub get_next {
    my ($self)=@_;
    return undef unless $self->has_next;
  
    my $line=$self->{next_line};
    $self->{next_line}=$self->{fh}->getline;
    $self->{has_next}=$self->{next_line} ?  1 : 0;
  
    chomp $line;
    return new Data::Range::Compare::Stream(split /\s+/,$line);
  }
  
  1;

DESCRIPTION

This module acts as the base class for all Data::Range::Compare::Stream::Iterator classes.

Methods to implement

  • my $iterator=new MyIterator(arguments=>here);

    The default object constructor takes a hash of arguments, and returns a blessed anonymous hash. If you want to do anything other than that you will need to overload this function!

  • while($iterator->has_next) { do something }

    The internals return $self->{has_next}. If you want to do anything other than that you will need to overload this function!

  • my $range=$iterator->get_next;

    Objects returned from this function should implement Data::Range::Compare::Stream

  • my $string=$iterator->to_string;

    Returns the package name of $iterator

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.