Split process and render in View::TT (patch from ash)
[catagits/Catalyst-View-TT.git] / t / lib / TestApp.pm
CommitLineData
07571b2f 1package TestApp;
2
3use strict;
4use warnings;
5
6use Catalyst; # qw/-Debug/;
e2bbd784 7use Path::Class;
07571b2f 8
9our $VERSION = '0.01';
10
11__PACKAGE__->config(
12 name => 'TestApp',
13 default_message => 'hi',
14 default_view => 'Pkgconfig',
15 'View::TT::Appconfig' => {
16 PRE_CHOMP => 1,
17 POST_CHOMP => 1,
18 TEMPLATE_EXTENSION => '.tt',
19 },
20);
21
22__PACKAGE__->setup;
23
24sub default : Private {
25 my ($self, $c) = @_;
26
27 $c->response->redirect($c->uri_for('test'));
28}
29
30sub test : Local {
31 my ($self, $c) = @_;
32
33 $c->stash->{message} = ($c->request->param('message') || $c->config->{default_message});
34}
35
e2bbd784 36sub test_includepath : Local {
37 my ($self, $c) = @_;
38 $c->stash->{message} = ($c->request->param('message') || $c->config->{default_message});
39 $c->stash->{template} = $c->request->param('template');
40 if ( $c->request->param('additionalpath') ){
41 my $additionalpath = Path::Class::dir($c->config->{root}, $c->request->param('additionalpath'));
42 $c->stash->{additional_template_paths} = ["$additionalpath"];
43 }
3a4ffa2a 44 if ( $c->request->param('addpath') ){
45 my $additionalpath = Path::Class::dir($c->config->{root}, $c->request->param('addpath'));
46 my $view = 'TestApp::View::TT::' . ($c->request->param('view') || $c->config->{default_view});
47 no strict "refs";
48 push @{$view . '::include_path'}, "$additionalpath";
49 use strict;
50 }
e2bbd784 51}
52
1bc9fc55 53sub test_render : Local {
54 my ($self, $c) = @_;
55
56 $c->stash->{message} = $c->view('TT')->render($c, $c->req->param('template'), {param => $c->req->param('param')});
57 $c->stash->{template} = 'test.tt';
58
59}
60
61sub test_msg : Local {
62 my ($self, $c) = @_;
63 my $tmpl = $c->req->param('msg');
64
65 $c->stash->{message} = $c->view('TT')->render($c, \$tmpl);
66 $c->stash->{template} = 'test.tt';
67}
68
07571b2f 69sub end : Private {
70 my ($self, $c) = @_;
71
72 return 1 if $c->response->status =~ /^3\d\d$/;
73 return 1 if $c->response->body;
74
75 my $view = 'View::TT::' . ($c->request->param('view') || $c->config->{default_view});
76 $c->forward($view);
77}
78
791;