NAME

Top Close Open

Template::TT3::Service - base class template service module

SYNOPSIS

Top Close Open
# 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;

DESCRIPTION

Top Close Open

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.

CONFIGURATION OPTIONS

Top Close Open

The base class service module defines one optional configuration item.

template

Top Close Open

Many services are involved in processing an additional template, e.g. a header, footer, wrapper, etc. This default option is provided for that purpose. Subclasses may ignore this option if it is of no relevance and/or define their own.

METHODS

Top Close Open

This module implements the following methods in addition to those inherited from the Template::TT3::Base and Badger::Base base class modules.

serve(\%env, $pipeline)

Top Close Open

This is a stub method in the base class that should be re-defined by service subclasses.

connect($pipeline)

Top Close Open

This method creates a service pipeline subroutine around the service.

my $pipeline = $service->connect;

See Template::TT3::Services for further details.

template_name()

Top Close Open

Returns the name of the default template specified via the template option.

template(\%env)

Top Close Open

Returns a template object for the default template specified via the template option. It is fetched from the context that must be provided in the environment passed to the method.

INTERNAL METHODS

Top Close Open

no_source()

Top Close Open

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.

AUTHOR

Top Close Open

Andy Wardley http://wardley.org/

COPYRIGHT

Top Close Open

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.

SEE ALSO.

Top Close Open

This module inherits methods from the Template::TT3::Base and Badger::Base base classes.


http://tt3.template-toolkit.org/docs/Template/TT3/Service.pm last modified 2009-12-18 08:59:42