DirConfig — batch-set a bunch of variables (or values in general) from files
The directive allows you to batch-set a bunch of variables from files.
is usually
directive_name
Variable
, but can practically be any hash-based directive.
is a filespec
that can encompass multiple directories (files are ignored).
directory_glob
The specified directories are read for file names that
contain only word characters, i.e. something that would be a valid
Variable
. (This alone might make
it unsuitable for some other uses, but picking up the junk from the
in-directory-backup-file people would be intolerable.)
Then the contents of the found files are used to set the variables (or other
values) named after file names.
The source file name is kept in
$Vend::Cfg->{DirConfig}{Variable}{VARNAME}
if dynamic_variables
pragma is set.
dynamic_variables
enables dynamic
updating of variables from files.
dynamic_variables_files_only
restricts dynamic variables to
files only — otherwise variables are dynamically read from the
VariableDatabase
definition as well.
With dynamic variables, all
@_
and
VARIABLE
_@__
calls are checked
first to see if their source file is defined. If they are — if there is
a hash key present for the source file — even if its contents are blank,
it is returned as the value.
VARIABLE
__
Example: Setting DirConfig
DirConfig Variable templates/foundation/regions
If the file NOLEFT_TOP
is present at catalog config time
at the specified location, code encountered on
a page will mimic
[include templates/foundation/regions/NOLEFT_TOP]
.
Interchange 5.9.0:
Source: lib/Vend/Config.pm
Line 4735 (context shows lines 4735-4767)
sub parse_dirconfig { my ($var, $value) = @_; return '' if ! $value; $value =~ s/(\w+)\s+//; my $direc = $1; #::logDebug("direc=$direc value=$value"); my $ref = $C->{$direc}; unless(ref($ref) eq 'HASH') { config_error("DirConfig called for non-hash configuration directive."); } my $source = $C->{$var} || {}; my $sref = $source->{$direc} || {}; my @dirs = grep -d $_, glob($value); foreach my $dir (@dirs) { opendir(DIRCONFIG, $dir) or next; my @files = grep /^\w+$/, readdir(DIRCONFIG); for(@files) { next unless -f "$dir/$_"; #::logDebug("reading key=$_ from $dir/$_"); $ref->{$_} = readfile("$dir/$_", $Global::NoAbsolute, 0); $ref->{$_} = substitute_variable($ref->{$_}) if $C->{ParseVariables}; $sref->{$_} = "$dir/$_"; } } $source->{$direc} = $sref; return $source; }