Apache-Template

 view release on metacpan or  search on metacpan

lib/Apache/Template.pm  view on Meta::CPAN

    my $pbases = $cfg->{ PLUGIN_BASE } ||= [ ];
    push(@$pbases, $base);
}

#------------------------------------------------------------------------
# TT2AutoReset Off      # disable AUTO_RESET
#------------------------------------------------------------------------

sub TT2AutoReset($$$) {
    my ($cfg, $parms, $on) = @_;
    $cfg->{ AUTO_RESET } = $on;
}

#------------------------------------------------------------------------
# TT2CacheSize 128      # define CACHE_SIZE
#------------------------------------------------------------------------

sub TT2CacheSize($$$) {
    my ($cfg, $parms, $size) = @_;
    $cfg->{ CACHE_SIZE } = $size;
}

#------------------------------------------------------------------------
# TT2CompileExt .tt2        # define COMPILE_EXT
#------------------------------------------------------------------------

sub TT2CompileExt($$$) {
    my ($cfg, $parms, $ext) = @_;
    $cfg->{ COMPILE_EXT } = $ext;
}

#------------------------------------------------------------------------
# TT2CompileDir /var/tt2/cache  # define COMPILE_DIR
#------------------------------------------------------------------------

sub TT2CompileDir($$$) {
    my ($cfg, $parms, $dir) = @_;
    $cfg->{ COMPILE_DIR } = $dir;
}

#------------------------------------------------------------------------
# TT2Debug On           # enable DEBUG
#------------------------------------------------------------------------

sub TT2Debug($$$) {
    my ($cfg, $parms, $on) = @_;
    $cfg->{ DEBUG } = $DEBUG = $on;
}

#------------------------------------------------------------------------
# TT2Headers length etag        # add certain HTTP headers
#------------------------------------------------------------------------

sub TT2Headers($$@) {
    my ($cfg, $parms, $item) = @_;
    my $headers = $cfg->{ SERVICE_HEADERS } ||= [ ];
    push(@$headers, $item);
}

#------------------------------------------------------------------------
# TT2Params uri env pnotes uploads request            # add template vars
#------------------------------------------------------------------------

sub TT2Params($$@) {
    my ($cfg, $parms, $item) = @_;
    my $params = $cfg->{ SERVICE_PARAMS } ||= [ ];
    push(@$params, $item);
}

#------------------------------------------------------------------------
# TT2ContentType   text/xml                         # custom content type
#------------------------------------------------------------------------

sub TT2ContentType($$$) {
    my ($cfg, $parms, $type) = @_;
    $cfg->{ CONTENT_TYPE } = $type;
}

#------------------------------------------------------------------------
# TT2ServiceModule   My::Service::Class     # custom service module
#------------------------------------------------------------------------

sub TT2ServiceModule($$$) {
    my ($cfg, $parms, $module) = @_;
    $Template::Config::SERVICE = $module;
}

#------------------------------------------------------------------------
# TT2Variable name value       # define template variable
#------------------------------------------------------------------------

sub TT2Variable($$$$) {
    my ($cfg, $parms, $name, $value) = @_;
    $cfg->{ VARIABLES }->{ $name } = $value;
}

#------------------------------------------------------------------------
# TT2Constant   foo  bar
#------------------------------------------------------------------------

sub TT2Constant($$@@) {
    my ($cfg, $parms, $name, $value) = @_;
    my $constants = $cfg->{ CONSTANTS } ||= { };
    $constants->{ $name } = $value;
}

#------------------------------------------------------------------------
# TT2ConstantsNamespace const
#------------------------------------------------------------------------

sub TT2ConstantsNamespace($$$) {
    my ($cfg, $parms, $namespace) = @_;
    $cfg->{ CONSTANTS_NAMESPACE } = $namespace;
}



#========================================================================
# Configuration creators/mergers
#========================================================================

lib/Apache/Template.pm  view on Meta::CPAN


This is equivalent to the COMPILE_DIR option.  It can be used to
specify a root directory under which compiled templates should be 
written back to disk for cache persistance.  Any TT2IncludePath 
directories will be replicated in full under this root directory.

    TT2CompileDir   /var/tt2/cache

=item TT2Debug

This is equivalent to the DEBUG option which enables Template Toolkit
debugging.  The main effect is to raise additional warnings when
undefined variables are used but is likely to be expanded in a future
release to provide more extensive debugging capabilities.

    TT2Debug        On

=item TT2Tolerant

This is equivalent to the TOLERANT option which makes the Template
Toolkit providers tolerant to errors.

    TT2Tolerant     On

=item TT2Headers

Allows you to specify which HTTP headers you want added to the
response.  Current permitted values are: 'type' (Content-Type),
'length' (Content-Length), 'modified' (Last-Modified) and 'etag'
(E-Tag).

    TT2Headers      type length

It can also be set to 'all' to enable all headers.

    TT2Headers      all

If the TT2Headers option is not specified, then it default to 'type',
sending the Content-Type header set to the value of TT2ContentType
or 'text/html' if undefined. 

    TT2Headers      type    # default - same as no TT2Headers option

The option can be set to 'none' to disable all headers, including the
Content-Type.

    TT2Headers      none

=item TT2ContentType

This option can be used to set a Content-Type other than the default
value of 'text/html'.

    TT2ContentType   text/xml

=item TT2Params

Allows you to specify which parameters you want defined as template
variables.  Current permitted values are 'uri', 'env' (hash of
environment variables), 'params' (hash of CGI parameters), 'pnotes'
(the request pnotes hash), 'cookies' (hash of cookies), 'uploads' (a
list of Apache::Upload instances), 'request' (the Apache::Request
object) or 'all' (all of the above).

    TT2Params       uri env params uploads request

When set, these values can then be accessed from within any 
template processed:

    The URI is [% uri %]

    Server name is [% env.SERVER_NAME %]

    CGI params are:
    <table>
    [% FOREACH key = params.keys %]
       <tr>
     <td>[% key %]</td>  <td>[% params.$key %]</td>
       </tr>
    [% END %]
    </table>


=item TT2ServiceModule

The modules have been designed in such a way as to make it easy to
subclass the Template::Service::Apache module to create your own
custom services.  

For example, the regular service module does a simple 1:1 mapping of
URI to template using the request filename provided by Apache, but
you might want to implement an alternative scheme.  You might prefer,
for example, to map multiple URIs to the same template file, but to
set some different template variables along the way.  

To do this, you can subclass Template::Service::Apache and redefine
the appropriate methods.  The template() method performs the task of
mapping URIs to templates and the params() method sets up the template
variable parameters.  Or if you need to modify the HTTP headers, then
headers() is the one for you.

The TT2ServiceModule option can be set to indicate the name of your
custom service module.  The following trivial example shows how you
might subclass Template::Service::Apache to add an additional parameter,
in this case as the template variable 'message'.

    <perl>
    package My::Service::Module;
    use base qw( Template::Service::Apache );

    sub params {
    my $self = shift;
        my $params = $self->SUPER::params(@_);
        $params->{ message } = 'Hello World';
        return $params;
    }
    </perl>

    PerlModule          Apache::Template
    TT2ServiceModule    My::Service::Module

=back

=head1 CONFIGURATION MERGING



( run in 2.310 seconds using v1.01-cache-2.11-cpan-b16cb0d3907 )