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