[Catalyst-commits] r6753 - trunk/Catalyst-View-Mason/lib/Catalyst/View

rafl at dev.catalyst.perl.org rafl at dev.catalyst.perl.org
Tue Aug 28 16:58:35 GMT 2007


Author: rafl
Date: 2007-08-28 16:58:35 +0100 (Tue, 28 Aug 2007)
New Revision: 6753

Modified:
   trunk/Catalyst-View-Mason/lib/Catalyst/View/Mason.pm
Log:
Implement a render method.


Modified: trunk/Catalyst-View-Mason/lib/Catalyst/View/Mason.pm
===================================================================
--- trunk/Catalyst-View-Mason/lib/Catalyst/View/Mason.pm	2007-08-28 15:58:31 UTC (rev 6752)
+++ trunk/Catalyst-View-Mason/lib/Catalyst/View/Mason.pm	2007-08-28 15:58:35 UTC (rev 6753)
@@ -2,6 +2,7 @@
 
 use strict;
 use base qw/Catalyst::View/;
+use Scalar::Util qw/blessed/;
 use HTML::Mason;
 use NEXT;
 
@@ -117,6 +118,32 @@
         return 0;
     }
 
+    my $output = $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"/;
+        $c->log->error($error);
+        $c->error($error);
+        return 0;
+    }
+
+    unless ( $c->response->content_type ) {
+        $c->response->content_type('text/html; charset=utf-8');
+    }
+
+    $c->response->body( $output );
+
+    return 1;
+}
+
+=head3 render
+
+=cut
+
+sub render {
+    my ($self, $c, $component_path, $args) = @_;
+
     unless ( $component_path =~ m[^/]o ) {
         $component_path = '/' . $component_path;
     }
@@ -136,25 +163,15 @@
     eval {
         $self->template->exec(
             $component_path,
-            %{ $c->stash },    # pass the stash
+            ref $args eq 'HASH' ? %{ $args } : %{ $c->stash },
         );
     };
 
-    if ( my $error = $@ ) {
-        chomp $error;
-        $error = qq/Couldn't render component "$component_path" - error was "$error"/;
-        $c->log->error($error);
-        $c->error($error);
-        return 0;
+    if (my $error = $@) {
+        return $error;
     }
 
-    unless ( $c->response->content_type ) {
-        $c->response->content_type('text/html; charset=utf-8');
-    }
-
-    $c->response->body( $self->{output} );
-
-    return 1;
+    return $self->{output};
 }
 
 =head3 config




More information about the Catalyst-commits mailing list