Catalyst-Action-REST
view release on metacpan or search on metacpan
lib/Catalyst/Action/Deserialize/Callback.pm view on Meta::CPAN
package Catalyst::Action::Deserialize::Callback;
$Catalyst::Action::Deserialize::Callback::VERSION = '1.22';
use Moose;
use namespace::autoclean;
use Scalar::Util qw(openhandle);
extends 'Catalyst::Action';
sub execute {
my $self = shift;
my ( $controller, $c, $callbacks ) = @_;
my $rbody;
# could be a string or a FH
if ( my $body = $c->request->body ) {
if(openhandle $body) {
seek($body, 0, 0); # in case something has already read from it
while ( defined( my $line = <$body> ) ) {
$rbody .= $line;
}
} else {
$rbody = $body;
}
}
if ( $rbody ) {
my $rdata = eval { $callbacks->{deserialize}->( $rbody, $controller, $c ) };
if ($@) {
return $@;
}
$c->request->data($rdata);
} else {
$c->log->debug(
'I would have deserialized, but there was nothing in the body!')
if $c->debug;
}
return 1;
}
__PACKAGE__->meta->make_immutable;
1;
( run in 2.627 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )