GT::Conf - Manage configuration


This module provides functions to manage personal GeniusTrader configuration. The configuration information are stored in file ~/.gt/options by default.

The configuration file format is similar to a perl hash, in other words, a key followed by data for that key. keys are delimited from their value by whitespace. key values can contain embedded whitespace.

key value strings can be continued across multiple lines by delimiting the newline with a backslash (\) (watch out for trailing whitespace after the \ and before the newline).

comments introduced with a # as the first character on a line. data lines cannot contain a comment since the # character is used in many data strings.

blank lines and lines with only whitespace are ignored.

EXAMPLES of ~/.gt/options Entries

 # this is an example of a comment
 DB::module genericdbi
 DB::bean::dbname beancounter
 Graphic::Candle::UpBorderColor "[0,180,80]"
 Graphic::Candle::DownBorderColor "[180,0,80]"

this example shows how continuing key values across lines can be useful.

 DB::genericdbi::prices_sql SELECT day_open, day_high, day_low, \
   day_close, volume, date FROM stockprices WHERE symbol = '$code' ORDER \
   BY date DESC

comments are permitted on data lines provided they can be distinguished from positional arguments markers (e.g. #1, #2, etc). in order to do this any trailing data line comment marker (#) must be surrounded by whitespace. the code is a bit more forgiving, using this regex (\s+#[\s\D]+.$)

note that the comment must follow the end of the logical data line and terminates at the end of the logical line. logical line means the line after continuation processing has completed.


  Aliases::Global::TFS2[]       SY:TFS #1 #2 | CS:SY:TFS #1 # comment
  graphic::positions::buycolor  "[0,135,0]" # very dark green
  graphic::buysellarrows::buycolor      "[0,135,0,64]" # semitransparent dark green
 note: configuration keys are lower cased automatically regardless of how
       they are defined, but their values are as specified when defined


GT::Conf::load([ $file ])

Load the configuration from the indicated file. If the file is omitted then it looks at ~/.gt/options by default.


Clear all the configuration.


Write all the current configuration in the given file. Note: all prior commentary, if any is lost.


Return the configuration value for the given key. If the key doesn't exist, it returns the optional defaultValue.

If neither the key nor defaultValue exist, it returns undef.

GT::Conf::set($key, $value)

Set the given configuration item to the corresponding value. Replaces any previous value.

GT::Conf::default($key, $value)

Set a default value to the given item. Must be called by GT itself to give reasonable default values to most of configurations items.

GT::Conf::get_first($key, ...)

Return the value of the first item that does have a non-zero value.


Helper function, returns the home directory environment variable HOME on Unix or on windows the environment variables HOMEDRIVE . HOMEPATH

GT::Conf::conf_dump( [ "regex" ] )

Helper function, writes the entire configure key=value pairs on stderr. code example: GT::Conf::conf_dump;

pass a perl regex string to filter the output

my $gt_root_dir = GT::Conf::get_gt_root()

Helper function, returns the gt root directory which is the directory that contains GT and Scripts directories, along with any others that may be there. if that configuration key-value is unset check for the environment variable GT_ROOT otherwise returns an empty string