Commit | Line | Data |
9a76221e |
1 | package Catalyst::Action::Serialize::View; |
930013e6 |
2 | use Moose; |
3 | use namespace::autoclean; |
9a76221e |
4 | |
930013e6 |
5 | extends 'Catalyst::Action'; |
9a76221e |
6 | |
ad46030d |
7 | our $VERSION = '0.86'; |
6edee33e |
8 | $VERSION = eval $VERSION; |
9 | |
9a76221e |
10 | sub execute { |
11 | my $self = shift; |
12 | my ( $controller, $c, $view ) = @_; |
faf5c20b |
13 | |
96eccfeb |
14 | # Views don't care / are not going to render an entity for 3XX |
15 | # responses. |
16 | return 1 if $c->response->status =~ /^(?:204|3\d\d)$/; |
17 | |
faf5c20b |
18 | my $stash_key = ( |
07682cbc |
19 | $controller->{'serialize'} ? |
20 | $controller->{'serialize'}->{'stash_key'} : |
21 | $controller->{'stash_key'} |
faf5c20b |
22 | ) || 'rest'; |
9a76221e |
23 | |
24 | if ( !$c->view($view) ) { |
25 | $c->log->error("Could not load $view, refusing to serialize"); |
58c1c5f5 |
26 | return; |
9a76221e |
27 | } |
28 | |
6d4a379f |
29 | if ($c->view($view)->process($c, $stash_key)) { |
30 | return 1; |
31 | } else { |
32 | # This is stupid. Please improve it. |
33 | my $error = join("\n", @{ $c->error }) || "Error in $view"; |
34 | $error .= "\n"; |
35 | $c->clear_errors; |
36 | die $error; |
37 | } |
9a76221e |
38 | } |
39 | |
40 | 1; |