Commit | Line | Data |
---|---|---|
256c894f | 1 | package Catalyst::Action::Deserialize::YAML; |
2 | ||
930013e6 | 3 | use Moose; |
4 | use namespace::autoclean; | |
1bb5ad32 | 5 | use Scalar::Util qw(openhandle); |
256c894f | 6 | |
930013e6 | 7 | extends 'Catalyst::Action'; |
256c894f | 8 | use YAML::Syck; |
256c894f | 9 | |
7cc6122a | 10 | our $VERSION = '1.12'; |
6edee33e | 11 | $VERSION = eval $VERSION; |
12 | ||
256c894f | 13 | sub execute { |
14 | my $self = shift; | |
15 | my ( $controller, $c, $test ) = @_; | |
eccb2137 | 16 | |
7ad87df9 | 17 | my $body = $c->request->body; |
18 | if ($body) { | |
1bb5ad32 | 19 | |
20 | my $rbody = ''; | |
21 | ||
22 | if(openhandle $body) { | |
23 | seek($body, 0, 0); # in case something has already read from it | |
24 | while ( defined( my $line = <$body> ) ) { | |
25 | $rbody .= $line; | |
26 | } | |
27 | } else { | |
28 | $rbody = $body; | |
29 | } | |
30 | ||
e601adda | 31 | my $rdata; |
32 | eval { | |
1bb5ad32 | 33 | $rdata = Load( $rbody ); |
e601adda | 34 | }; |
35 | if ($@) { | |
36 | return $@; | |
37 | } | |
256c894f | 38 | $c->request->data($rdata); |
256c894f | 39 | } else { |
eccb2137 | 40 | $c->log->debug( |
faf5c20b | 41 | 'I would have deserialized, but there was nothing in the body!') |
42 | if $c->debug; | |
256c894f | 43 | } |
e601adda | 44 | return 1; |
eccb2137 | 45 | } |
256c894f | 46 | |
24748286 | 47 | __PACKAGE__->meta->make_immutable; |
48 | ||
256c894f | 49 | 1; |