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

Array::Stream::Transactional - Transactional array wrapper

SYNOPSIS

  use Array::Stream::Transactional;
  my $stream = Array::Stream::Transactional->new([1..100]);
  $stream->commit;
  while($stream->has_more) {
    if($stream->next == 50 && !$reverted) {
      $stream->rollback;
      $reverted = 1;
    }
    print $stream->current, "\n";
  }

DESCRIPTION

Array::Stream::Transactional is a Perl extension for wrapping an array and having it pose as a stream. The streams current position can be commited and rollbacked at any time.

CONSTRUCTOR

new ( ARRAYREF )

Creates an Array::Stream::Transactional. Wrapps the passed array reference. Position is set to 0, current is set the first element in ARRAYREF, previous is set to undef and the transaction stack is empty.

METHODS

next ( )

Get the next element from the stream and increment the position in the current transaction.

rewind ( )

Get the previous element from the stream and decrement the position in the current transaction.

current ( )

Get the current element read from the stream in the current transaction.

previous ( )

Get the previous element read from the stream in the current transaction.

following ( )

Get the following element read from the strean in the current transaction. This method is like "next" except it doesn't increment the position.

pos ( )

Return the current position in the stream.

length ( )

Return the length of the wrapped array

has_more ( )

Return true if there are more elements in the stream, false otherwise.

commit ( )

Push the current position, element and previous element on the transaction stack.

rollback ( )

Rollback the current transaction by reseting the stream position, current and previous element. The transaction will be removed from the transaction stack so that next rollback will rollback to the commit previous to the commit that created the rollbacked transaction.

regret ( )

Removes the top item of the commit stack. Returns the position, current element and previous element of the stream at the time the commit was made.

reset ( )

Resets the reading of the stream to position 0, current to first element and previous to undefined.

AUTHOR

Claes Jacobsson, claesjac@cpan.org

COPYRIGHT AND LICENSE

Copyright 2004 by Claes Jacobsson

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

1 POD Error

The following errors were encountered while parsing the POD:

Around line 97:

=pod directives shouldn't be over one line long! Ignoring all 2 lines of content