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