Apache2::DirBasedHandler::TT - TT hooked into DirBasedHandler
package My::Thingy; use strict; use Apache2::DirBasedHandler::TT our @ISA = qw(Apache2::DirBasedHandler::TT); use Apache2::Const -compile => qw(:common); sub index { my $self = shift; my ($r,$uri_args,$args) = @_; if (@$uri_args) { return Apache2::Const::NOT_FOUND; } $$args{'vars'}{'blurb'} = qq[this is the index]; return $self->process_template( $r, $$args{'tt'}, $$args{'vars'}, qq[blurb.tmpl], qq[text/plain; charset=utf-8], ); } sub super_page { my $self = shift; my ($r,$uri_args,$args) = @_; $$args{'vars'}{'blurb'} = qq[this is \$location/super and all it's contents]; return $self->process_template( $r, $$args{'tt'}, $$args{'vars'}, qq[blurb.tmpl], qq[text/plain; charset=utf-8], ); } sub super_dooper_page { my $self = shift; my ($r,$uri_args,$args) = @_; $$args{'vars'}{'blurb'} = qq[this is \$location/super/dooper and all it's contents]; return $self->process_template( $r, $$args{'tt'}, $$args{'vars'}, qq[blurb.tmpl], qq[text/plain; charset=utf-8], ); } 1;
Apache2::DirBasedHandler::TT, is an subclass of Apache2::DirBasedHandler with modified to allow easy use of Template Toolkit templates for content generation.
init calls get_tt to get the template object, and stuffs it into the hash it gets back from the super class.
init
get_tt returns a Template Toolkit object, and a hash reference of variables which will be passed into the TT process call. You should really override this function with to create the Template object appropriate to your environment.
get_tt
process_template is a helper function to generate a page based using the template object, variables, and template passed in. It sets the content_type of the response to the value of the fifth argument.
process_template
Copyright 2008, Adam Prime (adam.prime@utoronto.ca)
This software is free. It is licensed under the same terms as Perl itself.
To install Apache2::DirBasedHandler::TT, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Apache2::DirBasedHandler::TT
CPAN shell
perl -MCPAN -e shell install Apache2::DirBasedHandler::TT
For more information on module installation, please visit the detailed CPAN module installation guide.