Template::Exception - exception handling class for the Template Toolkit
use Template::Exception; my $exception = Template::Exception->new($type, $data);
The Template::Exception module defines an object class for representing exceptional conditions (i.e. errors) within the template processing life cycle. Exceptions can be raised by modules within the Template Toolkit, or can be generated and returned by user code bound to template variables.
User code bound to template stash variables is expected to return a single $value or a pair of ($value, $error). The $error code may be a numerical value represented by one of the Template::Constant STATUS_XXXX constants. User code may "throw" an exception to the calling context, or throw the exception type and information fields so that an exception can be constructed. The context will then handle the exception in some way and return a value which can be propogated back to the caller. Depending on the presence of a CATCH for the exception type, that value may be the exception itself or some other status value.
$value
($value, $error)
sub my_code { my ($context = shift); # blah, blah, blah... if ($database_has_exploded) { return (undef, $context->throw("database", $database_error)); } else { return $value; } } $template->process($my_file, { 'magic' => \&my_code }) || die $template->error();
Andy Wardley <cre.canon.co.uk>
$Revision: 1.3 $
Copyright (C) 1996-1999 Andy Wardley. All Rights Reserved. Copyright (C) 1998-1999 Canon Research Centre Europe Ltd.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Template
To install Template, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Template
CPAN shell
perl -MCPAN -e shell install Template
For more information on module installation, please visit the detailed CPAN module installation guide.