add a $VERSION to every module
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Serialize.pm
index 1f6db7d..0ce4558 100644 (file)
@@ -1,18 +1,15 @@
-#
-# Catlyst::Action::Serialize.pm
-# Created by: Adam Jacob, Marchex, <adam@hjksolutions.com>
-#
-# $Id$
-
 package Catalyst::Action::Serialize;
 
-use strict;
-use warnings;
+use Moose;
+use namespace::autoclean;
 
-use base 'Catalyst::Action::SerializeBase';
+extends 'Catalyst::Action::SerializeBase';
 use Module::Pluggable::Object;
 use MRO::Compat;
 
+our $VERSION = '0.81';
+$VERSION = eval $VERSION;
+
 sub execute {
     my $self = shift;
     my ( $controller, $c ) = @_;
@@ -32,7 +29,7 @@ sub execute {
             $c->log->info("Could not find a serializer for $content_type");
         } else {
             $c->log->info(
-                "Could not find a serializer for an empty content type");
+                "Could not find a serializer for an empty content-type");
         }
         return 1;
     }
@@ -40,15 +37,17 @@ sub execute {
         "Serializing with $sclass" . ( $sarg ? " [$sarg]" : '' ) ) if $c->debug;
 
     my $rc;
-    if ( defined($sarg) ) {
-        $rc = $sclass->execute( $controller, $c, $sarg );
-    } else {
-        $rc = $sclass->execute( $controller, $c );
-    }
-    if ( $rc eq 0 ) {
+    eval {
+        if ( defined($sarg) ) {
+            $rc = $sclass->execute( $controller, $c, $sarg );
+        } else {
+            $rc = $sclass->execute( $controller, $c );
+        }
+    };
+    if ($@) {
+        return $self->_serialize_bad_request( $c, $content_type, $@ );
+    } elsif (!$rc) {
         return $self->_unsupported_media_type( $c, $content_type );
-    } elsif ( $rc ne 1 ) {
-        return $self->_serialize_bad_request( $c, $content_type, $rc );
     }
 
     return 1;
@@ -137,15 +136,12 @@ a sensible set of defaults for doing a REST controller.
 
 L<Catalyst::Action::Deserialize>, L<Catalyst::Action::REST>
 
-=head1 AUTHOR
-
-Adam Jacob <adam@stalecoffee.org>, with lots of help from mst and jrockway
+=head1 AUTHORS
 
-Marchex, Inc. paid me while I developed this module.  (http://www.marchex.com)
+See L<Catalyst::Action::REST> for authors.
 
 =head1 LICENSE
 
 You may distribute this code under the same terms as Perl itself.
 
 =cut
-