How does the specification file tell sgmlspl what to do?

Links: Next Previous Up Top

# How does the specification file tell `sgmlspl` what to do?

`sgmlspl` uses an event model rather than a procedural model -- instead of saying "do A then B then C" you say "whenever X happens, do A; whenever Y happens, do B; whenever Z happens, do C". In other words, while you design the code, `sgmlspl` decides when and how often to run it.

The specification file, which contains your instructions, is regular `perl5` code, and you can define packages and subroutines, display information, read files, create variables, etc. For processing the SGML document, however, `sgmlspl` exports a single subroutine, `sgml(event, handler)`, into the 'main' package -- each time you call `sgml`, you declare a handler for a specific type of `sgmls` event, and `sgmlspl` will then execute that handler every time the event occurs. You may use `sgml` to declare a handler for a generic event, like `'start_element'`, or a specific event, like `'<DOC>'` -- a specific event will always take precedence over a generic event, so when the `DOC` element begins, `sgmlspl` will execute the `'<DOC>'` handler rather than the `'start_element'` handler.

Links: Next Previous Up Top