1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
package TestAppSingleton;
use strict;
use base qw(CGI::Application);
use CGI::Application::Plugin::TT;
TestAppSingleton->tt_config(
TEMPLATE_OPTIONS => {
INCLUDE_PATH => 't',
POST_CHOMP => 1,
DEBUG => 1,
},
);
sub setup {
my $self = shift;
$self->start_mode('test_mode');
$self->run_modes(test_mode => 'test_mode' );
}
sub test_mode {
my $self = shift;
$self->tt_params(template_param_hash => 'template param hash.');
$self->tt_params({template_param_hashref => 'template param hashref.'});
my $tt_vars = {
template_var => 'template param.'
};
return $self->tt_process(\*DATA, $tt_vars);
}
sub tt_pre_process {
my $self = shift;
my $file = shift;
my $vars = shift;
$vars->{pre_process_var} = 'pre_process param.';
}
sub tt_post_process {
my $self = shift;
my $htmlref = shift;
$$htmlref =~ s/post_process_var/post_process param./;
}
1;
# The test template file is below in the DATA segment
__DATA__
[% template_var %]
[% template_param_hash %]
[% template_param_hashref %]
[% pre_process_var %]
post_process_var
|