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";
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;
...
}
|