Template::Base(3pm) User Contributed Perl Documentation Template::Base(3pm)
NAME
Template::Base - Base class module implementing common functionality
SYNOPSIS
package My::Module;
use base qw( Template::Base );
sub _init {
my ($self, $config) = @_;
$self->{ doodah } = $config->{ doodah }
|| return $self->error("No 'doodah' specified");
return $self;
}
package main;
my $object = My::Module->new({ doodah => 'foobar' })
|| die My::Module->error();
DESCRIPTION
Base class module which implements a constructor and error reporting functionality for
various Template Toolkit modules.
PUBLIC METHODS
new(\%config)
Constructor method which accepts a reference to a hash array or a list of "name => value"
parameters which are folded into a hash. The _init() method is then called, passing the
configuration hash and should return true/false to indicate success or failure. A new
object reference is returned, or undef on error. Any error message raised can be examined
via the error() class method or directly via the package variable ERROR in the derived
class.
my $module = My::Module->new({ ... })
|| die My::Module->error(), "\n";
my $module = My::Module->new({ ... })
|| die "constructor error: $My::Module::ERROR\n";
error($msg, ...)
May be called as an object method to get/set the internal _ERROR member or as a class
method to get/set the $ERROR variable in the derived class's package.
my $module = My::Module->new({ ... })
|| die My::Module->error(), "\n";
$module->do_something()
|| die $module->error(), "\n";
When called with parameters (multiple params are concatenated), this method will set the
relevant variable and return undef. This is most often used within object methods to
report errors to the caller.
package My::Module;
sub foobar {
my $self = shift;
# some other code...
return $self->error('some kind of error...')
if $some_condition;
}
debug($msg, ...)
Generates a debugging message by concatenating all arguments passed into a string and
printing it to STDERR. A prefix is added to indicate the module of the caller.
package My::Module;
sub foobar {
my $self = shift;
$self->debug('called foobar()');
# some other code...
}
When the foobar() method is called, the following message is sent to STDERR:
[My::Module] called foobar()
Objects can set an internal DEBUG value which the debug() method will examine. If this
value sets the relevant bits to indicate DEBUG_CALLER then the file and line number of the
caller will be appened to the message.
use Template::Constants qw( :debug );
my $module = My::Module->new({
DEBUG => DEBUG_SERVICE | DEBUG_CONTEXT | DEBUG_CALLER,
});
$module->foobar();
This generates an error message such as:
[My::Module] called foobar() at My/Module.pm line 6
AUTHOR
Andy Wardley <abw AT wardley.org>
<http://wardley.org/|http://wardley.org/>
VERSION
2.77, distributed as part of the Template Toolkit version 2.19, released on 27 April 2007.
COPYRIGHT
Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same
terms as Perl itself.
SEE ALSO
Template
perl v5.10.0 2007-04-27 Template::Base(3pm)
Generated by $Id: phpMan.php,v 4.49 2006/02/26 13:18:18 chedong Exp $ Author: Che Dong
On Apache
Under GNU General Public License
2012-05-25 02:26 @38.107.179.238 Crawled by CCBot/1.0 (+http://www.commoncrawl.org/bot.html)