Tidy up dependencies
[catagits/Catalyst-Devel.git] / lib / Catalyst / Restarter / Forking.pm
1 package Catalyst::Restarter::Forking;
2 use Moose;
3
4 use threads;
5 use Thread::Cancel;
6 use namespace::autoclean;
7
8 extends 'Catalyst::Restarter';
9
10 has _child => (
11     is  => 'rw',
12     isa => 'Int',
13 );
14
15
16 sub _fork_and_start {
17     my $self = shift;
18
19     if ( my $pid = fork ) {
20         $self->_child($pid);
21     }
22     else {
23         $self->start_sub->();
24     }
25 }
26
27 sub _kill_child {
28     my $self = shift;
29
30     return unless $self->_child;
31
32     return unless kill 0, $self->_child;
33
34     local $SIG{CHLD} = 'IGNORE';
35     die "Cannot send INT signal to ", $self->_child, ": $!"
36         unless kill 'INT', $self->_child;
37 }
38
39 1;
40
41 __END__
42
43 =head1 NAME
44
45 Catalyst::Restarter::Forking - Forks and restarts the child process
46
47 =head1 DESCRIPTION
48
49 This class forks and runs the server in a child process. When it needs
50 to restart, it kills the child and creates a new one.
51
52 =head1 SEE ALSO
53
54 L<Catalyst::Restarter>, L<Catalyst>, <File::ChangeNotify>
55
56 =head1 AUTHORS
57
58 Catalyst Contributors, see Catalyst.pm
59
60 =head1 COPYRIGHT
61
62 This program is free software, you can redistribute it and/or modify
63 it under the same terms as Perl itself.
64
65 =cut