# an example of a service class package Template::TT3::Service::Header; use Template::TT3::Class version => 2.70, debug => 0, base => 'Template::TT3::Service', config => 'name=header'; sub serve { my ($self, $env, $pipeline) = @_; # fetch the header template if there is one my $header = $self->template( $env ) || return $pipeline->( $env ); # process the header and then the rest of the pipeline return $header->fill_in( $env->{ context } ) . $pipeline->( $env ); } 1;
This module implements a base class for template service modules. A service is responsible for modifying the generated output from a template in some way. For example, adding a header, footer, etc.
You should start by reading the documentation for Template::TT3::Services which provides an overview of services and service pipeline.
The base class service module defines one optional configuration item.
This module implements the following methods in addition to those inherited from the Template::TT3::Base and Badger::Base base class modules.
This is a stub method in the base class that should be re-defined by service subclasses.
This method creates a service pipeline subroutine around the service.
my $pipeline = $service->connect;
See Template::TT3::Services for further details.
Returns the name of the default template specified via the template option.
This method is called by the
connect()
method when called without a
source $pipeline
to connect to. In most cases this is an indication
of incorrect usage and the method throws an error accordingly. However,
some services (most notably
Template::TT3::Service::Input
) do not
require a source pipeline as they usually sit at the start of a pipeline.
In this case the module will re-define the no_source()
method to silently
return without complaint.
Andy Wardley http://wardley.org/
Copyright (C) 1996-2009 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.
This module inherits methods from the Template::TT3::Base and Badger::Base base classes.