Apache2-Controller
view release on metacpan or search on metacpan
lib/Apache2/Controller/Render/Template.pm view on Meta::CPAN
package Apache2::Controller::Render::Template;
=head1 NAME
Apache2::Controller::Render::Template - A2C render() with Template Toolkit
=head1 VERSION
Version 1.001.001
=cut
use version;
our $VERSION = version->new('1.001.001');
=head1 SYNOPSIS
# apache2 config file
PerlLoadModule Apache2::Controller::Directives
PerlLoadModule Apache2::Controller::DBI::Connector
# location of templates - must be defined
A2C_Render_Template_Path /var/myapp/templates /var/myapp/template_components
<Location /foo>
SetHandler modperl
PerlInitHandler MyApp::Dispatch::Foo
# set directives A2C_DBI_DSN, etc.
PerlHeaderParserHandler Apache2::Controller::DBI::Connector
</Location>
See L<Apache2::Controller::Dispatch> for A2C Dispatch implementations.
See L<Apache2::Controller::Directives> and L<Apache2::Controller::DBI::Connector>.
package MyApp::C::Bar; # let's assume this controller was dispatched
use strict;
use warnings;
use base qw(
Apache2::Controller
Apache2::Controller::Render::Template
);
use Apache2::Const -compile => qw( HTTP_OK );
sub allowed_methods {qw( default )}
sub default {
my ($self, @first, @last) = @_;
my @path_args = $self->my_detaint_path_args('name'); # from $self->{path_args}
$self->{stash}{creditcards} = $self->pnotes->{a2c}{dbh}->fetchall_arrayref(
q{ SELECT ccnum, exp, addr1, zip, cac
FROM customer_credit_cards
WHERE lname = ? AND fname = ?
}, undef, @path_args
);
# request was like http://myserver.xyz/foo/Larry/Wall
$self->render(); # renders /var/myapp/templates/foo/default.html
return Apache2::Const::HTTP_OK;
}
__END__
[%# /var/myapp/templates/foo/default.html %]
<p>Here is the credit card info you requested for
everyone named [% path_args.reverse.join(' ') %]:</p>
<ul>
[% FOREACH card = creditcards %]
[% FOREACH field = ['ccnum','exp','addr1','zip','cac'] %]
<li><strong>[% field %]:</strong> [% card.$field %]</li>
[% END %]
[% END %]
</ul>
[%# end template toolkit file %]
=head1 DESCRIPTION
This module provides a nice rendering mechanism for Apache2::Controller.
=head1 TEMPLATE OPTIONS
You can specify options for L<Template> in one of two ways:
=head2 DIRECTIVES
By using
L<Apache2::Controller::Directives/A2C_Render_Template_Opts>:
<Location '/foo'>
A2C_Render_Template_Opts INTERPOLATE 1
A2C_Render_Template_Opts PRE_PROCESS header
A2C_Render_Template_Opts POST_CHOMP 1
</Location>
=head2 METHOD template_options()
Or by implementing C<<template_options>> in your controller:
package MyApp::Controller;
use base qw( Apache2::Controller Apache2::Controller::Render::Template );
sub allowed_methods {qw( default )}
sub template_options {
my ($self) = @_;
return {
INTERPOLATE => 1,
( run in 1.766 second using v1.01-cache-2.11-cpan-39bf76dae61 )