The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

XML::Template::Vars - Module for handling XML::Template variables.

SYNOPSIS

This module is used for handling the various XML::Template data types and variables. It is used to create and remove variable contexts and get, set, and unset scalar, array, nested, and XPath variables.

CONSTRUCTOR

A constructor method new is provided by XML::Template::Base. A list of named configuration parameters may be passed to the constructor. The constructor returns a reference to a new parser object or under if an error occurred. If undef is returned, you can use the method error to retrieve the error. For instance:

  my $parser = XML::Template::Vars->new (%config)
    || die XML::Template::Vars->error;

PRIVATE METHODS

_init

This method is the internal initialization function called from XML::Template::Base when a new vars object is created.

_set

  $self->_set ($context, %vars);

This is the internal method for setting variables. The first parameter specifies the variable context in which the variables will be set. The remaining parameters comprise a hash of variable name/value pairs to set. The variable names are in the format of actual XML::Template variable names (e.g., hash.varname[2]/xpath).

_unset

  $self->_unset ($context, @varparts);

This method is the internal method for unsetting (deleting) variables. The first parameter is the context in which to remove variables. The remaining parameters are the individual parts of a nested variable. For instance to remove the variable hash1.hash2.varname, do

  $self->_unset ($context, 'hash1', 'hash2', 'varname');

  my $value = $self->_get ($var);

This method is the internal method for getting variables. The only parameter names the variable to get. The name of the variable is in the format of an XML::Template variable name.

PUBLIC METHODS

create_context

  $vars->create_context ();

This method creates a new variable context. Any variables added to this context will shadow variables with the same name in previous contexts.

delete_context

  $vars->delete_context ()

This method deletes the current variable context.

set

  $vars->set ('hash.varname[2]' => 'blah', 'varname2' => 'ick');

This method is used to set variables in the current variable context. The parameters comprise a hash of variable name/value pairs. The variable names are in the format of actual XML::Template variable names.

set_global

  $vars->set_global ('hash.varname[2]' => 'blah', varname2 => 'ick');

This method sets global variables by setting them in the topmost variable contest. The parameters comprise a hash containing variable name/value pairs to set. The variable names are in the format of actual XML::Template variable names.

unset

  $vars->unset ('hash.varname', 'varname2');

This method unsets (deletes) variables in the current variable context. The parameters comprise an array containing the names of variables to delete. The variable names are in the format of actual XML::Template variable names.

get

  my $value = $vars->get ('varname');
  my @values = $vars->get ('hash.varname[2]/xpath', 'varname2');

This method is used to get variable values. The parameters comprise an array of names of variables to get. The variable names are in the format of actual XML::Template variable names.

get

  my $value = $vars->get ('varname');
  my @values = $vars->get ('hash.varname[2]/xpath', 'varname2');

Like get, this method is used to get variable values. However, this method is XPath aware. That is, if a value is a GDOME object, it will be converted to text. Currently, only GDOME is supported. I need to implement a way to handle arbitrary XML parsers. The parameters comprise an array of names of variables to get. The variable names are in the format of actual XML::Template variable names.

AUTHOR

Jonathan Waxman jowaxman@bbl.med.upenn.edu

COPYRIGHT

Copyright (c) 2002-2003 Jonathan A. Waxman All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.