Refactored the Content-Type negotiation to live in Catalyst::Request::REST.(drolsky)
[catagits/Catalyst-Action-Serialize-Data-Serializer.git] / lib / Catalyst / Action / Serialize.pm
index 0ccc077..2ec7add 100644 (file)
@@ -17,19 +17,27 @@ sub execute {
     my $self = shift;
     my ( $controller, $c ) = @_;
 
-    $self->NEXT::execute( @_ );
+    $self->NEXT::execute(@_);
 
     return 1 if $c->req->method eq 'HEAD';
     return 1 if length( $c->response->body );
     return 1 if scalar @{ $c->error };
     return 1 if $c->response->status =~ /^(?:204|3\d\d)$/;
 
-    my ($sclass, $sarg, $content_type) = $self->_load_content_plugins("Catalyst::Action::Serialize", $controller, $c);
+    my ( $sclass, $sarg, $content_type ) =
+      $self->_load_content_plugins( "Catalyst::Action::Serialize",
+        $controller, $c );
     unless ( defined($sclass) ) {
-        $c->log->debug("Could not find a serializer for $content_type");
+        if ( defined($content_type) ) {
+            $c->log->debug("Could not find a serializer for $content_type");
+        } else {
+            $c->log->debug(
+                "Could not find a serializer for an empty content type");
+        }
         return 1;
     }
-    $c->log->debug("Serializing with $sclass" . ($sarg ? " [$sarg]" : ''));
+    $c->log->debug(
+        "Serializing with $sclass" . ( $sarg ? " [$sarg]" : '' ) );
 
     my $rc;
     if ( defined($sarg) ) {
@@ -37,11 +45,11 @@ sub execute {
     } else {
         $rc = $sclass->execute( $controller, $c );
     }
-    if ($rc eq 0) {
-        return $self->_unsupported_media_type($c, $content_type);
-    } elsif ($rc ne 1) {
-        return $self->_serialize_bad_request($c, $content_type, $rc);
-    } 
+    if ( $rc eq 0 ) {
+        return $self->_unsupported_media_type( $c, $content_type );
+    } elsif ( $rc ne 1 ) {
+        return $self->_serialize_bad_request( $c, $content_type, $rc );
+    }
 
     return 1;
 }
@@ -61,6 +69,7 @@ Catalyst::Action::Serialize - Serialize Data in a Response
             'default'   => 'YAML',
             'stash_key' => 'rest',
             'map'       => {
+                               'text/html'          => [ 'View', 'TT', ],
                 'text/x-yaml'        => 'YAML',
                 'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
             },
@@ -88,6 +97,9 @@ nothing is stopping you from choosing specific methods to Serialize:
      .. populate stash with data ..
   }
 
+When you use this module, the request class will be changed to
+L<Catalyst::Request::REST>.
+
 =head1 CONFIGURATION
 
 =over 4
@@ -135,3 +147,4 @@ Marchex, Inc. paid me while I developed this module.  (http://www.marchex.com)
 You may distribute this code under the same terms as Perl itself.
 
 =cut
+