Commit | Line | Data |
09274aae |
1 | #!/usr/bin/perl |
2 | # Fork.pm |
3 | # Copyright (c) 2006 Jonathan Rockway <jrockway@cpan.org> |
4 | |
5 | package TestApp::Controller::Fork; |
6 | |
7 | use strict; |
8 | use warnings; |
9 | use base 'Catalyst::Controller'; |
10 | use YAML; |
11 | |
31b71f4b |
12 | sub system : Local { |
09274aae |
13 | my ($self, $c, $ls) = @_; |
14 | my ($result, $code) = (undef, 1); |
15 | |
16 | if(!-e $ls || !-x _){ |
17 | $result = 'skip'; |
09274aae |
18 | } |
19 | else { |
a147e337 |
20 | $result = system($ls, $ls, $ls); |
21 | $result = $! if $result != 0; |
09274aae |
22 | } |
23 | |
a147e337 |
24 | $c->response->body(Dump({result => $result})); |
09274aae |
25 | } |
26 | |
8d5f3e92 |
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(Dump({result => $result, code => $code})); |
41 | } |
31b71f4b |
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(Dump({pid => $pid, result => $x})); |
58 | } |
59 | |
09274aae |
60 | 1; |