More precise error messages that 'serialize' is a deprecated configuration key. POD...
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Controller / REST.pm
index 2cd5f47..33eb25b 100644 (file)
@@ -83,6 +83,12 @@ Or if you use pre-Moose Catalyst versions,
   use parent 'Catalyst::Controller::REST';
 
 
+=head1 CONFIGURATION
+
+See L<Catalyst::Action::Serialize/CONFIGURATION>. Note that the C<serialize>
+key has been deprecated.
+
+
 =head1 SERIALIZATION
 
 Catalyst::Controller::REST will automatically serialize your
@@ -174,12 +180,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:
-
-  'text/html' => [ 'View', 'TT' ],
-  'text/xml'  => [ 'View', 'XML' ],
+C<text/html> and C<text/xml> views rendered by TT, set:
 
-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