X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FAction%2FSerialize%2FView.pm;h=227898b41f6701c685e6c721ead74e727de5ece7;hb=5cb0b36f518a1f5e9c2225eec3187416319e8eec;hp=630a4e7f4a418dbb05adf68b2769b74bca30db35;hpb=07682cbc3e3c974a32b52eec5cc8c7035a5c12ed;p=catagits%2FCatalyst-Action-REST.git diff --git a/lib/Catalyst/Action/Serialize/View.pm b/lib/Catalyst/Action/Serialize/View.pm index 630a4e7..227898b 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.11'; +$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); + 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;