Config module

This module contains the API to the configuration file. It is responsible for reading the file, locating the parameter group for the current source-tree and presenting an abstract interface to the 'variables'.

new (@parms)

Method new creates a new configuration object.

  1. @parms

    the paramaters array (just passed "as is" to _initialize)

emergency ()

Method emergency returns whatever can be retrieved from the configuration file.

It is intended to allow editing user-friendly error message when a catastrophic event occurred during initialisation.

readconfig ()

Method readconfig returns the content of the configuration file as a list.

Note:

readfile ($file)

Function readfile returns the content of the designated file as a list of "words" ("words" are delimited by spaces).

  1. $file

    a string containing the file name, relative to the LXR root directory or absolute

Note:

_initialize ($host, $script_path, $firstseg, $confpath)

Internal method _initialize does the real object initialization.

  1. $host

    a string containing the host name

  2. $script_path

    a string containing the hierarchical web path to the script (truncated at the invoking script)

  3. $firstseg

    a string containing the first segment of the path into the source-trees, possibly the tree name (may be empty if single-tree context)

    CAUTION! It may also be a first-level directory!

  4. $confpath

    a string containing the path of an alternate configuration file (either relative to the LXR root directory or absolute)

If $confpath is not defined, use the internal $confname.

If $host, $script_path is not defined, try to extract something meaningful from the invoking URL.

CAVEAT!

treeurl ($group, $global)

Method treeurl returns a URL for the tree described by parameter group $group. This URL tries to match the present hostname used to invoke LXR.

  1. $group

    a reference to the tree-specific parameter group

  2. $global

    a reference to the global parameter group to provide default values for parameters not present in the tree-specific group

Algorithm

Parameters 'host_names' and 'virtroot' are retrieved to build a URL to launch LXR on that tree.

It compares the hosts (in a list composed of 'host_names' from the tree-specific or global parameter group) + 'virtroot' to 'script_path' (with the script name removed).

If a match is found, undef is returned, meaning that an HTML-relative URL may be used.

If no match, a second attempt is made with the hosts only to test for a target tree different from the current one.

If a host matches, an HTML-absolute URL is returned.

Otherwise, the first hostname in the list is selected for the returned HTML-absolute URL.

Potential problems:

allvariables ()

Method allvariables returns the list of all defined variables.

variable ($var, $val)

Method variable returns the current value of the designated variable.

  1. $var

    a string containing the name of the variable

  2. $val

    optional value; if present, replaces the current value

If no current value has already been set, the default value is returned.

vardefault ($var)

Method vardefault returns the default value of the designated variable.

  1. $var

    a string containing the name of the variable

If no default value has been defined, the first value in 'range' is returned.

vardescription ($var, $val)

Method vardescription returns the description of the designated variable.

  1. $var

    a string containing the name of the variable

  2. $val

    optional value; if present, replaces the description

Note:

varrange ($var)

Method varrange returns the set of values of the designated variable.

  1. $var

    a string containing the name of the variable

varexpand ($exp)

Method varexpand returns its argument with all occurrences of $xxx replaced by the current value of variable 'xxx'.

  1. $exp

    a string to expand

value ($var)

Method value returns the value of a configuration parameter with occurrences of $xxx replaced by the current value of variable 'xxx'.

  1. $var

    a string containing the configuration parameter name

AUTOLOAD (@parms)

Magical Perl method AUTOLOAD to instantiate unknown barewords.

  1. @parms

    optional arguments array passed to instantiated function

When a bareword is encountered in a construct like $config->bareword, this method is called. It tries to get the expanded value of configuration parameter 'bareword' with method value. If the value itself is a function, that function is called with the parameters provided to bareword.

The final value is returned to the caller.

mappath ($path, @args)

Method mappath returns its argument path transformed by the 'maps' rules.

  1. $path

    a string containing the path to transform

  2. @args

    an array containing strings of the form var=value forcing a context in which the 'maps' rules are applied

Note:

unmappath ($path, @args)

Method unmappath attempts to undo the effects of mappath. It returns an abstract path suitable for a new processing by mappath with a new set of variables values.

  1. $path

    a string containing the file path to "invert".

  2. @args

    an array containing strings of the form var=value defining the context in which the 'maps' rules were applied.

Algorithm

'maps' rules are given as pattern => replacement where replacement may itself contain $var markers asking for substitution by the designated variable value.

Tentatively inverting mappath processing means applying "inverse" 'maps' rules in reverse order.

Note:

The generated "inverted" rule has the following form:

transformed replacement => transformed pattern

The generated rule is then applied to $path.

The effect is cumulated on all "inverse" rules and the final $path is returned as the value of this sub.

_ensuredirexists ($chkdir)

Internal function _ensuredirexists checks that directory $dir exists and creates it if not in a way similar to "mkdir -p".

  1. $chkdir

    a string containing the directory path.

Algorithm

"Manual" algorithm replaced by a call to File::Path::make_path().

Every component of the path is checked from left to right. Both OS-absolute or relative paths are accepted, though the latter form would probably not make sense in LXR context.