Catalyst::Restarter::Forking: clear watcher in child process
[catagits/Catalyst-Devel.git] / lib / Catalyst / Restarter.pm
index c08517a..81295f1 100644 (file)
@@ -6,6 +6,7 @@ use Cwd qw( abs_path );
 use File::ChangeNotify;
 use File::Spec;
 use FindBin;
+use Catalyst::Utils;
 use namespace::clean -except => 'meta';
 
 has start_sub => (
@@ -21,8 +22,9 @@ has argv =>  (
 );
 
 has _watcher => (
-    is  => 'rw',
-    isa => 'File::ChangeNotify::Watcher',
+    is      => 'rw',
+    isa     => 'File::ChangeNotify::Watcher',
+    clearer => '_clear_watcher',
 );
 
 has _filter => (
@@ -48,8 +50,7 @@ sub pick_subclass {
 
     $subclass = 'Catalyst::Restarter::' . $subclass;
 
-    eval "use $subclass";
-    die $@ if $@;
+    Catalyst::Utils::ensure_class_loaded($subclass);
 
     return $subclass;
 }
@@ -116,9 +117,11 @@ sub _handle_events {
     for my $event (@events) {
         my $path = $event->path();
         my $type = $event->type();
-        if (   ( $type ne 'delete' && -f $path )
-            || ( $type eq 'delete' && $path =~ $self->_filter ) )
-        {
+        if ( (    ( $type ne 'delete' && -f $path )
+               || ( $type eq 'delete' )
+             )
+             && ( $path =~ $self->_filter )
+        ) {
             push @files, { path => $path, type => $type };
         }
     }