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

36
########
# process the <myconf> node
########
sub process_myconf
{
my ($context, $node)=@_;
# get the current operation
my $op = $context->get_op();
my $verbose = $context->get_var('verbose');
# get the concatenated data buffers
my $data = $context->get_data();
# read the config file into $contents
my $configFile=$node->getAttribute('config_file');
$configFile='/tmp/myconf' if !$configFile;
my $contents = read_config($configFile);
# get the tag out of the data buffer (if it is there)
my $tag = ($data =~ /$TAG\s*(\w+)/) ? $1: "";
# Process operation
# delete or repalce
if ($op =~ /^(delete|replace)/) {
# remove all lines with the tag
$contents=~s/^(.*?$TAG\s*$tag.*?)$//mg;
write_config($configFile, $contents)
if $op =~ /^delete/;
}
# add or replace
if ($op =~ /^(add|replace)/) {
# append the data to the file whether it is tagged or not
$contents .= $data;
write_config($configFile, $contents);
}
# list
elsif ($op =~ /^list/) {
if ($verbose) {
# print the contents of the config file
print $contents;
}
else {
# print all tagged lines in the file that match the tag
while ( $contents=~/^(.*?$TAG\s*$tag.*?)$/mg) {
my $line = $1;
print "$line\n";
}
}
}
# export
elsif ($op =~ /^export/) {
my $xmlp = $context->get_xmlOut();
my $xpath = $xmlp->get_xp();
# example XML::XPath code to udpate the exchange file
# create a XML::XPATH data node with some text