[%# # IMPORTANT NOTE # This documentation is generated automatically from source # templates. Any changes you make here may be lost. # # The 'docsrc' documentation source bundle is available for download # from http://www.template-toolkit.org/docs.html and contains all # the source templates, XML files, scripts, etc., from which the # documentation for the Template Toolkit is built. -%] [% META book = 'Modules' page = 'Base' %] [% WRAPPER toc; INCLUDE tocitem title = 'SYNOPSIS'; INCLUDE tocitem title = 'DESCRIPTION'; INCLUDE tocitem title = 'PUBLIC METHODS' subs = [ 'new(\\%config)', 'error($msg)' ]; INCLUDE tocitem title = 'AUTHOR'; INCLUDE tocitem title = 'VERSION'; INCLUDE tocitem title = 'COPYRIGHT'; INCLUDE tocitem title = 'SEE ALSO'; END %] [% WRAPPER section title='SYNOPSIS' -%]

        package Template::MyModule;
        use base qw( Template::Base );

        sub _init {
    	my ($self, $config) = @_;
    	$self->{ doodah } = $config->{ doodah }
    	    || return $self->error("No 'doodah' specified");
    	return $self;
        }

[%- END %] [% WRAPPER section title='DESCRIPTION' -%]

Base class module which implements a constructor and error reporting functionality for various Template Toolkit modules.

[%- END %] [% WRAPPER section title='PUBLIC METHODS' -%][% WRAPPER subsection title = '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 = Template::MyModule->new({ ... })
            || die Template::MyModule->error(), "\n";

        my $module = Template::MyModule->new({ ... })
            || die "constructor error: $Template::MyModule::ERROR\n";

[%- END %] [% WRAPPER subsection title = '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 = Template::MyModule->new({ ... })
            || die Template::MyModule->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 Template::MyModule;

        ...

        sub foobar {
    	my $self = shift;
    	...
    	return $self->error('some kind of error...')
    	    if $some_condition;
    	...
        }

[%- END %] [%- END %] [% WRAPPER section title='AUTHOR' -%]

Andy Wardley <abw@kfs.org>

[% ttlink('http://www.andywardley.com/', 'http://www.andywardley.com/') -%]

[%- END %] [% WRAPPER section title='VERSION' -%]

2.33, distributed as part of the Template Toolkit version 2.06, released on 07 November 2001.

[%- END %] [% WRAPPER section title='COPYRIGHT' -%]

      Copyright (C) 1996-2001 Andy Wardley.  All Rights Reserved.
      Copyright (C) 1998-2001 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.

[%- END %] [% WRAPPER section title='SEE ALSO' -%]

[% ttlink('Template', 'Template') -%]

[%- END %]