View on
Jonathan Waxman > XML-Template-3.20 > XML::Template



Annotate this POD

View/Report Bugs
Module Version: 3.20   Source  


XML::Template - Front end module to XML::Template.


  use XML::Template;

  my $xml_template = XML::Template->new ($config)
    || die XML::Template->error;
  $xml_template->process ('filename.xhtml', %vars)
    || die $xml_template->error;


This module provides a front-end interface to XML::Template.


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 XML::Template object or undef if an error occurrs. If undef is returned, use the method error to retrieve the error. For instance:

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

The following named configuration parameters are supported by this module:


If a scalar, the name of the XML::Template document to display when an exception is raised. The template variables Exception.type and will be set for the exception type and description, respectively.

ErrorTemplate may also be a reference to an array in which the first element is the name of the default error template and the second element is a hash of exception type/template name pairs. If the type of the exception raised in listed in the hash, the associated template will be displayed. Otherwise, the default template is displayed.

If no error template is given (the default), XML::Template will die.


A reference to a processor object. This value will override the default value $PROCESS in XML::Template::Config. The default process object is XML::Template::Process.

See XML::Template::Base and XML::Template::Config for additional options.



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


  $self->_handle_error ($type, $info);

This method will display the appropriate error template for the exception type, the first parameter. The second parameter is the description of the exception or error message.



  $xml_template->process ($filename, %vars)
    || die $xml_template->error;

This method is used to process an XML file. The first parameter is the name of an XML document. The actual source of the XML depends on the which loader loads the document first. (See XML::Template::Process.) The second parameter is a reference to a hash containing name/value pairs of variables to add to the global variable context.


Much of the initial design philosophy (and design) was taken from or inspired by the masterfully written Template Toolkit by Andy Wardley which I use extensively myself.

Thanks to Josh Marcus, August Wohlt, and Kristina Clair for many valuable discussions.


Jonathan A. Waxman <>


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.

syntax highlighting: