| 1 | package Catalyst::Action::Deserialize::Data::Serializer; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | extends 'Catalyst::Action'; | |||||||||
| 7 | 1 | ▶ | use Data::Serializer; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Safe; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Scalar::Util qw(openhandle); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | my $compartment = Safe->new; | |||||||||
| 11 | 1 | $compartment->permit_only( qw(padany null lineseq const pushmark list anonhash anonlist refgen leaveeval undef) ); | |||||||||
| 12 | |||||||||||
| 13 | 1 | our $VERSION = '1.08'; | |||||||||
| 14 | 1 | $VERSION = eval $VERSION; | |||||||||
| 15 | |||||||||||
| 16 | 9 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: called CC=10 SCAR=24.5
Pod
documented
| |||||||||||
| 17 | 9 | my $self = shift; | |||||||||
| 18 | 9 | my ( $controller, $c, $serializer ) = @_; | |||||||||
| 19 | |||||||||||
| 20 | 9 | my $sp = $serializer; | |||||||||
| 21 | 9 | $sp =~ s/::/\//g; | |||||||||
| 22 | 9 | $sp .= ".pm"; | |||||||||
| 23 | 9 | eval { | |||||||||
| 24 | 9 | require $sp | |||||||||
| 25 | }; | ||||||||||
| 26 | 9 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 0 | ▶ | $c->log->debug("Could not load $serializer, refusing to serialize: $@") | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | if $c->debug; | ||||||||||
| 29 | 0 | return 0; | |||||||||
| 30 | } | ||||||||||
| 31 | 9 | my $body = $c->request->body; | |||||||||
| 32 | 9 | ▶ | if ($body) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 9 | my $rbody = ''; | |||||||||
| 34 | |||||||||||
| 35 | 9 | ▶ | if(openhandle $body) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 9 | seek($body, 0, 0); # in case something has already read from it | |||||||||
| 37 | 9 | ▶ | while ( defined( my $line = <$body> ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 16 | $rbody .= $line; | |||||||||
| 39 | } | ||||||||||
| 40 | } else { | ||||||||||
| 41 | 0 | $rbody = $body; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 9 | my $rdata; | |||||||||
| 45 | 9 | ▶ | if ( $serializer eq "Data::Dumper" ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | # Taken from Data::Serialize::Data::Dumper::deserialize, but run within a Safe compartment | ||||||||||
| 47 | 3 | ▶ | my $code = $rbody =~ /^\{/ ? "+".$rbody : $rbody; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 3 | $rdata = $compartment->reval( $code ); | |||||||||
| 49 | } | ||||||||||
| 50 | else { | ||||||||||
| 51 | 6 | my $dso = Data::Serializer->new( serializer => $serializer ); | |||||||||
| 52 | 6 | eval { | |||||||||
| 53 | 6 | $rdata = $dso->raw_deserialize($rbody); | |||||||||
| 54 | }; | ||||||||||
| 55 | } | ||||||||||
| 56 | 9 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 2 | return $@; | |||||||||
| 58 | } | ||||||||||
| 59 | 7 | $c->request->data($rdata); | |||||||||
| 60 | } else { | ||||||||||
| 61 | 0 | ▶ | $c->log->debug( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 'I would have deserialized, but there was nothing in the body!') | ||||||||||
| 63 | if $c->debug; | ||||||||||
| 64 | } | ||||||||||
| 65 | 7 | return 1; | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 69 | |||||||||||
| 70 | 1 | 1; | |||||||||