X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FAction%2FSerialize.pm;h=cc1f83893e200d34fb8dd19ea68121c81c7ac26b;hb=05009b91e5e1729a5dc81af102e13823ce89f0d6;hp=31597cf0b036e3e40e992f733a147169e8ae1e9b;hpb=de1fb650378975cfcafe60e7b9a031825df7392e;p=catagits%2FCatalyst-Action-REST.git diff --git a/lib/Catalyst/Action/Serialize.pm b/lib/Catalyst/Action/Serialize.pm index 31597cf..cc1f838 100644 --- a/lib/Catalyst/Action/Serialize.pm +++ b/lib/Catalyst/Action/Serialize.pm @@ -1,22 +1,20 @@ -# -# Catlyst::Action::Serialize.pm -# Created by: Adam Jacob, Marchex, -# -# $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 ) = @_; - $self->NEXT::execute(@_); + $self->maybe::next::method(@_); return 1 if $c->req->method eq 'HEAD'; return 1 if length( $c->response->body ); @@ -31,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; } @@ -39,21 +37,23 @@ 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; } -1; +__PACKAGE__->meta->make_immutable; =head1 NAME @@ -136,15 +136,12 @@ a sensible set of defaults for doing a REST controller. L, L -=head1 AUTHOR - -Adam Jacob , 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 for authors. =head1 LICENSE You may distribute this code under the same terms as Perl itself. =cut -