Fix the restarter in devel branch hopefully
Tomas Doran [Mon, 5 Oct 2009 22:11:21 +0000 (22:11 +0000)]
lib/Catalyst/Restarter.pm
lib/Catalyst/Restarter/Forking.pm
lib/Catalyst/Restarter/Win32.pm

index 55f8329..2e1980e 100644 (file)
@@ -1,10 +1,11 @@
 package Catalyst::Restarter;
+
 use Moose;
 
 use Cwd qw( abs_path );
 use File::ChangeNotify;
 use FindBin;
-use namespace::autoclean;
+use namespace::clean -except => 'meta';
 
 has start_sub => (
     is       => 'ro',
@@ -12,6 +13,12 @@ has start_sub => (
     required => 1,
 );
 
+has argv =>  (
+    is       => 'ro',
+    isa      => 'ArrayRef',
+    required => 1,
+);
+
 has _watcher => (
     is  => 'rw',
     isa => 'File::ChangeNotify::Watcher',
@@ -47,7 +54,7 @@ sub BUILD {
 
     delete $p->{start_sub};
 
-    $p->{filter} ||= qr/(?:\/|^)(?!\.\#).+(?:\.yml$|\.yaml$|\.conf|\.pm)$/;
+    $p->{filter} ||= qr/(?:\/|^)(?![.#_]).+(?:\.yml$|\.yaml$|\.conf|\.pm)$/;
     $p->{directories} ||= abs_path( File::Spec->catdir( $FindBin::Bin, '..' ) );
 
     # We could make this lazily, but this lets us check that we
index 94c2dde..0897019 100644 (file)
@@ -1,9 +1,6 @@
 package Catalyst::Restarter::Forking;
-use Moose;
 
-use threads;
-use Thread::Cancel;
-use namespace::autoclean;
+use Moose;
 
 extends 'Catalyst::Restarter';
 
@@ -31,9 +28,12 @@ sub _kill_child {
 
     return unless kill 0, $self->_child;
 
-    local $SIG{CHLD} = 'IGNORE';
     die "Cannot send INT signal to ", $self->_child, ": $!"
         unless kill 'INT', $self->_child;
+    # If we don't wait for the child to exit, we could attempt to
+    # start a new server before the old one has given up the port it
+    # was listening on.
+    wait;
 }
 
 1;
index 8aeee81..fb24a23 100644 (file)
@@ -1,7 +1,7 @@
 package Catalyst::Restarter::Win32;
+
 use Moose;
 use Proc::Background;
-use namespace::autoclean;
 
 extends 'Catalyst::Restarter';
 
@@ -16,7 +16,7 @@ sub _fork_and_start {
 
     # This is totally hack-tastic, and is probably much slower, but it
     # does seem to work.
-    my @command = ( $^X, $0, grep { ! /^\-r/ } @ARGV );
+    my @command = ( $^X, map("-I$_", @INC), $0, grep { ! /^\-r/ } @{ $self->argv } );
 
     my $child = Proc::Background->new(@command);