HP-UX CMGR A.02.01 Administrator's and Developer's Guide
33
Function Name Description
$context->get_op()
Returns the current operation: add, delete, replace,
help
, or
list
.
$context-
>get_var(“name”)
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-
>set_var(“name”,
“value”)
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->get_xmlOut-
>get_xp()
$context->get_xmlIn-
>get_xp()
Get XML::XPath object for export/import exchange.xml
file.
$node-
>getAttribute(“name”)
Returns the value of attribute “name”.
6. NOTE: For import and export operations, the handler may update the exchange.xml file
which is stored in the exchange file archive. The exchange file archive is currently readable
with the tar command.
7. 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 function with an error message.
8. Test the new element handler and DTD by running the cmgr command with the validate
option:
# cmgr –t mytemplate.cst –Validate –l
3.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:
<var name=”variable”
validate=”Cmgr::Modulename::functionname(‘You must enter a
value!’)” />