package TestApp::Controller::Root;
use Moose;
use namespace::autoclean;

BEGIN {
    extends 'Catalyst::Controller';
}

__PACKAGE__->config(namespace => '');

sub test_render
    :Local
{
    my ($self, $c) = @_;

    $c->stash->{message} = eval {
        $c->view('Xslate::Appconfig')->render($c, $c->req->param('template'), {param => $c->req->param('param') || ''})
    };
    if (my $err = $@) {
        $c->response->body($err);
        $c->response->status(403);
    } else {
        $c->stash->{template} = 'test.tx';
    }

}

# XXX From View::TT, but not supported in Xslate
# sub test_msg : Local {
#     my ($self, $c) = @_;
#     my $tmpl = $c->req->param('msg');
# 
#     $c->stash->{message} = $c->view('Xslate::AppConfig')->render($c, $tmpl);
#     $c->stash->{template} = 'test.xt';
# }

sub end 
    :Private
{
    my ($self, $c) = @_;

    return 1 if $c->response->status =~ /^3\d\d$/;
    return 1 if $c->response->body;

    my $view = 'View::Xslate::' . ($c->request->param('view') || $c->config->{default_view});
    $c->forward($view);
}


__PACKAGE__->meta->make_immutable();

1;
