why oh why does every class have VERSION???
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Deserialize / JSON.pm
index 75a168b..cea87ad 100644 (file)
@@ -2,23 +2,29 @@ package Catalyst::Action::Deserialize::JSON;
 
 use Moose;
 use namespace::autoclean;
+use Scalar::Util qw(openhandle);
 
 extends 'Catalyst::Action';
 use JSON;
 
-our $VERSION = '0.87';
+our $VERSION = '1.13';
 $VERSION = eval $VERSION;
 
 sub execute {
     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;
         }
     }
 
@@ -42,4 +48,6 @@ sub execute {
     return 1;
 }
 
+__PACKAGE__->meta->make_immutable;
+
 1;