File Coverage

lib/Catalyst/Action/Serialize/View.pm
Criterion Covered Total %
statement 17 19 89.4
branch 4 6 66.6
condition 2 5 40.0
subroutine 3 3 100.0
pod 1 1 100.0
total 27 34 79.4


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