1Template::Base(3)     User Contributed Perl Documentation    Template::Base(3)
2
3
4

NAME

6       Template::Base - Base class module implementing common functionality
7

SYNOPSIS

9           package My::Module;
10           use base qw( Template::Base );
11
12           sub _init {
13               my ($self, $config) = @_;
14               $self->{ doodah } = $config->{ doodah }
15                   ⎪⎪ return $self->error("No 'doodah' specified");
16               return $self;
17           }
18
19           package main;
20
21           my $object = My::Module->new({ doodah => 'foobar' })
22               ⎪⎪ die My::Module->error();
23

DESCRIPTION

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

PUBLIC METHODS

29       new(\%config)
30
31       Constructor method which accepts a reference to a hash array or a list
32       of "name => value" parameters which are folded into a hash.  The
33       _init() method is then called, passing the configuration hash and
34       should return true/false to indicate success or failure.  A new object
35       reference is returned, or undef on error.  Any error message raised can
36       be examined via the error() class method or directly via the package
37       variable ERROR in the derived class.
38
39           my $module = My::Module->new({ ... })
40               ⎪⎪ die My::Module->error(), "\n";
41
42           my $module = My::Module->new({ ... })
43               ⎪⎪ die "constructor error: $My::Module::ERROR\n";
44
45       error($msg, ...)
46
47       May be called as an object method to get/set the internal _ERROR member
48       or as a class method to get/set the $ERROR variable in the derived
49       class's package.
50
51           my $module = My::Module->new({ ... })
52               ⎪⎪ die My::Module->error(), "\n";
53
54           $module->do_something()
55               ⎪⎪ die $module->error(), "\n";
56
57       When called with parameters (multiple params are concatenated), this
58       method will set the relevant variable and return undef.  This is most
59       often used within object methods to report errors to the caller.
60
61           package My::Module;
62
63           sub foobar {
64               my $self = shift;
65
66               # some other code...
67
68               return $self->error('some kind of error...')
69                   if $some_condition;
70           }
71
72       debug($msg, ...)
73
74       Generates a debugging message by concatenating all arguments passed
75       into a string and printing it to STDERR.  A prefix is added to indicate
76       the module of the caller.
77
78           package My::Module;
79
80           sub foobar {
81               my $self = shift;
82
83               $self->debug('called foobar()');
84
85               # some other code...
86           }
87
88       When the foobar() method is called, the following message is sent to
89       STDERR:
90
91           [My::Module] called foobar()
92
93       Objects can set an internal DEBUG value which the debug() method will
94       examine.  If this value sets the relevant bits to indicate DEBUG_CALLER
95       then the file and line number of the caller will be appened to the mes‐
96       sage.
97
98           use Template::Constants qw( :debug );
99
100           my $module = My::Module->new({
101               DEBUG => DEBUG_SERVICE ⎪ DEBUG_CONTEXT ⎪ DEBUG_CALLER,
102           });
103
104           $module->foobar();
105
106       This generates an error message such as:
107
108           [My::Module] called foobar() at My/Module.pm line 6
109

AUTHOR

111       Andy Wardley <abw@wardley.org>
112
113       <http://wardley.org/http://wardley.org/>
114

VERSION

116       2.77, distributed as part of the Template Toolkit version 2.18,
117       released on 09 February 2007.
118
120         Copyright (C) 1996-2007 Andy Wardley.  All Rights Reserved.
121
122       This module is free software; you can redistribute it and/or modify it
123       under the same terms as Perl itself.
124

SEE ALSO

126       Template
127
128
129
130perl v5.8.8                       2007-02-09                 Template::Base(3)
Impressum