AutoVariable — specify config directives to make available through the Variable space
Specify list of configuration directives whose values are to be made
available through the variable space.
This allows you to conveniently
write say, __
, and
retrieve the corresponding configuration directive's value.
DirectiveName
__
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
__
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
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.
Interchange 5.9.0:
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); } } }