silence warning, see RT#75104
[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     $c->stash->{template} = $c->request->param('template');
16 }
17
18 sub test_includepath : Local {
19     my ($self, $c) = @_;
20     $c->stash->{message} = ($c->request->param('message') || $c->config->{default_message});
21     $c->stash->{template} = $c->request->param('template');
22     if ( $c->request->param('additionalpath') ){
23         my $additionalpath = Path::Class::dir($c->config->{root}, $c->request->param('additionalpath'));
24         $c->stash->{additional_template_paths} = ["$additionalpath"];
25     }
26     if ( $c->request->param('addpath') ){
27         my $additionalpath = Path::Class::dir($c->config->{root}, $c->request->param('addpath'));
28         my $view = 'TestApp::View::TT::' . ($c->request->param('view') || $c->config->{default_view});
29         no strict "refs";
30         push @{$view . '::include_path'}, "$additionalpath";
31         use strict;
32     }
33 }
34
35 sub test_render : Local {
36     my ($self, $c) = @_;
37
38     $c->stash->{message} = eval { $c->view('TT::Appconfig')->render($c, $c->req->param('template'), {param => $c->req->param('param') || ''}) };
39     if (my $err = $@) {
40         $c->response->body($err);
41         $c->response->status(403);
42     } else {
43         $c->stash->{template} = 'test.tt';
44     }
45
46 }
47
48 sub test_msg : Local {
49     my ($self, $c) = @_;
50     my $tmpl = $c->req->param('msg');
51     
52     $c->stash->{message} = $c->view('TT::Appconfig')->render($c, \$tmpl);
53     $c->stash->{template} = 'test.tt';
54 }
55
56 sub end : Private {
57     my ($self, $c) = @_;
58
59     return 1 if $c->response->status =~ /^3\d\d$/;
60     return 1 if $c->response->body;
61
62     my $view = 'View::TT::' . ($c->request->param('view') || $c->config->{default_view});
63     $c->forward($view);
64 }
65
66 1;