Environment variables

DomTool has its own concept of typed environment variables that are used to tweak parameters of configuration directives. Here's an example to demonstrate how they're used and why they're useful.

Running this configuration:

vhost "www" with
end;

gives you an Apache virtual host that serves documents out of ~/public_html. If you wanted to serve documents out of $DIR instead, you could run:

vhost "www" where
  DocumentRoot = "$DIR"
with
end;

Maybe you want to use the same document root for two different virtual hosts. In that case, you could use:

let
  DocumentRoot = "$DIR"
in
  vhost "www" with
  end;

  vhost "www2" with
  end;
end;

Both of these alternatives involve assigning a new value to the environment variable DocumentRoot of type your_path, the type of filesystem paths that you may reference in configuration. Both where and let only introduce local values for environment variables. That is, once the let or the expression with the where clause has finished, it undoes changes to the environment made in the where clause or the first part of the let. This helps you maintain neat code that doesn't rely too much on global state.

As this example hopefully shows, environment variables are useful because they make it more pleasant to use highly-customizable configuration directives. The less-commonly-configured aspects of a directive can be taken in as environment variables rather than normal arguments. That way, you don't need to write any code to deal with them when you are happy with their default values. When you do want to set a non-standard value, you can use a construct like let to apply it to multiple directives at once.