GT::Registry - Generic registry functions


This module is used by GT::Indicators, GT::Signals and GT::Systems to keep a list of available objects. Those objects can be reused with different datas.

GT::Registry::get_registered_object($repository, $name)

Returns the object corresponding to $name if available. Otherwise returns undef.

GT::Registry::register_object($repository, $name, $object)

Register the object $object under the name $name. Replaces any previous object registered under the same name.

GT::Registry::get_or_register_object($repository, $name, $object)

If an object corresponding to name $name is already registered then returns this object. Otherwise register $object under the name $name.

This function is intented to be used by constructor of objects. Once the constructor know the name of the object, it uses this function to bless the object reference. It will check if an object with the same name exists. In that case the registered object is used instead of creating a new one. Otherwise the object in creation is blessed, stored in the registry and returned.


  sub new {
      my $type = shift;
      my $class = ref($type) || $type;
      # Get the name of the object
      my $name = get_indicator_name(...);
      my $self = {};
      # Check the registry and register it
      $self = GT::Indicators::get_or_register_object($name, $self);
      return $self;
GT::Registry::manage_object($repository, \@NAMES, $obj, $class, $args, $key)

Manage the creation of a new object. Build their names, stores and/or retrieve the object from the database. Calls initialize for a new object.

GT::Registry::build_object_name($encoded, [ @args ], $key)

Returns the real $name of the object by substitution of #1, #2 (and so on) by the real values of the parameters (given in the second argument). "($key)" is appended at the end. It's used to differentiate similar objects but using a different input method for example (think about indicators like "Average" working on prices or any other value).

Method for "named" objects
 get_name() or get_name($i)