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.20';
3 1     1   7 use Moose;
  1         2  
  1         10  
4 1     1   6743 use namespace::autoclean;
  1         3  
  1         11  
5 1     1   78 use Scalar::Util qw(openhandle);
  1         2  
  1         360  
6              
7             extends 'Catalyst::Action';
8              
9             sub execute {
10 1     1 1 3 my $self = shift;
11 1         2 my ( $controller, $c, $callbacks ) = @_;
12              
13 1         3 my $rbody;
14              
15             # could be a string or a FH
16 1 50       33 if ( my $body = $c->request->body ) {
17 1 50       153 if(openhandle $body) {
18 1         12 seek($body, 0, 0); # in case something has already read from it
19 1         19 while ( defined( my $line = <$body> ) ) {
20 1         7 $rbody .= $line;
21             }
22             } else {
23 0         0 $rbody = $body;
24             }
25             }
26              
27 1 50       5 if ( $rbody ) {
28 1         2 my $rdata = eval { $callbacks->{deserialize}->( $rbody, $controller, $c ) };
  1         7  
29 1 50       11 if ($@) {
30 0         0 return $@;
31             }
32 1         29 $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         32 return 1;
39             }
40              
41             __PACKAGE__->meta->make_immutable;
42              
43             1;
44