7fd2cdcf94ab197a222558b66432e4323b54fdda
[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 our $VERSION = '0.81';
8 $VERSION = eval $VERSION;
9
10 sub execute {
11     my $self = shift;
12     my ( $controller, $c, $view ) = @_;
13
14     my $stash_key = (
15             $controller->{'serialize'} ?
16                 $controller->{'serialize'}->{'stash_key'} :
17                 $controller->{'stash_key'} 
18         ) || 'rest';
19
20     if ( !$c->view($view) ) {
21         $c->log->error("Could not load $view, refusing to serialize");
22         return;
23     }
24
25     if ($c->view($view)->process($c, $stash_key)) {
26       return 1;
27     } else {
28       # This is stupid. Please improve it.
29       my $error = join("\n", @{ $c->error }) || "Error in $view";
30       $error .= "\n";
31       $c->clear_errors;
32       die $error;
33     }
34 }
35
36 1;