r11835@t0mlaptop (orig r11800): t0m | 2009-11-12 00:32:30 +0000
Tomas Doran [Tue, 16 Feb 2010 22:23:03 +0000 (22:23 +0000)]
 Merge miscommit from other branch: svn merge -r 11796:11797 http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-View-TT/branches/render_die

 Original commit:
 Author: osfameron
 Date: 2009-11-11 10:58:24 +0000 (Wed, 11 Nov 2009)
 New Revision: 11797

 Modified:
   Catalyst-View-TT/branches/render_die/lib/Catalyst/View/TT.pm
 Log:
 Clarify docs for 'sub end' to promote RenderView

 (Previously, the docs suggested doing something that would break
 ->res->redirect)
 r12651@t0mlaptop (orig r12616):  t0m | 2010-01-12 02:02:15 +0000
 Show config setting as a method call rather than a hask assignment
 r12932@t0mlaptop (orig r12896):  rafl | 2010-02-16 04:41:34 +0000
 Fix repo url.
 r12933@t0mlaptop (orig r12897):  rafl | 2010-02-16 04:47:19 +0000
 Version 0.32.

Changes
lib/Catalyst/View/TT.pm
t/lib/TestApp/Controller/Root.pm

diff --git a/Changes b/Changes
index 845c2f9..c28bd39 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 Revision history for Perl extension Catalyst::View::TT.
 
+        - The "render()" method now dies on exception, rather than returning
+          the exception object.
+
 0.32    2010-02-16 05:55:00
         - Various documentation improvements.
         - Fix repository metadata.
index 7277ddf..1b561e2 100644 (file)
@@ -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 {
@@ -525,7 +522,7 @@ N.B. This is usually done automatically by L<Catalyst::Action::RenderView>.
 
 =head2 render($c, $template, \%args)
 
-Renders the given template and returns output, or a L<Template::Exception>
+Renders the given template and returns output. Throws a L<Template::Exception>
 object upon error.
 
 The template variables are set to C<%$args> if $args is a hashref, or
index e119a1b..41a0d46 100644 (file)
@@ -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';