remove hardcoded version strings
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Serialize / View.pm
1 package Catalyst::Action::Serialize::View;
2 use Moose;
3 use namespace::autoclean;
4
5 extends 'Catalyst::Action';
6
7 # VERSION
8
9 sub execute {
10     my $self = shift;
11     my ( $controller, $c, $view ) = @_;
12
13     # Views don't care / are not going to render an entity for 3XX
14     # responses.
15     return 1 if $c->response->status =~ /^(?:204|3\d\d)$/;
16
17     my $stash_key = (
18             $controller->{'serialize'} ?
19                 $controller->{'serialize'}->{'stash_key'} :
20                 $controller->{'stash_key'} 
21         ) || 'rest';
22
23     if ( !$c->view($view) ) {
24         $c->log->error("Could not load $view, refusing to serialize");
25         return;
26     }
27
28     if ($c->view($view)->process($c, $stash_key)) {
29       return 1;
30     } else {
31       # This is stupid. Please improve it.
32       my $error = join("\n", @{ $c->error }) || "Error in $view";
33       $error .= "\n";
34       $c->clear_errors;
35       die $error;
36     }
37 }
38
39 __PACKAGE__->meta->make_immutable;
40
41 1;