[Catalyst-commits] r13041 - in Catalyst-View-TT/trunk: . lib/Catalyst/Helper/View lib/Catalyst/View t/lib t/lib/TestApp/Controller

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Wed Mar 10 20:05:23 GMT 2010


Author: t0m
Date: 2010-03-10 20:05:23 +0000 (Wed, 10 Mar 2010)
New Revision: 13041

Modified:
   Catalyst-View-TT/trunk/
   Catalyst-View-TT/trunk/Changes
   Catalyst-View-TT/trunk/lib/Catalyst/Helper/View/TT.pm
   Catalyst-View-TT/trunk/lib/Catalyst/View/TT.pm
   Catalyst-View-TT/trunk/t/lib/TestApp.pm
   Catalyst-View-TT/trunk/t/lib/TestApp/Controller/Root.pm
Log:
 r11755 at t0mlaptop (orig r11720):  theory | 2009-11-03 00:23:43 +0000
 Branch Catalyst::View::TT to make `render()` die instead of return an exception object.
 r11756 at t0mlaptop (orig r11721):  theory | 2009-11-03 00:37:04 +0000
 Have `render()` die on exception, not return an exception object.
 r11832 at t0mlaptop (orig r11797):  osfameron | 2009-11-11 10:58:24 +0000
 Clarify docs for 'sub end' to promote RenderView
 
 (Previously, the docs suggested doing something that would break
 $c->res->redirect)
 r11834 at t0mlaptop (orig r11799):  t0m | 2009-11-12 00:31:26 +0000
 Back out 11797 - misscommit to wrong branch. svn merge -r11797:11796 .
 r12947 at t0mlaptop (orig r12911):  t0m | 2010-02-16 22:37:01 +0000
 Localise execeptions
 r13074 at t0mlaptop (orig r13038):  theory | 2010-03-10 18:24:49 +0000
 Have render() warn on exception, rather than die.
 
 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.
 
 
 r13075 at t0mlaptop (orig r13039):  t0m | 2010-03-10 20:02:47 +0000
 Document setting, make skeleton generate it by default
 r13076 at t0mlaptop (orig r13040):  t0m | 2010-03-10 20:04:57 +0000
 Bump versions



Property changes on: Catalyst-View-TT/trunk
___________________________________________________________________
Added: svk:merge
   + 4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-View-TT/branches/render_die:13040
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst-View-TT:10559

Modified: Catalyst-View-TT/trunk/Changes
===================================================================
--- Catalyst-View-TT/trunk/Changes	2010-03-10 20:04:57 UTC (rev 13040)
+++ Catalyst-View-TT/trunk/Changes	2010-03-10 20:05:23 UTC (rev 13041)
@@ -1,5 +1,13 @@
 Revision history for Perl extension Catalyst::View::TT.
 
+0.33   2010-03-10 20:08:00
+        - 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 when unspecified. The Helper will generate new views
+          with render_die => 1.
+
 0.32    2010-02-16 05:55:00
         - Various documentation improvements.
         - Fix repository metadata.

Modified: Catalyst-View-TT/trunk/lib/Catalyst/Helper/View/TT.pm
===================================================================
--- Catalyst-View-TT/trunk/lib/Catalyst/Helper/View/TT.pm	2010-03-10 20:04:57 UTC (rev 13040)
+++ Catalyst-View-TT/trunk/lib/Catalyst/Helper/View/TT.pm	2010-03-10 20:05:23 UTC (rev 13041)
@@ -55,7 +55,10 @@
 
 use base 'Catalyst::View::TT';
 
-__PACKAGE__->config(TEMPLATE_EXTENSION => '.tt');
+__PACKAGE__->config(
+    TEMPLATE_EXTENSION => '.tt',
+    render_die => 1,
+);
 
 =head1 NAME
 

Modified: Catalyst-View-TT/trunk/lib/Catalyst/View/TT.pm
===================================================================
--- Catalyst-View-TT/trunk/lib/Catalyst/View/TT.pm	2010-03-10 20:04:57 UTC (rev 13040)
+++ Catalyst-View-TT/trunk/lib/Catalyst/View/TT.pm	2010-03-10 20:05:23 UTC (rev 13041)
@@ -9,7 +9,7 @@
 use Template::Timer;
 use MRO::Compat;
 
-our $VERSION = '0.32';
+our $VERSION = '0.33';
 
 __PACKAGE__->mk_accessors('template');
 __PACKAGE__->mk_accessors('include_path');
@@ -43,6 +43,7 @@
             # Not set by default
             PRE_PROCESS        => 'config/main',
             WRAPPER            => 'site/wrapper',
+            render_die => 1, # Default for new apps, see render method docs
         },
     );
 
@@ -168,6 +169,7 @@
                                    @{ $p->{copy_config} };
                     }
                 }
+                local $@;
                 eval "require $prov";
                 if(!$@) {
                     push @providers, "$prov"->new($p->{args});
@@ -207,10 +209,10 @@
         return 0;
     }
 
-    my $output = $self->render($c, $template);
-
-    if (UNIVERSAL::isa($output, 'Template::Exception')) {
-        my $error = qq/Couldn't render template "$output"/;
+    local $@;
+    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 +242,16 @@
         [ @{ $vars->{additional_template_paths} }, @{ $self->{include_path} } ]
         if ref $vars->{additional_template_paths};
 
-    unless ($self->template->process( $template, $vars, \$output ) ) {
+    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;
-    } else {
-        return $output;
     }
+    return $output;
 }
 
 sub template_vars {
@@ -525,7 +532,7 @@
 
 =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
@@ -548,6 +555,22 @@
 
     my $fragment = $c->forward("View::TT", "render", $template_name, $c->stash->{fragment_data});
 
+=head3 Backwards compatibility note
+
+The render method used to just return the Template::Exception object, rather
+than just throwing it. This is now deprecated and instead the render method
+will throw an exception for new applications.
+
+This behaviour can be activated (and is activated in the default skeleton
+configuration) by using C<< render_die => 1 >>. If you rely on the legacy
+behaviour then a warning will be issued.
+
+To silence this warning, set C<< render_die => 0 >>, but it is recommended
+you adjust your code so that it works with C<< render_die => 1 >>.
+
+In a future release, C<< render_die => 1 >> will become the default if
+unspecified.
+
 =head2 template_vars
 
 Returns a list of keys/values to be used as the catalyst variables in the

Modified: Catalyst-View-TT/trunk/t/lib/TestApp/Controller/Root.pm
===================================================================
--- Catalyst-View-TT/trunk/t/lib/TestApp/Controller/Root.pm	2010-03-10 20:04:57 UTC (rev 13040)
+++ Catalyst-View-TT/trunk/t/lib/TestApp/Controller/Root.pm	2010-03-10 20:05:23 UTC (rev 13041)
@@ -34,9 +34,9 @@
 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';

Modified: Catalyst-View-TT/trunk/t/lib/TestApp.pm
===================================================================
--- Catalyst-View-TT/trunk/t/lib/TestApp.pm	2010-03-10 20:04:57 UTC (rev 13040)
+++ Catalyst-View-TT/trunk/t/lib/TestApp.pm	2010-03-10 20:05:23 UTC (rev 13041)
@@ -16,6 +16,7 @@
         PRE_CHOMP          => 1,
         POST_CHOMP         => 1,
         TEMPLATE_EXTENSION => '.tt',
+        render_die         => 1,
     },
 );
 




More information about the Catalyst-commits mailing list