Yet another template module


The module contains a single function named interpolate. This is called as

interpolate(\$tmpl, %inter);
with a string $tmpl where it interpolates variables using %inter. The nice thing is that it can handle arrays.

It can be used for cgi pages or as a report generator.

Take a Closer Look

One of several possible concepts concerning GUI development is to have seperate files containing window descriptions. This is to seperate the GUI design from the implemented functionality.

Doing a few cgi pages, I missed such a beast. The obvious simple thing to do is:

This is very limited because it can't handle arrays. And in most cases there are things like e.g. listboxes to be dynamically filled.

The way this package handles this is to handle arrays by an universal example:

<select name="pizza" size="3">
  <option value="@+list$value">@+list$entry</option>
  <option value="@-list">@-list</option>

So there are two types of names.

The universial example has two lines. The first line of the name block starts with the @+name and ends with the last @+name. The second line starts with the first @-name and ends with the last. Both lines should not overlap.

The interpolate function takes a hash of the form

@list = ({'value' => '11',
          'name'  => 'Funghi'},
         {'value' => '12',
          'name'  => 'Margherita'},
         {'value' => '13',
          'name'  => 'Spinacci'})

%inter = (
   'list' => \@list

It takes the first line and does the obvious with the first entry. Then it appends the section from the universial which is between the two lines. After this it takes the first line again to the obvious with the second entry.

This results in

That's it.