Solstice::PositionService - Queueing and positioning info for collections of objects.


Solstice documentation Contained in the Solstice distribution.

Index


Code Index:

NAME

Top

Solstice::PositionService - Queueing and positioning info for collections of objects.

SYNOPSIS

Top

    use Solstice::PositionService;
    my $position_service = new Solstice::PositionService;

    # get zero-indexed position in queue
    my $position = $position_service->enqueue();

    #am I the last one?
    if ( $position == ($position_service->getQueueSize() - 1)){
        ...
    }

DESCRIPTION

Top

Superclass

Solstice::Service

Export

No symbols exported.

Methods

initialize($id, $value)

Sets the position value for the passed $id to $value, or 0 if $value is undefined. Returns undef.

enqueue([$id])

Increment the position value for the passed $id. If the value is not defined, it is initialized as 0. Returns the current position value.

reset([$id])

Sets the position value for the passed $id to 0. Returns undef.

getQueueSize([$id])

Returns the current position value for the passed $id, or 0 if not defined.

Private Methods

_getClassName()

Return the class name. Overridden to avoid a ref() in the superclass.

Modules Used

Solstice::Service.

AUTHOR

Top

Catalyst Group, <catalyst@u.washington.edu>

VERSION

Top

$Revision: 3364 $

COPYRIGHT

Top


Solstice documentation Contained in the Solstice distribution.
package Solstice::PositionService;

# $Id: PositionService.pm 3364 2006-05-05 07:18:21Z mcrawfor $

use 5.006_000;
use strict;
use warnings;

use base qw(Solstice::Service);

our ($VERSION) = ('$Revision: 3364 $' =~ /^\$Revision:\s*([\d.]*)/);

sub initialize {
    my $self  = shift;
    my $id    = shift || caller;
    my $value = shift || 0;

    $self->set($id, $value);

    return;
}

sub enqueue {
    my $self = shift;
    my $id   = shift || caller;
    
    my $position = $self->get($id) || 0;
    $self->set($id, $position + 1);

    return $position;
}

sub reset {
    my $self = shift;
    my $id   = shift || caller;

    $self->set($id, 0);

    return;
}

sub getQueueSize {
    my $self = shift;
    my $id   = shift || caller;

    return $self->get($id) || 0;
}

sub _getClassName {
    return 'Solstice::PositionService';
}



1;


__END__