AddDirective — add a new configuration directive


directive_name [parse_function_name [default_value]]


This directive allows you to extend the set of regular configuration directives accepted in each catalog.cfg. The added directives are then treated the same as the existing "built-ins".

Three standard arguments can be specified: the directive_name, parse_function_name and default_value.

If the parse function is not defined (either by omitting it or literally specifying undef), then no parser will be called on the value at all, and the value of the directive will be exactly what users specify in their config files (which will usually be Perl scalar values). If the parser argument is supplied, then the requested parser function must already be defined because it can't be referenced in advance. It can be defined either as a Sub or GlobalSub block, or can refer to an existing parser function from lib/Vend/ The file lib/Vend/ contains all the default parser functions, which are recognized by the mandatory prefix parse_. (You do not, however, include parse_ in the parse_function_name.)

The default_value is optional.

Directly modifying (or any other files from the Interchange installation) is discouraged for portability reasons. Therefore, to add a custom parsing function, you should modify interchange.cfg as seen in the section called “EXAMPLES” (note again that the parser definition must logically come before AddDirective).


Global directive


Example: Adding a new catalog configuration directive with a custom parse routine

Let's add the DocRoot directive. Put the following in your interchange.cfg:

GlobalSub <<EOS
sub declare_extra_config {

	package Vend::Config;

	sub parse_docroot {
		my ($var, $value) = @_;

		unless ( -d $value ) { $@ = errmsg("Directory $value: $!") }
		if ($@) { config_warn($@) }


AddDirective DocRoot docroot "/var/www"

Example: Adding the "Swish" directive with an existing parse routine

Require       module  Vend::Swish

Variable      swish   Vend::Swish

AddDirective  Swish   hash


Note that boolean, one of the default parse functions, is actually a boolean list, and not a true boolean value. The list achieves the effect of being boolean by logically returning true or false, depending on whether the searched item is present in the list or not. True boolean values are called "yesno"s in Interchange parlance.

Please see the configuration glossary entry for a discussion on config directives.


AddDirective is available in Interchange versions:

4.6.0-5.9.0 (git-head)


Interchange 5.9.0:

Source: lib/Vend/
Line 501

['AddDirective',   'directive',     ''],

Source: lib/Vend/
Line 2924 (context shows lines 2924-2941)

sub parse_directive {
my($name, $val) = @_;

return '' unless $val;
my($dir, $parser, $default) = split /\s+/, $val, 3 ;
if(! defined &{"parse_$parser"} and ! defined &{"$parser"}) {
  if (defined $Global::GlobalSub->{"parse_$parser"}) {
    no strict 'refs';
    *{"Vend::Config::parse_$parser"} = $Global::GlobalSub->{"parse_$parser"};
  } else {
    $parser = undef;
$default = '' if ! $default or $default eq 'undef';
$Global::AddDirective = [] unless $Global::AddDirective;
push @$Global::AddDirective, [ $dir, $parser, $default ];
return $Global::AddDirective;


Interchange Development Group


DeleteDirective(7ic), ActionMap(7ic), Replace(7ic)

DocBook! Interchange!