UR::Singleton(3pm)

UR::Singleton3pm

Abstract class for implementing singleton objects

Usage

  package MyApp::SomeClass;
  use UR;
  class MyApp::SomeClass {
      is => 'UR::Singleton',
      has => [
          foo => { is => 'Number' },
      ]
  };
  $obj = MyApp::SomeClass->get();
  $obj->foo(1);

Overview

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.

Releases

6 releases since Debian 8 (Jessie); the text changed 4 times.

  1. 8
  2. 9
  3. 10–11
  4. 12
  5. 13

From libur-perl 0.470+ds-3 in Debian 13 (Trixie). Parsed by carta from the page's man source.