The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Finance::GeniusTrader::Registry - Generic registry functions

DESCRIPTION

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

Finance::GeniusTrader::Registry::get_registered_object($repository, $name)

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

Finance::GeniusTrader::Registry::register_object($repository, $name, $object)

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

Finance::GeniusTrader::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.

Example:

  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 = Finance::GeniusTrader::Indicators::get_or_register_object($name, $self);

      return $self;
  }
Finance::GeniusTrader::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.

Finance::GeniusTrader::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)
 get_nb_values()