extends 'Catalyst::Action';
use Data::Serializer;
use Safe;
+use Scalar::Util qw(openhandle);
my $compartment = Safe->new;
$compartment->permit_only( qw(padany null lineseq const pushmark list anonhash anonlist refgen leaveeval undef) );
}
my $body = $c->request->body;
if ($body) {
- my $rbody;
- if ( -f $c->request->body ) {
- open( BODY, "<", $c->request->body );
- while ( my $line = <BODY> ) {
+ my $rbody = '';
+
+ if(openhandle $body) {
+ seek($body, 0, 0); # in case something has already read from it
+ while ( defined( my $line = <$body> ) ) {
$rbody .= $line;
}
- close(BODY);
+ } else {
+ $rbody = $body;
}
+
my $rdata;
if ( $serializer eq "Data::Dumper" ) {
# Taken from Data::Serialize::Data::Dumper::deserialize, but run within a Safe compartment
use Moose;
use namespace::autoclean;
+use Scalar::Util qw(openhandle);
extends 'Catalyst::Action';
use JSON;
my $self = shift;
my ( $controller, $c, $test ) = @_;
- my $body = $c->request->body;
my $rbody;
- if ($body) {
- while (my $line = <$body>) {
- $rbody .= $line;
+ # 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;
}
}
use Moose;
use namespace::autoclean;
+use Scalar::Util qw(openhandle);
extends 'Catalyst::Action';
my $xs = XML::Simple->new('ForceArray' => 0,);
my $rdata;
eval {
- $rdata = $xs->XMLin( "$body" );
+ if(openhandle $body){ # make sure we rewind the file handle
+ seek($body, 0, 0); # in case something has already read from it
+ }
+ $rdata = $xs->XMLin( $body );
};
if ($@) {
return $@;
use Moose;
use namespace::autoclean;
+use Scalar::Util qw(openhandle);
extends 'Catalyst::Action';
use YAML::Syck;
my $body = $c->request->body;
if ($body) {
+
+ my $rbody = '';
+
+ 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;
+ }
+
my $rdata;
eval {
- my $body = $c->request->body;
- $rdata = LoadFile( "$body" );
+ $rdata = Load( $rbody );
};
if ($@) {
return $@;