bye bye Class::C3. for good.
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / HTTP / Restarter.pm
index 134e6be..4691cad 100644 (file)
@@ -1,28 +1,29 @@
 package Catalyst::Engine::HTTP::Restarter;
 
-use strict;
-use warnings;
-use base 'Catalyst::Engine::HTTP';
+use Moose;
+extends 'Catalyst::Engine::HTTP';
+
 use Catalyst::Engine::HTTP::Restarter::Watcher;
-use NEXT;
 
-sub run {
+around run => sub {
+    my $orig = shift;
     my ( $self, $class, $port, $host, $options ) = @_;
 
     $options ||= {};
 
     # Setup restarter
-    my $restarter;
-    my $parent = $$;
-
-    unless ( $restarter = fork ) {
+    unless ( my $restarter = fork ) {
 
         # Prepare
         close STDIN;
         close STDOUT;
 
         my $watcher = Catalyst::Engine::HTTP::Restarter::Watcher->new(
-            directory => File::Spec->catdir( $FindBin::Bin, '..' ),
+            directory => ( 
+                $options->{restart_directory} || 
+                File::Spec->catdir( $FindBin::Bin, '..' )
+            ),
+            follow_symlinks => $options->{follow_symlinks},
             regex     => $options->{restart_regex},
             delay     => $options->{restart_delay},
         );
@@ -49,25 +50,26 @@ sub run {
                     PeerAddr => $host,
                     PeerPort => $port
                   )
-                  or die "can't create client socket (is server running?): ",
+                  or die "Can't create client socket (is server running?): ",
                   $!;
 
                 # build the Kill request
                 my $req =
-                  HTTP::Request->new( 'KILL', '/',
+                  HTTP::Request->new( 'RESTART', '/',
                     HTTP::Headers->new( 'Connection' => 'close' ) );
                 $req->protocol('HTTP/1.0');
 
                 $client->send( $req->as_string )
-                  or die "can't send restart instruction: ", $!;
+                  or die "Can't send restart instruction: ", $!;
                 $client->close();
                 exit;
             }
         }
     }
 
-    return $self->NEXT::run( $class, $port, $host, $options );
-}
+    return $self->$orig( $class, $port, $host, $options );
+    no Moose;
+};
 
 1;
 __END__
@@ -87,11 +89,7 @@ and restart the server when any changes are detected.
 
 =head1 METHODS
 
-=over 4
-
-=item run
-
-=back
+=head2 run
 
 =head1 SEE ALSO