#============================================================= -*-perl-*-
#
# Template::Base
#
# DESCRIPTION
# Base class module implementing common functionality for various other
# Template Toolkit modules.
#
# AUTHOR
# Andy Wardley <abw@kfs.org>
#
# COPYRIGHT
# Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved.
# Copyright (C) 1998-2000 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.
#
#------------------------------------------------------------------------
#
# $Id: Base.pm,v 2.1 2000/11/01 12:01:39 abw Exp $
#
#========================================================================
package Template::Base;
require 5.004;
use strict;
use vars qw( $VERSION );
$VERSION = sprintf("%d.%02d", q$Revision: 2.1 $ =~ /(\d+)\.(\d+)/);
#------------------------------------------------------------------------
# new(\%params)
#
# General purpose constructor method which expects a hash reference of
# configuration parameters, or a list of name => value pairs which are
# folded into a hash. Blesses a hash into an object and calls its
# _init() method, passing the parameter hash reference. Returns a new
# object derived from Template::Base, or undef on error.
#------------------------------------------------------------------------
sub new {
my $class = shift;
my $params = (@_ && UNIVERSAL::isa($_[0], 'HASH')) ? shift : { @_ };
my $self = bless {
_ERROR => '',
}, $class;
return $self->_init($params) ? $self : $class->error($self->error);
}
#------------------------------------------------------------------------
# error()
# error($msg, ...)
#
# May be called as a class or object method to set or retrieve the
# package variable $ERROR (class method) or internal member
# $self->{ _ERROR } (object method). The presence of parameters indicates
# that the error value should be set. Undef is then returned. In the
# abscence of parameters, the current error value is returned.
#------------------------------------------------------------------------
sub error {
my $self = shift;
my $errvar;
{
no strict qw( refs );
$errvar = ref $self ? \$self->{ _ERROR } : \${"$self\::ERROR"};
}
if (@_) {
$$errvar = ref($_[0]) ? shift : join('', @_);
return undef;
}
else {
return $$errvar;
}
}
#------------------------------------------------------------------------
# _init()
#
# Initialisation method called by the new() constructor and passing a
# reference to a hash array containing any configuration items specified
# as constructor arguments. Should return $self on success or undef on
# error, via a call to the error() method to set the error message.
#------------------------------------------------------------------------
sub _init {
my ($self, $config) = @_;
return $self;
}
1;