[Catalyst-commits] r11700 - in Catalyst-View-TD/trunk: lib/Catalyst/View t t/lib/TestApp/Controller t/lib/TestApp/TD

theory at dev.catalyst.perl.org theory at dev.catalyst.perl.org
Sat Oct 31 20:43:45 GMT 2009


Author: theory
Date: 2009-10-31 20:43:44 +0000 (Sat, 31 Oct 2009)
New Revision: 11700

Modified:
   Catalyst-View-TD/trunk/lib/Catalyst/View/TD.pm
   Catalyst-View-TD/trunk/t/07render.t
   Catalyst-View-TD/trunk/t/lib/TestApp/Controller/Root.pm
   Catalyst-View-TD/trunk/t/lib/TestApp/TD/Appconfig.pm
Log:
Make render() die on failure instead of returning a reference to a string with an error message in it.

Modified: Catalyst-View-TD/trunk/lib/Catalyst/View/TD.pm
===================================================================
--- Catalyst-View-TD/trunk/lib/Catalyst/View/TD.pm	2009-10-31 19:01:25 UTC (rev 11699)
+++ Catalyst-View-TD/trunk/lib/Catalyst/View/TD.pm	2009-10-31 20:43:44 UTC (rev 11700)
@@ -124,7 +124,7 @@
 
     my $output = eval { $self->render($c, $template) };
 
-    if (my $error = $@ ? $@ : ref $output ? $$output : undef) {
+    if (my $error = $@) {
         my $error = qq/Couldn't render template: "$error"/;
         $c->log->error($error);
         $c->error($error);
@@ -170,12 +170,7 @@
 
     Template::Declare->init( %{ $init }, dispatch_to => $self->dispatch_to );
     Template::Declare::Catalyst->context($c);
-    my $output = eval { Template::Declare->show($template, $vars) };
-    if (my $err = $@) {
-        return $err if ref $err;
-        die $$err;
-    }
-    return $output;
+    return Template::Declare->show($template, $vars);
 }
 
 package Template::Declare::Catalyst;
@@ -188,13 +183,6 @@
 
 *c = \&context;
 
-# XXX Not sure if this is the best way to do things.
-TAGS: {
-    use Template::Declare::Tags ();
-    no warnings 'redefine';
-    *Template::Declare::Tags::carp = sub { die \join '', @_ };
-}
-
 1;
 __END__
 
@@ -603,18 +591,21 @@
 
 =head3 C<process>
 
+  $view->process($c);
+
 Renders the template specified in C<< $c->stash->{template} >> or
 C<< $c->action >> (the private name of the matched action). Calls L<render()>
 to perform actual rendering. Output is stored in C<< $c->response->body >>.
 
 =head3 C<render>
 
-Renders the given template and returns output, or a L<Template::Exception>
-object upon error.
+  my $output = $view->render( $c, $template_name, $args );
 
-The template variables are set to C<$args> if $args is a hashref, or
-C<< $c->stash >> otherwise.
+Renders the given template and returns output. Dies on error.
 
+If C<$args> is a hash reference, it will be passed to the template. Otherwise,
+C<< $c->stash >> will be passed if C<$c> is defined.
+
 =head3 C<config>
 
 This method allows your view subclass to pass additional settings to the TD

Modified: Catalyst-View-TD/trunk/t/07render.t
===================================================================
--- Catalyst-View-TD/trunk/t/07render.t	2009-10-31 19:01:25 UTC (rev 11699)
+++ Catalyst-View-TD/trunk/t/07render.t	2009-10-31 20:43:44 UTC (rev 11700)
@@ -16,7 +16,7 @@
 # ok(($response = request("/test_msg?msg=$message"))->is_success, 'request ok');
 # is($response->content, "$message", 'message ok');
 
-$response = request("/test_render?template=non_existant_template");
+$response = request("/test_render?template=omgwtf");
 
-is (403, $response->code, 'request returned error');
-is($response->content, q{The template 'non_existant_template' could not be found (it might be private)}, 'Error from non-existant-template');
+is ($response->code, 403, 'request returned error');
+like($response->content, qr{OMGWTF!}, 'Error from dieing template');

Modified: Catalyst-View-TD/trunk/t/lib/TestApp/Controller/Root.pm
===================================================================
--- Catalyst-View-TD/trunk/t/lib/TestApp/Controller/Root.pm	2009-10-31 19:01:25 UTC (rev 11699)
+++ Catalyst-View-TD/trunk/t/lib/TestApp/Controller/Root.pm	2009-10-31 20:43:44 UTC (rev 11700)
@@ -50,11 +50,15 @@
 sub test_render : Local {
     my ($self, $c) = @_;
 
-    my $out = $c->stash->{message} = $c->view('Appconfig')->render(
-        $c, $c->req->param('template'), {param => $c->req->param('param') || ''}
-    );
-    if (ref $out) {
-        $c->response->body($$out);
+    my $out = eval {
+        $c->stash->{message} = $c->view('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';

Modified: Catalyst-View-TD/trunk/t/lib/TestApp/TD/Appconfig.pm
===================================================================
--- Catalyst-View-TD/trunk/t/lib/TestApp/TD/Appconfig.pm	2009-10-31 19:01:25 UTC (rev 11699)
+++ Catalyst-View-TD/trunk/t/lib/TestApp/TD/Appconfig.pm	2009-10-31 20:43:44 UTC (rev 11700)
@@ -25,4 +25,8 @@
     outs "Self is $args->{what}" if $self->isa($args->{what});
 };
 
+template omgwtf => sub {
+    die 'OMGWTF!';
+};
+
 1;




More information about the Catalyst-commits mailing list