1 package Catalyst::Engine::HTTP::Restarter;
4 extends 'Catalyst::Engine::HTTP';
6 use Catalyst::Engine::HTTP::Restarter::Watcher;
10 my ( $self, $class, $port, $host, $options ) = @_;
15 unless ( my $restarter = fork ) {
21 my $watcher = Catalyst::Engine::HTTP::Restarter::Watcher->new(
23 $options->{restart_directory} ||
24 File::Spec->catdir( $FindBin::Bin, '..' )
26 follow_symlinks => $options->{follow_symlinks},
27 regex => $options->{restart_regex},
28 delay => $options->{restart_delay},
31 $host ||= '127.0.0.1';
34 # poll for changed files
35 my @changed_files = $watcher->watch();
37 # check if our parent process has died
38 exit if $^O ne 'MSWin32' and getppid == 1;
40 # Restart if any files have changed
42 my $files = join ', ', @changed_files;
43 print STDERR qq/File(s) "$files" modified, restarting\n\n/;
45 require IO::Socket::INET;
46 require HTTP::Headers;
47 require HTTP::Request;
49 my $client = IO::Socket::INET->new(
53 or die "Can't create client socket (is server running?): ",
56 # build the Kill request
58 HTTP::Request->new( 'RESTART', '/',
59 HTTP::Headers->new( 'Connection' => 'close' ) );
60 $req->protocol('HTTP/1.0');
62 $client->send( $req->as_string )
63 or die "Can't send restart instruction: ", $!;
70 return $self->$orig( $class, $port, $host, $options );
80 Catalyst::Engine::HTTP::Restarter - Catalyst Auto-Restarting HTTP Engine
84 script/myapp_server.pl -restart
88 The Restarter engine will monitor files in your application for changes
89 and restart the server when any changes are detected.
97 L<Catalyst>, L<Catalyst::Engine::HTTP>, L<Catalyst::Engine::CGI>,
102 Catalyst Contributors, see Catalyst.pm
106 Many parts are ripped out of C<HTTP::Server::Simple> by Jesse Vincent.
110 This program is free software, you can redistribute it and/or modify it under
111 the same terms as Perl itself.