65a8e3e789de45948158027429e6e1140f4b05f3
[catagits/Catalyst-Devel.git] / lib / Catalyst / Restarter / Win32.pm
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 _fork_and_start {
15     my $self = shift;
16
17     # This is totally hack-tastic, and is probably much slower, but it
18     # does seem to work.
19     my @command = ( $^X, $0, grep { ! /^\-r/ } @{ $self->argv } );
20
21     my $child = Proc::Background->new(@command);
22
23     $self->_child($child);
24 }
25
26 sub _kill_child {
27     my $self = shift;
28
29     return unless $self->_child;
30
31     $self->_child->die;
32 }
33
34 1;
35
36 __END__
37
38 =head1 NAME
39
40 Catalyst::Restarter::Win32 - Uses Proc::Background to manage process restarts
41
42 =head1 DESCRIPTION
43
44 This class uses L<Proc::Background>, which in turn uses
45 L<Win32::Process>. The new process is run using the same command-line
46 as the original script, but without any restart-based options.
47
48 This is a big hack, but using forks just does not work on Windows.
49
50 =head1 SEE ALSO
51
52 L<Catalyst::Restarter>, L<Catalyst>, <File::ChangeNotify>
53
54 =head1 AUTHORS
55
56 Catalyst Contributors, see Catalyst.pm
57
58 =head1 COPYRIGHT
59
60 This program is free software, you can redistribute it and/or modify
61 it under the same terms as Perl itself.
62
63 =cut