# A Short FAQ on BML

# A short FAQ on BML

This is a crash guide to BML and its implementation. It's meant to be read by programmers or sysadmins with a working knowledge of Perl, who want to understand the implementation or improve it. This document is not a gentle introduction; it's meant to be terse and to-the-point.

What is BML?

BML is a server-side markup language designed by Brad Fitzpatrick. The official site is . However, the actual BML distribution there is outdated, so don't use it. Use the BML files inside LiveJournal source tree. See for information about LiveJournal CVS repository. The relevant files there which make up the implementation of BML all reside in `/livejournal/cgi-bin` directory, and they are:

## BML components

`bmlp.pl`

  The main program; the BML interpreter written in Perl.

`bmlp.cfg`

  The configuration file which alllows for customizing BML's run-time options.

`bml-client.pl`

  Helper functions to maintain persistent information between client requests.

`bml/schemes`

  A directory holding customizable template files for the site (see below).

What is BML for?

BML allows the site designer to encapsulate common chunks of HTML in abstract blocks, which are then used inside .bml files instead of repeating the same chunks of HTML many times. The BML interpreter processes a .bml file at runtime, transforming all the blocks which are placed there into HTML; it does this by using the definitions of blocks stored in site-wide template files. Since template files are site-wide, consistent use of BML blocks throughout the site ensures consistent user interface; in addition, simply changing the template (telling the BML interpreter to use another template file) automagically changes the user interface for the entire site in a consistent manner. Finally, a special kind of a block allows for embedding executable Perl code in a BML file, which is executed dynamically when the page is requested. This makes BML especially useful for writing sites with dynamic, database-driven content.

How does BML work?

All requests to BML documents end up as dynamic requests on the server side. Whenever a page is requested that is associated with a BML file, the HTTP server transfers control to the BML interpreter and asks it to return the appropriate HTML content to the user. The interpreter loads the page, processes it using appropriate template files and configuration options, creates HTML content and passes it back to the server.

How does the BML interpreter do what it needs to do?

The HTTP server config file is modified to tell the server to execute the intrepreter whenever a URI is requested which corresponds to a file with extension .bml. As the interpreter is executed, it receives from the server the name of the file to run and additional parameters such as environment variables, the remote user's HTTP headers and parameters embedded in the URL, and so on. The interpreter reads its config file to determine runtime options, finds the appropriate template files, loads the definitions of blocks from the template files, and processes the BML file, transforming all the block invocations into appropriate HTML text, which is fed back to the HTTP server.

What is the interface between the HTTP server and the BML interpreter?

Currently the interpreter is written to conform to FastCGI interface. See: for comprehensive information on what FastCGI is. Briefly, FastCGI allows for more efficient execution of scripts than the original CGI interface, but scripts must be written to process many requests in a loop, rather than just process one request and exit as in CGI. This requirement determines some important details of the interpreter's design, which are discussed below.

Nevertheless, one of the short-term goals of BML's evolution is to modify the interpreter so that it is able to run unchanged under three different interfaces: CGI, FastCGI and mod_perl. See: for more information of mod_perl.