1 package Catalyst::Engine::HTTP::Restarter;
5 extends 'Catalyst::Engine::HTTP';
8 use Catalyst::Engine::HTTP::Restarter::Watcher;
11 my ( $self, $class, $port, $host, $options ) = @_;
16 unless ( my $restarter = fork ) {
22 my $watcher = Catalyst::Engine::HTTP::Restarter::Watcher->new(
24 $options->{restart_directory} ||
25 File::Spec->catdir( $FindBin::Bin, '..' )
27 follow_symlinks => $options->{follow_symlinks},
28 regex => $options->{restart_regex},
29 delay => $options->{restart_delay},
32 $host ||= '127.0.0.1';
35 # poll for changed files
36 my @changed_files = $watcher->watch();
38 # check if our parent process has died
39 exit if $^O ne 'MSWin32' and getppid == 1;
41 # Restart if any files have changed
43 my $files = join ', ', @changed_files;
44 print STDERR qq/File(s) "$files" modified, restarting\n\n/;
46 require IO::Socket::INET;
47 require HTTP::Headers;
48 require HTTP::Request;
50 my $client = IO::Socket::INET->new(
54 or die "Can't create client socket (is server running?): ",
57 # build the Kill request
59 HTTP::Request->new( 'RESTART', '/',
60 HTTP::Headers->new( 'Connection' => 'close' ) );
61 $req->protocol('HTTP/1.0');
63 $client->send( $req->as_string )
64 or die "Can't send restart instruction: ", $!;
71 return $self->next::method( $class, $port, $host, $options );
79 Catalyst::Engine::HTTP::Restarter - Catalyst Auto-Restarting HTTP Engine
83 script/myapp_server.pl -restart
87 The Restarter engine will monitor files in your application for changes
88 and restart the server when any changes are detected.
96 L<Catalyst>, L<Catalyst::Engine::HTTP>, L<Catalyst::Engine::CGI>,
101 Sebastian Riedel, <sri@cpan.org>
103 Dan Kubb, <dan.kubb-cpan@onautopilot.com>
105 Andy Grundman, <andy@hybridized.org>
109 Many parts are ripped out of C<HTTP::Server::Simple> by Jesse Vincent.
113 This program is free software, you can redistribute it and/or modify it under
114 the same terms as Perl itself.