Solstice::Service - Superclass for all services. A service provides request-lifecycle-long caching of information.


Solstice documentation Contained in the Solstice distribution.

Index


Code Index:

NAME

Top

Solstice::Service - Superclass for all services. A service provides request-lifecycle-long caching of information.

SYNOPSIS

Top

  use base qw(Solstice::Service);

  sub new {
    my $obj = shift;
    return $obj->SUPER::new(@_);
  }

DESCRIPTION

Top

Creates an API for subclasses to use to manage and make available global data.

Export

No symbols exported.

Methods

new()

Creates a new Solstice::Service object.

setNamespace($str)

Sets the namespace on a per-object basis.

getNamespace()

Return the current namespace

getValue($str)

Returns the entity tied to the given key, in this namespace. The namespace is defined as the name of the derived subclass with the pid of the apache thread.

setValue($str, $str)

Will store the value entity, tied to the key in our namespace. The namespace is defined as the name of the derived subclass with the pid of the apache thread.

get()

Alias for getValue().

set()

Alias for setValue().

Private Methods

_getDataStore()

Return the global datastore hashref.

_getClassName()

Returns the result of ref($self). This can be overridden in a subclass to eliminate the ref(), by just returning a string containing the package name. Be careful when overriding this method in superclasses!

_getKeyname()

Returns a generated string for use as a hash key in the object's datastore.

AUTHOR

Top

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

VERSION

Top

$Revision: 3364 $

COPYRIGHT

Top


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

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

use 5.006_000;
use strict;
use warnings;

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

our $data_store = {};

sub new {
    my $obj = shift;
    my $self = $obj->SUPER::new(@_); 
    return $self;
}

sub setNamespace {
    my $self = shift;
    $self->{'_namespace'} = shift;
}

sub getNamespace {
    my $self = shift;
    return $self->{'_namespace'};
}

sub getValue {
    my $self = shift;
    my $key = shift;
    return $self->_getDataStore()->{$self->_getKeyname($key)};
}

sub setValue {
    my $self = shift;
    my $key = shift;
    my $value = shift;
    $self->_getDataStore()->{$self->_getKeyname($key)} = $value;
}

sub get {
    my $self = shift;
    return $self->getValue(@_);
}

sub set {
    my $self = shift;
    return $self->setValue(@_);
}

sub _getDataStore {
    return $data_store;
}

sub _getClassName {
    my $self = shift;
    return ref($self);
}

sub _getKeyname {
    my $self = shift;
    my $key  = shift || 'generic';
    return $$.':'.$self->_getClassName().':'.$key;
}

1;
__END__