Hi all catalyst/mason users.

This patch implements the ->render method on Catalyst::View::Mason (should
work the excact same way as ->render on Catalyst::View::TT)

 my $doc = $c->view("Mason")->render($c,"/path/to/template",{arg => value});


Jesper

-- 
Jesper Krogh
--- /usr/share/perl5/Catalyst/View/Mason.pm	2005-11-09 16:14:58.000000000 +0100
+++ lib/Catalyst/View/Mason.pm	2006-09-27 14:51:51.000000000 +0200
@@ -122,7 +122,31 @@
         $component_path = '/' . $component_path;
     }
 
-    $c->log->debug(qq/Rendering component "$component_path"/) if $c->debug;
+    my $doc = $self->render($c,$component_path);
+        unless ( $c->response->content_type ) {
+        $c->response->content_type('text/html;charset=utf8');
+    }
+
+    $c->response->body($doc);
+
+    return 1;
+}
+
+=head3 render($c,$template,\%args)
+
+This method is "inspired" from Catalyst::View::TT it allows to render a 
+template at get it back into Catalyst. If %args isn't supplied 
+the $c->stash is used instead. 
+
+
+    my $doc = $c->view("Mason")->render($c,"/path/to/template",{data => "value"});
+
+=cut
+
+sub render {
+    my ($self, $c, $template, $args) = @_;
+
+    $c->log->debug(qq/Rendering template "$template"/) if $c->debug;
 
     # Set the URL base, context and name of the app as global Mason vars
     # $base, $c and $name
@@ -136,28 +160,20 @@
 
     eval {
         $self->template->exec(
-            $component_path,
-            %{ $c->stash },    # pass the stash
+            $template,
+            %{ $args || $c->stash },    # pass the stash
         );
     };
 
     if ( my $error = $@ ) {
         chomp $error;
-        $error = qq/Couldn't render component "$component_path" - error was "$error"/;
+        $error = qq/Couldn't render component "$template" - error was "$error"/;
         $c->log->error($error);
         $c->error($error);
         return 0;
     }
-
-    unless ( $c->response->content_type ) {
-        $c->response->content_type('text/html;charset=utf8');
-    }
-
-    $c->response->body( $self->{output} );
-
-    return 1;
+    return $self->{output};
 }
-
 =head3 config
 
 This allows your view subclass to pass additional settings to the
_______________________________________________
List: Catalyst@lists.rawmode.org
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
Dev site: http://dev.catalyst.perl.org/

Reply via email to