X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FAction%2FSerialize.pm;h=057cc39e1d20bcbcee145277669431deecf36163;hb=b74200b31daa4a059b0f1555f2d9e079f35d08ff;hp=82ecb42b46be36128014348a7f1c26e26d8ff74d;hpb=cc188065d548c2c53c22000871a7d6dfab5c3c69;p=catagits%2FCatalyst-Action-REST.git diff --git a/lib/Catalyst/Action/Serialize.pm b/lib/Catalyst/Action/Serialize.pm index 82ecb42..057cc39 100644 --- a/lib/Catalyst/Action/Serialize.pm +++ b/lib/Catalyst/Action/Serialize.pm @@ -7,8 +7,6 @@ extends 'Catalyst::Action::SerializeBase'; use Module::Pluggable::Object; use MRO::Compat; -# VERSION - has _encoders => ( is => 'ro', isa => 'HashRef', @@ -28,6 +26,15 @@ sub execute { return 1 if defined $c->stash->{current_view}; return 1 if defined $c->stash->{current_view_instance}; + # on 3xx responses, serialize if there's something to + # serialize, no-op if not + my $stash_key = ( + $controller->{'serialize'} ? + $controller->{'serialize'}->{'stash_key'} : + $controller->{'stash_key'} + ) || 'rest'; + return 1 if $c->response->status =~ /^(?:3\d\d)$/ && ! defined $c->stash->{$stash_key}; + my ( $sclass, $sarg, $content_type ) = $self->_load_content_plugins( "Catalyst::Action::Serialize", $controller, $c ); @@ -145,7 +152,7 @@ with the rest of Catalyst. For building custom error responses when serialization fails, you can create an ActionRole (and use L to apply it to the -C action) which overrides C and/or C<_serialize_bad_request> +C action) which overrides C and/or C methods. =head1 SEE ALSO