/usr/share/perl5/Catalyst/Action/Deserialize/JSON.pm is in libcatalyst-action-rest-perl 0.94-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | package Catalyst::Action::Deserialize::JSON;
use Moose;
use namespace::autoclean;
use Scalar::Util qw(openhandle);
extends 'Catalyst::Action';
use JSON;
our $VERSION = '0.94';
$VERSION = eval $VERSION;
sub execute {
my $self = shift;
my ( $controller, $c, $test ) = @_;
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 $json = JSON->new->utf8;
if (my $options = $controller->{json_options}) {
foreach my $opt (keys %$options) {
$json->$opt( $options->{$opt} );
}
}
my $rdata = eval { $json->decode( $rbody ) };
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;
|