File Coverage

lib/Catalyst/Action/Deserialize/Callback.pm
Criterion Covered Total %
statement 23 26 88.4
branch 4 10 40.0
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 32 41 78.0


line stmt bran cond sub pod time code
1             package Catalyst::Action::Deserialize::Callback;
2             $Catalyst::Action::Deserialize::Callback::VERSION = '1.21';
3 1     1   6 use Moose;
  1         2  
  1         6  
4 1     1   5420 use namespace::autoclean;
  1         3  
  1         7  
5 1     1   68 use Scalar::Util qw(openhandle);
  1         2  
  1         245  
6              
7             extends 'Catalyst::Action';
8              
9             sub execute {
10 1     1 1 1     my $self = shift;
11 1         2     my ( $controller, $c, $callbacks ) = @_;
12              
13 1         2     my $rbody;
14              
15             # could be a string or a FH
16 1 50       20     if ( my $body = $c->request->body ) {
17 1 50       99         if(openhandle $body) {
18 1         12             seek($body, 0, 0); # in case something has already read from it
19 1         14             while ( defined( my $line = <$body> ) ) {
20 1         5                 $rbody .= $line;
21                         }
22                     } else {
23 0         0             $rbody = $body;
24                     }
25                 }
26              
27 1 50       3     if ( $rbody ) {
28 1         2         my $rdata = eval { $callbacks->{deserialize}->( $rbody, $controller, $c ) };
  1         5  
29 1 50       8         if ($@) {
30 0         0             return $@;
31                     }
32 1         23         $c->request->data($rdata);
33                 } else {
34 0 0       0         $c->log->debug(
35                         'I would have deserialized, but there was nothing in the body!')
36                         if $c->debug;
37                 }
38 1         3     return 1;
39             }
40              
41             __PACKAGE__->meta->make_immutable;
42              
43             1;
44              
45