HP-UX CMGR A.02.01 Administrator's and Developer's Guide

32
3 Developing a CMGR Plug-in
This chapter describes how to extend CMGR’s functionality by developing a new element handler and
a new variable validation function for CMGR.
This chapter discusses the following topics:
3.1 Developing an Element
Handler
3.2 Developing a Variable Validation
Function
3.3 Example
Plug-in
3.1 Developing an Element Handler
CMGR uses Perl modules to process CMGR template elements. The rules for writing a handler for a
new element are:
1. Select a lower-case name for the new element. For 3.3 Example
Plug-in, we chose the
element <myconf>.
2. Update CMGR’s template Document Type Definition (DTD) with the new element. The DTD file
is /etc/opt/hpcmgr/templates/cmgr.dtd.
Create an <!ELEMENT> entry for the new element and add the allowable child
elements for the new element (such as data, help, success, and failure).
Define the attributes (such as if and id, allowed for the new element with
<!ATTLIST>.
Add the new element to the allowable child elements for the head, prologue, and
body elements.
3. Create or update an existing template with the new element.
4. The file, module name, and function names for the handler are based upon the XML element
name (element_name) that it implements:
The handler must be included in a Perl module. The module name for the handler
must be “Cmgr::Element_name where Element_name has the first letter
capitalized.
The filename for the module is /opt/hpcmgr/lib/Cmgr/Element_name.pm
where Element_name has the first character capitalized.
The handler function name is “process_element_name. Note that the first
character of the element name is not capitalized.
For example, if the element is <myconf>, then the module filename is
/opt/hpcmgr/lib/Cmgr/Myconf.pm, the module name is Cmgr::Myconf and the
handler function name is process_myconf().
5. Write the handler function. The handler function must accept $context (as the first
parameter) and $node (as the second parameter). The $context parameter is a handle for
accessing template variables, and the $node parameter is a handle for reading attribute
values attached to the handler’s XML element in the template. The following functions can be
called on the $context and $node:
Function Name Description
$context->get_data()
Returns the contents of the concatenated <data> child
elements of the new element, with the variable values
substituted for their names.