use json for serialized data in tests
[catagits/Catalyst-Runtime.git] / t / lib / TestApp / Controller / Fork.pm
index b6992ab..2645e6e 100644 (file)
@@ -1,4 +1,3 @@
-#!/usr/bin/perl
 # Fork.pm 
 # Copyright (c) 2006 Jonathan Rockway <jrockway@cpan.org>
 
@@ -7,22 +6,22 @@ package TestApp::Controller::Fork;
 use strict;
 use warnings;
 use base 'Catalyst::Controller';
-use YAML;
+
+use JSON::MaybeXS qw(encode_json);
 
 sub system : Local {
     my ($self, $c, $ls) = @_;
     my ($result, $code) = (undef, 1);
 
     if(!-e $ls || !-x _){ 
-       $result = 'skip';
-       $code = 0;
+        $result = 'skip';
     }
     else {
-       $result = system($ls, $ls, $ls) || $!;
-       $code = $?;
+        $result = system($ls, $ls, $ls);
+        $result = $! if $result != 0;
     }
     
-    $c->response->body(Dump({result => $result, code => $code}));
+    $c->response->body(encode_json({result => $result}));
 }
 
 sub backticks : Local {
@@ -30,15 +29,15 @@ sub backticks : Local {
     my ($result, $code) = (undef, 1);
     
     if(!-e $ls || !-x _){ 
-       $result = 'skip';
-       $code = 0;
+        $result = 'skip';
+        $code = 0;
     }
     else {
-       $result = `$ls $ls $ls` || $!;
-       $code = $?;
+        $result = `$ls $ls $ls` || $!;
+        $code = $?;
     }
     
-    $c->response->body(Dump({result => $result, code => $code}));
+    $c->response->body(encode_json({result => $result, code => $code}));
 }
 
 sub fork : Local {
@@ -47,15 +46,15 @@ sub fork : Local {
     my $x = 0;
     
     if($pid = fork()){
-       $x = "ok";
+        $x = "ok";
     }
     else {
-       exit(0);
+        exit(0);
     }
 
     waitpid $pid,0 or die;
     
-    $c->response->body(Dump({pid => $pid, result => $x}));
+    $c->response->body(encode_json({pid => $pid, result => $x}));
 }
 
 1;