Have render() warn on exception, rather than die.
David E. Wheeler [Wed, 10 Mar 2010 18:24:49 +0000 (18:24 +0000)]
This is at mst's request, to minimize backward compatibility issues. To
silence the warning, pass `render_die => 0` to the constructor. Better yet,
pass 'render_die => 1' to make it die instead of returning the excption. This
will be the default in a future release.

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

diff --git a/Changes b/Changes
index c28bd39..9a23c7c 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,7 +1,10 @@
 Revision history for Perl extension Catalyst::View::TT.
 
-        - The "render()" method now dies on exception, rather than returning
-          the exception object.
+        - The "render()" method now throws a warning on exception before
+          returning the exception. To silence the warning, pass 'render_die =>
+          0' to the constructor. Better yet, pass 'render_die => 1' to make it
+          die instead of returning the excption. This will be the default in a
+          future release.
 
 0.32    2010-02-16 05:55:00
         - Various documentation improvements.
index 0426b93..fd9205b 100644 (file)
@@ -241,8 +241,15 @@ sub render {
         [ @{ $vars->{additional_template_paths} }, @{ $self->{include_path} } ]
         if ref $vars->{additional_template_paths};
 
-    $self->template->process( $template, $vars, \$output )
-        or die $self->template->error;
+    unless ( $self->template->process( $template, $vars, \$output ) ) {
+        if (exists $self->{render_die}) {
+            die $self->template->error if $self->{render_die};
+            return $self->template->error;
+        }
+        require Carp;
+        Carp::carp('The Catalyst::View::TT render() method of will die on error in a future release. If you want it to continue to return the exception instead, pass render_die => 0 to the constructor');
+        return $self->template->error;
+    }
     return $output;
 }
 
index 97bf8f0..399f813 100755 (executable)
@@ -16,6 +16,7 @@ __PACKAGE__->config(
         PRE_CHOMP          => 1,
         POST_CHOMP         => 1,
         TEMPLATE_EXTENSION => '.tt',
+        render_die         => 1,
     },
 );