Blast-Radius Aware AI Code Review for Business-Critical Systems
LiveReview LiveReview Explore LiveReview

UR::Singleton - Abstract class for implementing singleton objects

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.

Name

       UR::Singleton - Abstract class for implementing singleton objects

See Also

       UR::Object

perl v5.38.2                                       2024-06-15                                 UR::Singleton(3pm)

Synopsis

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

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

See Also