From: David E. Wheeler Date: Tue, 3 Nov 2009 00:37:04 +0000 (+0000) Subject: Have `render()` die on exception, not return an exception object. X-Git-Tag: v0.33^2~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-View-TT.git;a=commitdiff_plain;h=cad820fef1b09b7c8541b85555ff1accdd5dda9c Have `render()` die on exception, not return an exception object. --- diff --git a/Changes b/Changes index 36e3256..f6a91bb 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for Perl extension Catalyst::View::TT. +0.32 + - The "render()" method now dies on exception, rather than returning + the exception object. + 0.31 2009-10-29 19:26:00 - Moved the test actions to their own controller file to silence warning about actions in the app class being deprecated. diff --git a/lib/Catalyst/View/TT.pm b/lib/Catalyst/View/TT.pm index d07faba..0be7d30 100644 --- a/lib/Catalyst/View/TT.pm +++ b/lib/Catalyst/View/TT.pm @@ -207,10 +207,9 @@ sub process { return 0; } - my $output = $self->render($c, $template); - - if (UNIVERSAL::isa($output, 'Template::Exception')) { - my $error = qq/Couldn't render template "$output"/; + my $output = eval { $self->render($c, $template) }; + if (my $err = $@) { + my $error = qq/Couldn't render template "$template"/; $c->log->error($error); $c->error($error); return 0; @@ -240,11 +239,9 @@ sub render { [ @{ $vars->{additional_template_paths} }, @{ $self->{include_path} } ] if ref $vars->{additional_template_paths}; - unless ($self->template->process( $template, $vars, \$output ) ) { - return $self->template->error; - } else { - return $output; - } + $self->template->process( $template, $vars, \$output ) + or die $self->template->error; + return $output; } sub template_vars { @@ -493,7 +490,7 @@ N.B. This is usually done automatically by L. =head2 render($c, $template, \%args) -Renders the given template and returns output, or a L +Renders the given template and returns output. Throws a L object upon error. The template variables are set to C<%$args> if $args is a hashref, or diff --git a/t/lib/TestApp/Controller/Root.pm b/t/lib/TestApp/Controller/Root.pm index e119a1b..41a0d46 100644 --- a/t/lib/TestApp/Controller/Root.pm +++ b/t/lib/TestApp/Controller/Root.pm @@ -34,9 +34,9 @@ sub test_includepath : Local { sub test_render : Local { my ($self, $c) = @_; - my $out = $c->stash->{message} = $c->view('TT::Appconfig')->render($c, $c->req->param('template'), {param => $c->req->param('param') || ''}); - if (UNIVERSAL::isa($out, 'Template::Exception')) { - $c->response->body($out); + $c->stash->{message} = eval { $c->view('TT::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.tt';