Elive::DAO::Singleton - Singleton mixin class


Elive documentation Contained in the Elive distribution.

Index


Code Index:

NAME

Top

Elive::DAO::Singleton - Singleton mixin class

DESCRIPTION

Top

This mixin class provides a get method for fetching the singleton object. It also overrides the Elive::DAO list method, to return just the singleton object in a one element array.

Typical usage is:

    package Elive::Entity::SomeEntity;
    use warnings; use strict;

    use Mouse;

    extends 'Elive::DAO::Singleton', 'Elive::Entity';

METHODS

Top

get

    my $server = Elive::Entity::ServerDetails->get(connection => $connection);

Gets the singleton object.

list

    my $server_list = Elive::Entity::SomeEntity->list();
    my $server_obj = $server_list->[0];

Returns the singleton object in a one element array .


Elive documentation Contained in the Elive distribution.
package Elive::DAO::Singleton;
use warnings; use strict;

use Carp;

sub get {
    my ($class, %opt) = @_;

    my $object_list = $class->list(%opt);

    die "unable to get $class\n"
	unless (Elive::Util::_reftype($object_list) eq 'ARRAY'
		&& $object_list->[0]);

    return $object_list->[0];
}

sub list {
    my ($class, %opt) = @_;

    croak "filter not applicable to singleton class: $class"
	if ($opt{filter});

    return $class->_fetch({}, %opt);
}

1;