use json for serialized data in tests
[catagits/Catalyst-Runtime.git] / t / lib / TestApp / Controller / Fork.pm
CommitLineData
09274aae 1# Fork.pm
2# Copyright (c) 2006 Jonathan Rockway <jrockway@cpan.org>
3
4package TestApp::Controller::Fork;
5
6use strict;
7use warnings;
8use base 'Catalyst::Controller';
15f0ede8 9
8a1b06be 10use JSON::MaybeXS qw(encode_json);
09274aae 11
31b71f4b 12sub system : Local {
09274aae 13 my ($self, $c, $ls) = @_;
14 my ($result, $code) = (undef, 1);
15
16 if(!-e $ls || !-x _){
c7ded7aa 17 $result = 'skip';
09274aae 18 }
19 else {
c7ded7aa 20 $result = system($ls, $ls, $ls);
21 $result = $! if $result != 0;
09274aae 22 }
23
8a1b06be 24 $c->response->body(encode_json({result => $result}));
09274aae 25}
26
8d5f3e92 27sub backticks : Local {
28 my ($self, $c, $ls) = @_;
29 my ($result, $code) = (undef, 1);
30
31 if(!-e $ls || !-x _){
c7ded7aa 32 $result = 'skip';
33 $code = 0;
8d5f3e92 34 }
35 else {
c7ded7aa 36 $result = `$ls $ls $ls` || $!;
37 $code = $?;
8d5f3e92 38 }
39
8a1b06be 40 $c->response->body(encode_json({result => $result, code => $code}));
8d5f3e92 41}
31b71f4b 42
43sub fork : Local {
44 my ($self, $c) = @_;
45 my $pid;
46 my $x = 0;
47
48 if($pid = fork()){
c7ded7aa 49 $x = "ok";
31b71f4b 50 }
51 else {
c7ded7aa 52 exit(0);
31b71f4b 53 }
54
55 waitpid $pid,0 or die;
56
8a1b06be 57 $c->response->body(encode_json({pid => $pid, result => $x}));
31b71f4b 58}
59
09274aae 601;