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'; |
15f0ede8 |
10 | |
11 | eval 'use YAML'; |
09274aae |
12 | |
31b71f4b |
13 | sub system : Local { |
09274aae |
14 | my ($self, $c, $ls) = @_; |
15 | my ($result, $code) = (undef, 1); |
16 | |
17 | if(!-e $ls || !-x _){ |
c7ded7aa |
18 | $result = 'skip'; |
09274aae |
19 | } |
20 | else { |
c7ded7aa |
21 | $result = system($ls, $ls, $ls); |
22 | $result = $! if $result != 0; |
09274aae |
23 | } |
24 | |
a147e337 |
25 | $c->response->body(Dump({result => $result})); |
09274aae |
26 | } |
27 | |
8d5f3e92 |
28 | sub backticks : Local { |
29 | my ($self, $c, $ls) = @_; |
30 | my ($result, $code) = (undef, 1); |
31 | |
32 | if(!-e $ls || !-x _){ |
c7ded7aa |
33 | $result = 'skip'; |
34 | $code = 0; |
8d5f3e92 |
35 | } |
36 | else { |
c7ded7aa |
37 | $result = `$ls $ls $ls` || $!; |
38 | $code = $?; |
8d5f3e92 |
39 | } |
40 | |
41 | $c->response->body(Dump({result => $result, code => $code})); |
42 | } |
31b71f4b |
43 | |
44 | sub fork : Local { |
45 | my ($self, $c) = @_; |
46 | my $pid; |
47 | my $x = 0; |
48 | |
49 | if($pid = fork()){ |
c7ded7aa |
50 | $x = "ok"; |
31b71f4b |
51 | } |
52 | else { |
c7ded7aa |
53 | exit(0); |
31b71f4b |
54 | } |
55 | |
56 | waitpid $pid,0 or die; |
57 | |
58 | $c->response->body(Dump({pid => $pid, result => $x})); |
59 | } |
60 | |
09274aae |
61 | 1; |