Move the test actions to their own controller file to silence warning about
[catagits/Catalyst-View-TT.git] / t / lib / TestApp / Controller / Root.pm
1 package TestApp::Controller::Root;
2 use base 'Catalyst::Controller';
3 __PACKAGE__->config(namespace => '');
4
5 sub default : Private {
6     my ($self, $c) = @_;
7
8     $c->response->redirect($c->uri_for('test'));
9 }
10
11 sub test : Local {
12     my ($self, $c) = @_;
13
14     $c->stash->{message} = ($c->request->param('message') || $c->config->{default_message});
15 }
16
17 sub test_includepath : Local {
18     my ($self, $c) = @_;
19     $c->stash->{message} = ($c->request->param('message') || $c->config->{default_message});
20     $c->stash->{template} = $c->request->param('template');
21     if ( $c->request->param('additionalpath') ){
22         my $additionalpath = Path::Class::dir($c->config->{root}, $c->request->param('additionalpath'));
23         $c->stash->{additional_template_paths} = ["$additionalpath"];
24     }
25     if ( $c->request->param('addpath') ){
26         my $additionalpath = Path::Class::dir($c->config->{root}, $c->request->param('addpath'));
27         my $view = 'TestApp::View::TT::' . ($c->request->param('view') || $c->config->{default_view});
28         no strict "refs";
29         push @{$view . '::include_path'}, "$additionalpath";
30         use strict;
31     }
32 }
33
34 sub test_render : Local {
35     my ($self, $c) = @_;
36
37     my $out = $c->stash->{message} = $c->view('TT::Appconfig')->render($c, $c->req->param('template'), {param => $c->req->param('param') || ''});
38     if (UNIVERSAL::isa($out, 'Template::Exception')) {
39         $c->response->body($out);
40         $c->response->status(403);
41     } else {
42         $c->stash->{template} = 'test.tt';
43     }
44
45 }
46
47 sub test_msg : Local {
48     my ($self, $c) = @_;
49     my $tmpl = $c->req->param('msg');
50     
51     $c->stash->{message} = $c->view('TT::AppConfig')->render($c, \$tmpl);
52     $c->stash->{template} = 'test.tt';
53 }
54
55 sub end : Private {
56     my ($self, $c) = @_;
57
58     return 1 if $c->response->status =~ /^3\d\d$/;
59     return 1 if $c->response->body;
60
61     my $view = 'View::TT::' . ($c->request->param('view') || $c->config->{default_view});
62     $c->forward($view);
63 }
64
65 1;