File Coverage

lib/CatalystX/Eta/Controller/AutoResultPUT.pm
Criterion Covered Total %
statement 18 19 94.7
branch 3 6 50.0
condition 2 5 40.0
subroutine 2 2 100.0
pod n/a
total 25 32 78.1


line stmt bran cond sub pod time code
1             package CatalystX::Eta::Controller::AutoResultPUT;
2              
3 2     2   1330 use Moose::Role;
  2         5  
  2         14  
4             requires 'result_PUT';
5              
6             around result_PUT => \&AutoResult_around_result_PUT;
7              
8             sub AutoResult_around_result_PUT {
9 1     1   7 my $orig = shift;
10 1         4 my $self = shift;
11 1         2 my ($c) = @_;
12              
13 1         5 my $something = $c->stash->{ $self->config->{object_key} };
14              
15 1 50       146 my $data_from = $self->config->{data_from_body} ? 'data' : 'params';
16              
17 1         57 my $params = { %{ $c->req->$data_from } };
  1         5  
18 1 50 33     111 if ( exists $self->config->{prepare_params_for_update}
19             && ref $self->config->{prepare_params_for_update} eq 'CODE' ) {
20 0         0 $params = $self->config->{prepare_params_for_update}->( $self, $c, $params );
21             }
22              
23             $something = $something->execute(
24             $c,
25 1 50       63 for => ( exists $c->stash->{result_put_for} ? $c->stash->{result_put_for} : 'update' ),
26             with => $params,
27             );
28              
29 1   50     61644 my $primary_column = $self->config->{primary_key_column} || 'id';
30              
31 1         110 my @params = @{ $c->req->captures };
  1         10  
32 1         99 $params[-1] = $something->$primary_column;
33              
34 1         19 $self->status_accepted(
35             $c,
36             location => $c->uri_for( $self->action_for('result'), [@params] )->as_string,
37             entity => { $primary_column => $something->$primary_column }
38             );
39              
40 1         4610 $self->$orig(@_);
41              
42             }
43              
44             1;