Name

AutoVariable — specify config directives to make available through the Variable space

SYNOPSIS

directive...

DESCRIPTION

Specify list of configuration directives whose values are to be made available through the variable space. This allows you to conveniently write say, __DirectiveName__, and retrieve the corresponding configuration directive's value.

To support scalars, arrays and hashes of values (all three basic Perl types), the syntax had to be extended a little. With array or hash configuration directives, you need to append the index number or hash key respectively. See the section called “EXAMPLES” for clarification.

Note that the behavior of AutoVariable is not dynamic — you need to re-invoke AutoVariable every time you want to update the value in __DirectiveName__.

DIRECTIVE TYPE AND DEFAULT VALUE

Global directive,
Catalog directive

EXAMPLES

Example: Enabling configuration directives through Variable space

Put the following in catalog.cfg:

VendURL     http://myhost.mydomain.local/cgi-bin/ic/catalog
SecureURL   https://myhost.mydomain.local/cgi-bin/ic/catalog
MailOrderTo root@mydomain.local
SafeUntrap  sort
SysLog      command  /usr/bin/logger

AutoVariable VendURL SecureURL MailOrderTo SafeUnutrap SysLog

Example: Displaying a scalar value

Put the following on a page:

Orders are e-mailed to: root@localhost

Example: Displaying an array value

Put the following on a page:

First SafeUntrap value is: 

Example: Display a hash value

Put the following on a page:

Syslog command is: 

NOTES

The directive does not support hash keys that contain non-word characters or whitespace. In addition, only the first-level of array and hash indices/keys is translated properly.

AVAILABILITY

AutoVariable is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: lib/Vend/Config.pm
Line 517

['AutoVariable',   'autovar',        'UrlJoiner'],

Source: lib/Vend/Config.pm
Line 713

['AutoVariable',   'autovar',        ''],

Source: lib/Vend/Config.pm
Line 2550 (context shows lines 2550-2581)

sub parse_autovar {
my($var, $val) = @_;

return '' if ! $val;

my @dirs = grep /\w/, split /[\s,\0]+/, $val;

my $name;
foreach $name (@dirs) {
  next unless $name =~ /^\w+$/;
  my $val = get_directive($name);
  if(! ref $val) {
    parse_variable('Variable', "$name $val");
  }
  elsif ($val =~ /ARRAY/) {
    for(my $i = 0; $i < @$val; $i++) {
      my $an = "${name}_$i";
      parse_variable('Variable', "$an $val->[$i]");
    }
  }
  elsif ($val =~ /HASH/) {
    my ($k, $v);
    while ( ($k, $v) = each %$val) {
      next unless $k =~ /^\w+$/;
      parse_variable('Variable', "$k $v");
    }
  }
  else {
    config_warn('%s directive not parsable by AutoVariable', $name);
  }
}
}

AUTHORS

Interchange Development Group

SEE ALSO

base-url(7ic)

DocBook! Interchange!