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(
22 directory => File::Spec->catdir( $FindBin::Bin, '..' ),
23 regex => $options->{restart_regex},
24 delay => $options->{restart_delay},
27 $host ||= '127.0.0.1';
30 # poll for changed files
31 my @changed_files = $watcher->watch();
33 # check if our parent process has died
34 exit if $^O ne 'MSWin32' and getppid == 1;
36 # Restart if any files have changed
38 my $files = join ', ', @changed_files;
39 print STDERR qq/File(s) "$files" modified, restarting\n\n/;
41 require IO::Socket::INET;
42 require HTTP::Headers;
43 require HTTP::Request;
45 my $client = IO::Socket::INET->new(
49 or die "Can't create client socket (is server running?): ",
52 # build the Kill request
54 HTTP::Request->new( 'RESTART', '/',
55 HTTP::Headers->new( 'Connection' => 'close' ) );
56 $req->protocol('HTTP/1.0');
58 $client->send( $req->as_string )
59 or die "Can't send restart instruction: ", $!;
66 return $self->NEXT::run( $class, $port, $host, $options );
74 Catalyst::Engine::HTTP::Restarter - Catalyst Auto-Restarting HTTP Engine
78 script/myapp_server.pl -restart
82 The Restarter engine will monitor files in your application for changes
83 and restart the server when any changes are detected.
91 L<Catalyst>, L<Catalyst::Engine::HTTP>, L<Catalyst::Engine::CGI>,
96 Sebastian Riedel, <sri@cpan.org>
98 Dan Kubb, <dan.kubb-cpan@onautopilot.com>
100 Andy Grundman, <andy@hybridized.org>
104 Many parts are ripped out of C<HTTP::Server::Simple> by Jesse Vincent.
108 This program is free software, you can redistribute it and/or modify it under
109 the same terms as Perl itself.