1 package Catalyst::Engine::HTTP::Restarter;
5 use base 'Catalyst::Engine::HTTP';
6 use Catalyst::Engine::HTTP::Restarter::Watcher;
10 my ( $self, $class, $port, $host, $options ) = @_;
14 die qq/Sorry, but "restart" doesn't work together with "fork".\n/
21 unless ( $restarter = fork ) {
27 my $watcher = Catalyst::Engine::HTTP::Restarter::Watcher->new(
28 directory => File::Spec->catdir( $FindBin::Bin, '..' ),
29 regex => $options->{restart_regex},
30 delay => $options->{restart_delay},
33 $host ||= '127.0.0.1';
36 # poll for changed files
37 my @changed_files = $watcher->watch();
39 # check if our parent process has died
40 exit if $^O ne 'MSWin32' and getppid == 1;
42 # Restart if any files have changed
44 my $files = join ', ', @changed_files;
45 print STDERR qq/File(s) "$files" modified, restarting\n\n/;
47 require IO::Socket::INET;
48 require HTTP::Headers;
49 require HTTP::Request;
51 my $client = IO::Socket::INET->new(
55 or die "Can't create client socket (is server running?): ",
58 # build the Kill request
60 HTTP::Request->new( 'KILL', '/',
61 HTTP::Headers->new( 'Connection' => 'close' ) );
62 $req->protocol('HTTP/1.0');
64 $client->send( $req->as_string )
65 or die "Can't send restart instruction: ", $!;
72 return $self->NEXT::run( $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.
101 L<Catalyst>, L<Catalyst::Engine::HTTP>, L<Catalyst::Engine::CGI>,
106 Sebastian Riedel, <sri@cpan.org>
108 Dan Kubb, <dan.kubb-cpan@onautopilot.com>
110 Andy Grundman, <andy@hybridized.org>
114 Many parts are ripped out of C<HTTP::Server::Simple> by Jesse Vincent.
118 This program is free software, you can redistribute it and/or modify it under
119 the same terms as Perl itself.