HP-UX CMGR A.02.00 Administrator's and Developer's Guide
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:
DescriptionFunction Name
Returns the contents of the concatenated <data> child
elements of the new element, with the variable values
substituted for their names.
$context->get_data()
Returns the current operation: add, delete, replace, help,
or list.
$context->get_op()
Returns the value of the template variable “name”. Calls Perl's
die() function if the variable has an undefined value. Wrap
the function in a Perl eval{} block if you do not wish the
handler to terminate if this error occurs.
$context->get_var(“name”)
Sets the value of variable “name” to “value”. Calls the
variables validate function, if one is defined. If validation fails,
set_var() calls Perl’s die() function.
$context->set_var(“name”,
“value”)
Returns the value of attribute “name”.$node->getAttribute(“name”)
The handler may print output to stderr or stdout and must return a NULL list.
When the handler encounters a serious error it must call perl’s die() with an
error message.
6. Test the new element handler and DTD by running the cmgr command with the
validate option:
# cmgr –t mytemplate.cst –Validate -l
4.2 Developing a Variable Validation Function
A new CMGR variable validation function may be defined for a template. The rules
for writing and using the function are as follows:
1. Create a validation function with a descriptive name. The function must accept
the template variable name and value to be validated as the first and second
parameters. Additional parameters may also used. The function must call perl’s
die() when it encounters a validation error. Otherwise the value of the second
parameter is considered valid and the function must return 0.
2. The validation function must be part of a Perl module. The module file must be
located under /opt/hpcmgr/lib/cmgr and the module filename must be the
same as the module name as per Perl convention.
3. The CMGR template referencing the validation function must include the full
module name. For example: Cmgr::Mymodule::functionname(). Parameters
should be enclosed in single quotes and may contain template variables. For
example:
40 Developing a CMGR Plug-in