Catalyst::Action::Serialize::View uses the calculated $stash_key; amended C::C::REST...
Dan Dascalescu [Thu, 10 Dec 2009 03:38:32 +0000 (19:38 -0800)]
lib/Catalyst/Action/Serialize/View.pm
lib/Catalyst/Controller/REST.pm

index 630a4e7..6379fa3 100644 (file)
@@ -19,7 +19,7 @@ sub execute {
         return 0;
     }
 
-    return $c->view($view)->process($c);
+    return $c->view($view)->process($c, $stash_key);
 }
 
 1;
index 2cd5f47..22a5fe9 100644 (file)
@@ -174,12 +174,38 @@ you serialize be a HASHREF, we transform outgoing data to be in the form of:
 =item * L<View>
 
 Uses a regular Catalyst view.  For example, if you wanted to have your
-C<text/html> and C<text/xml> views rendered by TT:
+C<text/html> and C<text/xml> views rendered by TT, set:
 
-  'text/html' => [ 'View', 'TT' ],
-  'text/xml'  => [ 'View', 'XML' ],
-
-Will do the trick nicely.
+  __PACKAGE__->config(
+      map => {
+          'text/html' => [ 'View', 'TT' ],
+          'text/xml'  => [ 'View', 'XML' ],
+      }
+  );    
+
+Your views should have a C<process> method like this:
+
+  sub process {
+      my ( $self, $c, $stash_key ) = @_;
+      
+      my $output;
+      eval {
+          $output = $self->serialize( $c->stash->{$stash_key} );
+      };
+      return $@ if $@;
+      
+      $c->response->body( $output );
+      return 1;  # important
+  }
+  
+  sub serialize {
+      my ( $self, $data ) = @_;
+  
+      my $serialized = ... process $data here ...
+      
+      return $serialized;
+  }
+  
 
 =back