logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Config::General::Interpolated - Parse variables within Config files

Authors

        Thomas Linden <tlinden |AT| cpan.org>
        Autrijus Tang <autrijus@autrijus.org>
        Wei-Hon Chen <plasmaball@pchome.com.tw>

Description

       This is an internal module which makes it possible to interpolate Perl style variables in your config
       file (i.e. $variable or "${variable}").

       Normally you don't call it directly.

Name

       Config::General::Interpolated - Parse variables within Config files

Naming Conventions

       Variable names must:

       •   start with a US-ASCII letter(a-z or A-Z) or a digit (0-9).

       •   contain only US-ASCII letter(a-z or A-Z), digits (0-9), the dash (-)
                   colon (:), dot (.), underscore (_) and plus (+) characters.

       For added clarity variable names can be surrounded by curly braces.

See Also

       Config::General

Synopsis

        use Config::General;
        $conf = Config::General->new(
           -ConfigFile      => 'configfile',
           -InterPolateVars => 1
        );

Variables

       Variables can be defined everywhere in the config and can be used afterwards as the value of an option.
       Variables cannot be used as keys or as part of keys.

       If you define a variable inside a block or a named block then it is only visible within this block or
       within blocks which are defined inside this block. Well - let's take a look to an example:

        # sample config which uses variables
        basedir   = /opt/ora
        user      = t_space
        sys       = unix
        <table intern>
            instance  = INTERN
            owner     = $user                 # "t_space"
            logdir    = $basedir/log          # "/opt/ora/log"
            sys       = macos
            <procs>
                misc1   = ${sys}_${instance}  # macos_INTERN
                misc2   = $user               # "t_space"
            </procs>
        </table>

       This will result in the following structure:

        {
            'basedir' => '/opt/ora',
            'user'    => 't_space'
            'sys'     => 'unix',
            'table'   => {
                 'intern' => {
                       'sys'      => 'macos',
                       'logdir'   => '/opt/ora/log',
                       'instance' => 'INTERN',
                       'owner' => 't_space',
                       'procs' => {
                            'misc1' => 'macos_INTERN',
                            'misc2' => 't_space'
                   }
                }
            }

       As you can see, the variable sys has been defined twice. Inside the <procs> block a variable ${sys} has
       been used, which then were interpolated into the value of sys defined inside the <table> block, not the
       sys variable one level above. If sys were not defined inside the <table> block then the "global" variable
       sys would have been used instead with the value of "unix".

       Variables inside double quotes will be interpolated, but variables inside single quotes will not
       interpolated. This is the same behavior as you know of Perl itself.

       In addition you can surround variable names with curly braces to avoid misinterpretation by the parser.

Version

       2.16

perl v5.40.0                                       2025-01-31                         General::Interpolated(3pm)

See Also