[Catalyst-commits] r11724 - in Catalyst-View-Mason/branches/render_die: lib/Catalyst/View t t/lib

theory at dev.catalyst.perl.org theory at dev.catalyst.perl.org
Tue Nov 3 01:07:16 GMT 2009


Author: theory
Date: 2009-11-03 01:07:16 +0000 (Tue, 03 Nov 2009)
New Revision: 11724

Modified:
   Catalyst-View-Mason/branches/render_die/lib/Catalyst/View/Mason.pm
   Catalyst-View-Mason/branches/render_die/t/exception.t
   Catalyst-View-Mason/branches/render_die/t/lib/TestApp.pm
Log:
Changed `render()` to die on exception, rather than return the exception object.

Also changed the name of the attribute in which the Mason interpreter is stored from `template` to `interp`. Too much creeping Template Toolkitism.

I deleted the test that had a non-Mason exception return success. I could see no point in that at all.


Modified: Catalyst-View-Mason/branches/render_die/lib/Catalyst/View/Mason.pm
===================================================================
--- Catalyst-View-Mason/branches/render_die/lib/Catalyst/View/Mason.pm	2009-11-03 00:39:28 UTC (rev 11723)
+++ Catalyst-View-Mason/branches/render_die/lib/Catalyst/View/Mason.pm	2009-11-03 01:07:16 UTC (rev 11724)
@@ -10,7 +10,7 @@
 
 our $VERSION = '0.18';
 
-__PACKAGE__->mk_accessors('template');
+__PACKAGE__->mk_accessors('interp');
 
 =head1 NAME
 
@@ -115,7 +115,7 @@
 EOW
     }
 
-    $self->template(
+    $self->interp(
         HTML::Mason::Interp->new(
             %config,
             out_method => \$self->{output},
@@ -170,11 +170,10 @@
     my ($self, $c) = @_;
 
     my $component_path = $self->get_component_path($c);
-    my $output         = $self->render($c, $component_path);
+    my $output         = eval { $self->render($c, $component_path) };
 
-    if (blessed($output) && $output->isa('HTML::Mason::Exception')) {
-        chomp $output;
-        my $error = qq/Couldn't render component "$component_path" - error was "$output"/;
+    if (my $err = $@) {
+        my $error = qq/Couldn't render component "$component_path" - error was "$err"/;
         $c->log->error($error);
         $c->error($error);
         return 0;
@@ -191,8 +190,8 @@
 
 =head2 render($c, $component_path, \%args)
 
-Renders the given template and returns output, or a HTML::Mason::Exception
-object upon error.
+Renders the given template and returns output. Dies with an
+HTML::Mason::Exception object upon error.
 
 The template variables are set to %$args if $args is a hashref, or
 $c-E<gt>stash otherwise.
@@ -224,22 +223,16 @@
     # $base, $c and $name
     my %default_globals = $self->_default_globals($c);
     while (my ($key, $val) = each %default_globals) {
-        $self->template->set_global($key => $val);
+        $self->interp->set_global($key => $val);
     }
 
     $self->{output} = q//;
 
-    eval {
-        $self->template->exec(
-            $component_path,
-            ref $args eq 'HASH' ? %{ $args } : %{ $c->stash },
-        );
-    };
+    $self->interp->exec(
+        $component_path,
+        ref $args eq 'HASH' ? %{ $args } : %{ $c->stash },
+    );
 
-    if (my $error = $@) {
-        return $error;
-    }
-
     return $self->{output};
 }
 

Modified: Catalyst-View-Mason/branches/render_die/t/exception.t
===================================================================
--- Catalyst-View-Mason/branches/render_die/t/exception.t	2009-11-03 00:39:28 UTC (rev 11723)
+++ Catalyst-View-Mason/branches/render_die/t/exception.t	2009-11-03 01:07:16 UTC (rev 11724)
@@ -2,7 +2,7 @@
 
 use strict;
 use warnings;
-use Test::More tests => 4;
+use Test::More tests => 2;
 
 use FindBin;
 use lib "$FindBin::Bin/lib";
@@ -13,15 +13,3 @@
     my $response = request('/exception');
     ok(!$response->is_success, 'request fails');
 }
-
-SKIP: {
-    eval 'use Test::MockModule';
-    skip 'Test::MockModule required', 2 if $@;
-
-    my $mock = Test::MockModule->new('HTML::Mason::Interp');
-    $mock->mock(exec => sub { die bless \do { my $o }, 'FakeException' });
-
-    my $response = request('/exception');
-    ok($response->is_success, 'request succeeds');
-    like($response->content, qr/^FakeException=/, 'request content contains stringified exception');
-}

Modified: Catalyst-View-Mason/branches/render_die/t/lib/TestApp.pm
===================================================================
--- Catalyst-View-Mason/branches/render_die/t/lib/TestApp.pm	2009-11-03 00:39:28 UTC (rev 11723)
+++ Catalyst-View-Mason/branches/render_die/t/lib/TestApp.pm	2009-11-03 01:07:16 UTC (rev 11724)
@@ -66,16 +66,20 @@
 sub render : Local {
     my ($self, $c) = @_;
 
-    my $out = $self->view->render(
+    my $out = eval {
+        $self->view->render(
             $c, $c->request->param('template'),
             { param => $c->req->param('param') || '' },
-    );
+        )
+    };
 
-    $c->response->body($out);
-
-    if (blessed($out) && $out->isa('HTML::Mason::Exception')) {
+    if (my $err = $@) {
+        $c->response->body($err);
         $c->response->status(403);
     }
+    else {
+        $c->response->body($out);
+    }
 }
 
 sub match : Regex('^match/(\w+)') {




More information about the Catalyst-commits mailing list