Alexei Znamensky
and 1 contributors

NAME

Queue::Base - Simple OO style queue implementation.

VERSION

version 2.0_2

SYNOPSIS

    use Queue::Base;

    # construction
    my $queue = new Queue::Base;
    # or
    my $queue = new Queue::Base(\@elements);
 
    # add a new element to the queue
    $queue->add($element);
 
    # remove the next 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.

remove [NUMBER_OF_ELEMENTS]

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

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

remove_all

Returns an array with all the elements in the queue, and clears the queue.

size

Returns the size of the queue.

empty

Returns whether the queue is empty, which means its size is 0.

clear

Removes all elements from the queue.

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 basically scalars.

AUTHOR

Farkas Arpad, maintained by Alexei "RUSSOZ" Znamensky <russoz@cpan.org>