Writing a MODULE_PARSER
 
    How to write a MODULE_PARSER ?
Name

How to write a MODULE_PARSER.

Versions

Caudium 1.0, 1.2, 1.3

Synopsis

The attached module allows you to define your own RXML Tag. While this particular tag doesn't do much of anything, it shows a few concepts that can be used.

Documentation

Sometimes it is helpful to create a tag to perform a specific function where it might need to interface with a database, do some mathematical calculation or other function that cannot easily be done in RXML.

This sample module illustrates how to define a simple RXML tag called <parser/> which accepts an argument of 'text'. In addition, a global variable is used to demonstrate the use of the Status and Debug Info section of the Config Interface. Each time the tag is called, it will increment the counter unless the module is reloaded from the Config Interface.

There is text that can be entered in the Config Interface that will prefix the argument passed to the tag <parser />

To use the module, do:

    <parser text="output this" />
    

and the output (if you did not change the Config Interface Text) should say:

Default Text in config interface: output this

Source
#include <module.h>
inherit "module";
inherit "caudiumlib";

constant module_type = MODULE_PARSER;
constant module_name = "Sample Tag Module";
constant module_doc  = #"This module was designed to enable you to see what a 
                        simple MODULE_PARSER looks like.<p>
                        Usage:<p>
                        &lt;parser text=\"asdf\" /><p>";
constant module_unique = 1;
constant thread_safe=1;

int	count = 0;

void create()
{
  /* defvar()'s */
  defvar("phrase", 
         "Default Text in config interface: ",
         "Phrase to output", TYPE_STRING,
         "This is the phrase to output in conjunction with the tag");
}

string tag_parser(string t, mapping m, object id)
{
  count++;
  return(QUERY(phrase) + " " + (string)m->text);
}

mapping query_tag_callers()
{
  return ([ "parser":tag_parser, ]);
}

string status()
{
  return("The sample tag was called<br>"+(string)count+"<br>time(s)");
}

  
Download the source
 
HTML OK CSS