fix dynamic include bugs.
[catagits/Catalyst-View-TT.git] / t / lib / TestApp.pm
1 package TestApp;
2
3 use strict;
4 use warnings;
5
6 use Catalyst; # qw/-Debug/;
7 use Path::Class;
8
9 our $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
24 sub default : Private {
25     my ($self, $c) = @_;
26
27     $c->response->redirect($c->uri_for('test'));
28 }
29
30 sub test : Local {
31     my ($self, $c) = @_;
32
33     $c->stash->{message} = ($c->request->param('message') || $c->config->{default_message});
34 }
35
36 sub 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     }
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     }
51 }
52
53 sub end : Private {
54     my ($self, $c) = @_;
55
56     return 1 if $c->response->status =~ /^3\d\d$/;
57     return 1 if $c->response->body;
58
59     my $view = 'View::TT::' . ($c->request->param('view') || $c->config->{default_view});
60     $c->forward($view);
61 }
62
63 1;