Anthony Brummett > UR-0.43 > UR::Singleton

Download:
UR-0.43.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.43   Source  

NAME ^

UR::Singleton - Abstract class for implementing singleton objects

SYNOPSIS ^

  package MyApp::SomeClass;
  use UR;
  class MyApp::SomeClass {
      is => 'UR::Singleton',
      has => [
          foo => { is => 'Number' },
      ]
  };

  $obj = MyApp::SomeClass->get();
  $obj->foo(1);

DESCRIPTION ^

This class provides the infrastructure for singleton classes. Singletons are classes of which there can only be one instance, and that instance's ID is the class name.

If a class inherits from UR::Singleton, it overrides the default implementation of get() and is_loaded() in UR::Object with code that fabricates an appropriate object the first time it's needed.

Singletons are most often used as one of the parent classes for data sources within a Namespace. This makes it convienent to refer to them using only their name, as in a class definition.

METHODS ^

_singleton_object
  $obj = Class::Name->_singleton_object;

  $obj = $obj->_singleton_object;

Returns the object instance whether it is called as a class or object method.

_singleton_class_name
  $class_name = Class::Name->_singleton_class_name;

  $class_name = $obj->_singleton_class_name;

Returns the class name whether it is called as a class or object method.

SEE ALSO ^

UR::Object

syntax highlighting: