new config attr that lets you override the default content type
[catagits/Catalyst-View-TT.git] / t / lib / TestApp / Controller / Root.pm
CommitLineData
a18b1fe6 1package TestApp::Controller::Root;
2use base 'Catalyst::Controller';
3__PACKAGE__->config(namespace => '');
4
5sub default : Private {
6 my ($self, $c) = @_;
7
8 $c->response->redirect($c->uri_for('test'));
9}
10
11sub test : Local {
12 my ($self, $c) = @_;
13
14 $c->stash->{message} = ($c->request->param('message') || $c->config->{default_message});
a6fa99df 15 $c->stash->{template} = $c->request->param('template');
a18b1fe6 16}
17
18sub 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
35sub test_render : Local {
36 my ($self, $c) = @_;
37
cad820fe 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);
a18b1fe6 41 $c->response->status(403);
42 } else {
43 $c->stash->{template} = 'test.tt';
44 }
45
46}
47
48sub test_msg : Local {
49 my ($self, $c) = @_;
50 my $tmpl = $c->req->param('msg');
e47ed760 51
9ab4951c 52 $c->stash->{message} = $c->view('TT::Appconfig')->render($c, \$tmpl);
a18b1fe6 53 $c->stash->{template} = 'test.tt';
54}
55
59a2e92a 56sub test_alt_content_type : Local {
57 my ($self, $c) = @_;
58 $c->stash( message => 'test_alt_content_type');
59 $c->forward('View::TT::AltContentType');
60}
61
a18b1fe6 62sub end : Private {
63 my ($self, $c) = @_;
64
65 return 1 if $c->response->status =~ /^3\d\d$/;
66 return 1 if $c->response->body;
67
68 my $view = 'View::TT::' . ($c->request->param('view') || $c->config->{default_view});
69 $c->forward($view);
70}
71
721;