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 ) = @_;
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 regex => $options->{restart_regex},
27 delay => $options->{restart_delay},
30 $host ||= '127.0.0.1';
33 # poll for changed files
34 my @changed_files = $watcher->watch();
36 # check if our parent process has died
37 exit if $^O ne 'MSWin32' and getppid == 1;
39 # Restart if any files have changed
41 my $files = join ', ', @changed_files;
42 print STDERR qq/File(s) "$files" modified, restarting\n\n/;
44 require IO::Socket::INET;
45 require HTTP::Headers;
46 require HTTP::Request;
48 my $client = IO::Socket::INET->new(
52 or die "Can't create client socket (is server running?): ",
55 # build the Kill request
57 HTTP::Request->new( 'RESTART', '/',
58 HTTP::Headers->new( 'Connection' => 'close' ) );
59 $req->protocol('HTTP/1.0');
61 $client->send( $req->as_string )
62 or die "Can't send restart instruction: ", $!;
69 return $self->NEXT::run( $class, $port, $host, $options );
77 Catalyst::Engine::HTTP::Restarter - Catalyst Auto-Restarting HTTP Engine
81 script/myapp_server.pl -restart
85 The Restarter engine will monitor files in your application for changes
86 and restart the server when any changes are detected.
94 L<Catalyst>, L<Catalyst::Engine::HTTP>, L<Catalyst::Engine::CGI>,
99 Sebastian Riedel, <sri@cpan.org>
101 Dan Kubb, <dan.kubb-cpan@onautopilot.com>
103 Andy Grundman, <andy@hybridized.org>
107 Many parts are ripped out of C<HTTP::Server::Simple> by Jesse Vincent.
111 This program is free software, you can redistribute it and/or modify it under
112 the same terms as Perl itself.