bfd216dcef247ab9690362c806174b7bb58b76a5
[catagits/Catalyst-View-TT.git] / trunk / 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 test_render : Local {
54     my ($self, $c) = @_;
55
56     my $out = $c->stash->{message} = $c->view('TT::Appconfig')->render($c, $c->req->param('template'), {param => $c->req->param('param') || ''});
57     if (UNIVERSAL::isa($out, 'Template::Exception')) {
58         $c->response->body($out);
59         $c->response->status(403);
60     } else {
61         $c->stash->{template} = 'test.tt';
62     }
63
64 }
65
66 sub test_msg : Local {
67     my ($self, $c) = @_;
68     my $tmpl = $c->req->param('msg');
69     
70     $c->stash->{message} = $c->view('TT::AppConfig')->render($c, \$tmpl);
71     $c->stash->{template} = 'test.tt';
72 }
73
74 sub end : Private {
75     my ($self, $c) = @_;
76
77     return 1 if $c->response->status =~ /^3\d\d$/;
78     return 1 if $c->response->body;
79
80     my $view = 'View::TT::' . ($c->request->param('view') || $c->config->{default_view});
81     $c->forward($view);
82 }
83
84 1;