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

NAME

CPU::Z80::Assembler::Stream - Object to encapsulate an iterator to be able to unget

SYNOPSIS

  use CPU::Z80::Assembler::Stream;
  my $stream = CPU::Z80::Assembler::Stream->new(@input)
  my $head = $stream->head;
  my $next = $stream->get;
  $stream->unget(@items);

DESCRIPTION

This module encapsulates an iterator function. An iterator function returns the next element in the stream on each call, and returns undef on end of input.

The iterator can return a code reference - this new iterator is inserted at the head of the queue.

The object allows the user to peek the head element of the stream without consuming it, or to get it and remove from the stream.

A list of objects can also be pushed back to the stream, to be retrieved in the subsequent get() calls.

The input list to the constructor and to unget() contains either objects to be retireved on each get() call, or code references to be called to extract the next item from the stream.

EXPORTS

Nothing.

FUNCTIONS

new

Creates a new object ready to retrieve elements from the given input list.

Retrieves the element at the head of the stream, but keeps it in the stream to be retrieved by the next get().

Returns undef if the stream is empty.

get

Retrieves the element at the head of the stream and removes it from the stream.

Returns undef if the stream is empty

unget

Pushes back a list of values and/or iterators to the stream, that will be retrieved on the subsequent calls to get().

Can be called from within an iterator, to insert values that will be returned after the current call, e.g. calling from the iterator:

  $stream->unget(2..3); return 1;

will result in the stream 1,2,3 being returned from the stream.

iterator

Return an iterator function that returns the next stream element on each call.

BUGS and FEEDBACK

See CPU::Z80::Assembler.

SEE ALSO

CPU::Z80::Assembler

AUTHORS, COPYRIGHT and LICENCE

See CPU::Z80::Assembler.