Just Another Macro Language v3.01

. . . . . . . . . . . . . . . . . . . . . . . . for HTML

Using j-SEX Modules


Table of Contents


1. General introduction

has a mode to dynamically load Perl modules and to access functions of these modules from the source code. These modules can be loaded using the use macro of and can be used similar to those implemented in itself.

As these modules usually perform simple tasks we name these j-SEX Modules, (i.e.: Simple EXtension).

To use a j-SEX module you have to have access to the Perl source code of the module, and you have to install it. You need not be a Perl programming expert to use a j-SEX modules, however knowing Perl is not a drawback.

The release kit includes an example module, called example.pm. We will explain the usage of this module first, and then describe the methods more general.


2. Installing a module

To use the example extension you have to move or copy the supplied example.pm file to the directory perllibraries/jamal where perllibraries is the directory where the Perl modules usually are. If you do not know which directory this is: run using the -h or -? option, and will print out something like this:

jamal html preprocessor V{version}
Usage:

jamal [-options] input [output]

Options:
-? or -h               help
-m                     macro definition file
-D                     macro define
-I                     j-SEX directory
-0                     suppress output
-d                     put error message into result
.
Your default extension directories are:
D:\Perl\lib\i386-win32
D:\Perl\lib
.
This means that Perl searches for modules in the directories C:\Perl\lib\i386-win32, C:\Perl\lib and in . which is the actual directory. Therefore example.pm should be moved/copied to C:\Perl\lib\i386-win32\jamal\example.pm or C:\Perl\lib\jamal\example.pm or to .\jamal\example.pm. (Now you can guess that I develop using WindowsNT.)

In case you have no access to any of the directories that prints out on the machine that you use then you can specify an additional directory using the -I option of , example


               perl jamal.pl -I /etc/usr/users/meuser/myperlmodules test.jam
In this case example.pm should be copied to /etc/usr/users/meuser/myperlmodules/jamal/example.pm.

When you have copied the file to the location you can use the macros defined in it from any file. Note that the j-SEX module should be copied to the subdirectory named jamal below the /etc/usr/users/meuser/myperlmodules.


3. Using the extensions

To use an extension module you first have to tell to load it. This can be done using the built-in macro use. To use the example extension your file should contain the macro:

           {#use example}
This tells to load the extension called example and also set this extension to be the base extension. (See explanation of base extension later.)

This extension defines only two macros, called licence and list. This can be used to display a licence text on a Web page. A licence is usually printed all caps with initials printed using larger font. To write this in HTML requires lot of <FONT SIZE=+1> and alike typing.

The macro licence defined in the extension module example makes this job easy. It takes its argument as a text and convert all lower case characters to uppercase and all uppercase characters to <FONT SIZE=+1>x</FONT>, where x is the character itself. Therefore if you write:


        {#example::licence Here We Get All The Words Small Cap}
you will get:

HERE WE GET ALL THE WORDS SMALL CAP

Because the macro use not only loads the extension module, but also sets it to be the base extension you can write


        {#::licence Here We Get All The Words Small Cap}
which result the same

HERE WE GET ALL THE WORDS SMALL CAP

Note that the name of the macro in this case starts with the double colon. If you leave this will try to execute a built-in macro named licence and would eventually fail as there is no such built in macro. (By the way is freeware.)

The double colon is used to separate the module name from the macro name because Perl uses double colon for the same purpose.

There is a second optional argument to the macro use. This argument should be numeric if present and should define the version of the module that the file expects. compares this version number with the version installed, and if the installed version can not support the requested version i generates a fatal error.

See more information on version control in Writing j-SEX Modules.

When you use a macro defined by a module it should be preceeded by one of the character @ or # the same way as with built-in macros.


4. Module defined user macros

Modules may define "user defined" macros also. These macros have the name

modulename::macro
These macros can be used and can also be redefined by the user. The purpose of these macros is not to be used by the user directly usually, but to pass extra parameters to the Perl written macros and fine tune the behaviour of those.

The module example defines the user definable macro example::cap. As it is defined by the module it is equivalen to the definition:


      {#define example::cap/x=<FONT SIZE=+1>x</FONT>}
The macro example::licence generates an output text that uses this macro. Therefore the increase of the size of the capital letters can be fine tuned, or color can be defined. See the following example:

  {#define ExaText=This Is a Good Example}
  {#::licence {ExaText}}
  {#define example::cap/x=<FONT SIZE=+3 color=red>x</FONT>}
  {#::licence {ExaText}}
will result: THIS IS A GOOD EXAMPLE
THIS IS A GOOD EXAMPLE

The redefinition of example::cap can also be written in the form


  {#define ::cap/x=<FONT SIZE=+3 color=red>x</FONT>}
in case example is the base extension.

To see what actual macros the different modules define and how altering tunes the behaviour look at the documentation of the specific extension module.


5. Using more than one extension

Generally there is no restriction on the number of modules you can use in a file assumed that the modules are all installed (copied to the appropriate directory) and have different names. If you have a module named example and another module named pelda you can use both at the same time, like:

    {#use example}{#use pelda}
    {#example::licence Old Example}
    {#pelda::engedely Uj Pelda}
This example results the same output as

    {#use example}{#use pelda}
    {#example::licence Old Example}
    {#::engedely Uj Pelda}
The reason is that the macro use not only loads the extension but also sets it to be the base extension.

Whenever you want to change the base extension you can use the macro with, which does not load any extension only sets the named extension to be the base extensions. Therefore the following example results again the same output as the examples above:


    {#use example}{#use pelda}{#with example}
    {#::licence Old Example}{#with pelda}
    {#::engedely Uj Pelda}
keeps a record of the changing of the base extensions and whenever you change the base extension remembers the previous base extensions. You can use the macro with without argument to change the base extension back to its pervious value:

    {#use example}{#use pelda}{#with example}
    {#::licence Old Example}{#with}
    {#::engedely Uj Pelda}{#with}
    {#::licence New Example}
The base extensions in the order of evaluation are
  • example as the macro use not only loads the macro but also sets the base extension
  • pelda as it is use-d, but remembers example being the previous base extension.
  • example as it is set by the macro with, but remembers both pelda and example. Now we use this being a base extension calling the macro licence without specifying the extension.
  • pelda as macro with takes the last remembered base extension, and example remains remembered.
  • example as macro with takes this as the last remembered extension, and there remains no extension to be remembered.


6. Using different versions of modules

j-SEX modules develop and can have different versions. It can happen that a macro file wants to use a module but is not compatibe with the actual version installed in the j-SEX directory. In such a case miraculous results come out. To avoid this provides a way to define the version of the extension in the source file. When a macro file uses a module it can specify the name of the module as well as the version it requires, like

    {#use example 1.0}
The second argument of the macro use specify the version of the extension. If the version of the module which is currently installed on the system is not compatibel with the one that we request stops.

Specifying the version is a safe practice even if the version that macro file needs is the first version of the module. Later versions might change the behaviour and specifying the version we need gives them the chance to retard the behaviour to the specified version.


This page was created using jamal v3.01