Commit | Line | Data |
2e9609df |
1 | package Catalyst::Restarter::Win32; |
2 | |
3 | use Moose; |
4 | use Proc::Background; |
5 | |
6 | extends 'Catalyst::Restarter'; |
7 | |
8 | has _child => ( |
9 | is => 'rw', |
10 | isa => 'Proc::Background', |
11 | ); |
12 | |
13 | |
14 | sub run_and_watch { |
15 | my $self = shift; |
16 | |
17 | $self->_fork_and_start; |
18 | |
19 | return unless $self->_child; |
20 | |
21 | $self->_restart_on_changes; |
22 | } |
23 | |
24 | sub _fork_and_start { |
25 | my $self = shift; |
26 | |
27 | # This is totally hack-tastic, and is probably much slower, but it |
28 | # does seem to work. |
29 | my @command = ( $^X, $0, grep { ! /^\-r/ } @ARGV ); |
30 | |
31 | my $child = Proc::Background->new(@command); |
32 | |
33 | $self->_child($child); |
34 | } |
35 | |
36 | sub _kill_child { |
37 | my $self = shift; |
38 | |
39 | return unless $self->_child; |
40 | |
41 | $self->_child->die; |
42 | } |
43 | |
44 | 1; |