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