DirConfig — batch-set a bunch of variables (or values in general) from files


directive_name directory_glob


The directive allows you to batch-set a bunch of variables from files.

directive_name is usually Variable, but can practically be any hash-based directive. directory_glob is a filespec that can encompass multiple directories (files are ignored).

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 @_VARIABLE_@ 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.


Catalog directive


Example: Setting DirConfig

DirConfig Variable templates/foundation/regions

If the file NOLEFT_TOP is present at catalog config time at the specified location, code __NOLEFT_TOP__ encountered on a page will mimic [include templates/foundation/regions/NOLEFT_TOP].


Make sure you don't get confused by the existence of all DirConfig, ConfDir and ConfigDir.


DirConfig is available in Interchange versions:

4.6.0-5.9.0 (git-head)


Interchange 5.9.0:

Source: lib/Vend/
Line 619

['DirConfig',         'dirconfig',        ''],

Source: lib/Vend/
Line 4732 (context shows lines 4732-4764)

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;


Interchange Development Group


dynamic_variables(7ic), dynamic_variables_file_only(7ic), VariableDatabase(7ic)

DocBook! Interchange!