NAME

Queue::Base - Simple OO style queue implementation.

SYNOPSIS

use Queue::Base;

# construction
my $queue = new Queue::Base;
# or
my $queue = new Queue::Base(\@elements);

# add new element to the queue
$queue->add($element);

# remove an element from the queue
if (! $queue->empty()) {
    my $element = $queue->remove();
}
# or
$element = $queue->remove();
if (defined $element) {
    # do some processing here
}

# add/remove more than just one element
$queue->add($elem1, $elem2 ...)
# and
@elements = $queue->remove(5);

DESCRIPTION

The Queue::Base is a simple implementation for queue structures using an OO interface. Provides basic functionality: nothing less - nothing more.

METHODS

Constructor

new [ELEMENTS]

Creates a new empty queue.

ELEMENTS is an array reference with elements the queue to be initialized with.

Methods

add [LIST_OF_ELEMENTS]

Adds the LIST OF ELEMENTS to the end of the queue.

size

Returns the size of the queue.

remove [NUMBER_OF_ELEMENTS]

In scalar context it return the first element from the queue.

In scalar context it attempts to return the NUMBER_OF_ELEMENTS requested; when NUMBER_OF_ELEMENTS is not given, it defaults to 1.

emtpy

Empties the queue, and returns the size of the queue before the empty operation.

CAVEATS

The module works only with scalar values. If you want to use more complex structures (and there's a big change you want that) please use references, which in perl5 are implemented as scalars.

AUTHOR

Farkas Arpad <arpadf@spidernet.co.ro>