1 package Catalyst::Engine::HTTP::Restarter;
6 extends 'Catalyst::Engine::HTTP';
9 use Catalyst::Engine::HTTP::Restarter::Watcher;
12 my ( $self, $class, $port, $host, $options ) = @_;
17 unless ( my $restarter = fork ) {
23 my $watcher = Catalyst::Engine::HTTP::Restarter::Watcher->new(
25 $options->{restart_directory} ||
26 File::Spec->catdir( $FindBin::Bin, '..' )
28 follow_symlinks => $options->{follow_symlinks},
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( 'RESTART', '/',
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::method( $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 Sebastian Riedel, <sri@cpan.org>
104 Dan Kubb, <dan.kubb-cpan@onautopilot.com>
106 Andy Grundman, <andy@hybridized.org>
110 Many parts are ripped out of C<HTTP::Server::Simple> by Jesse Vincent.
114 This program is free software, you can redistribute it and/or modify it under
115 the same terms as Perl itself.