X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FAction%2FSerialize%2FView.pm;h=4f73989ffc49ae35c06cc6a8558ee54c2d011a27;hb=0a6732c935e687213c53f013d925f35083f8c592;hp=6379fa3ef98bee9ffe7de59c81b4a71438784308;hpb=3d8a0645a8c77bb59d727b4357b9142c7f66016a;p=catagits%2FCatalyst-Action-REST.git diff --git a/lib/Catalyst/Action/Serialize/View.pm b/lib/Catalyst/Action/Serialize/View.pm index 6379fa3..4f73989 100644 --- a/lib/Catalyst/Action/Serialize/View.pm +++ b/lib/Catalyst/Action/Serialize/View.pm @@ -1,13 +1,20 @@ package Catalyst::Action::Serialize::View; -use strict; -use warnings; +use Moose; +use namespace::autoclean; -use base 'Catalyst::Action'; +extends 'Catalyst::Action'; + +our $VERSION = '1.05'; +$VERSION = eval $VERSION; sub execute { my $self = shift; my ( $controller, $c, $view ) = @_; + # Views don't care / are not going to render an entity for 3XX + # responses. + return 1 if $c->response->status =~ /^(?:204|3\d\d)$/; + my $stash_key = ( $controller->{'serialize'} ? $controller->{'serialize'}->{'stash_key'} : @@ -16,10 +23,20 @@ sub execute { if ( !$c->view($view) ) { $c->log->error("Could not load $view, refusing to serialize"); - return 0; + return; } - return $c->view($view)->process($c, $stash_key); + if ($c->view($view)->process($c, $stash_key)) { + return 1; + } else { + # This is stupid. Please improve it. + my $error = join("\n", @{ $c->error }) || "Error in $view"; + $error .= "\n"; + $c->clear_errors; + die $error; + } } +__PACKAGE__->meta->make_immutable; + 1;