1 package Catalyst::Engine::HTTP::Daemon;
4 use base 'Catalyst::Engine::HTTP::Base';
6 use IO::Socket qw(AF_INET INADDR_ANY SOCK_STREAM SOMAXCONN );
10 Catalyst::Engine::HTTP::Daemon - Catalyst HTTP Daemon Engine
14 A script using the Catalyst::Engine::HTTP::Daemon module might look like:
18 BEGIN { $ENV{CATALYST_ENGINE} = 'HTTP::Daemon' }
21 use lib '/path/to/MyApp/lib';
28 This is the Catalyst engine specialized for development and testing.
30 =head1 OVERLOADED METHODS
32 This class overloads some methods from C<Catalyst::Engine::HTTP::Base>.
40 $SIG{'PIPE'} = 'IGNORE';
44 my $port = shift || 3000;
46 $HTTP::Daemon::PROTO = 'HTTP/1.0'; # For now until we resolve the blocking
47 # issues with HTTP 1.1
49 my $daemon = Catalyst::Engine::HTTP::Daemon::Catalyst->new(
57 die("Failed to create daemon: $!\n");
60 my $base = URI->new( $daemon->url )->canonical;
62 printf( "You can connect to your server at %s\n", $base );
64 while ( my $connection = $daemon->accept ) {
66 $connection->timeout(5);
68 while ( my $request = $connection->get_request ) {
70 $request->uri->scheme('http'); # Force URI::http
71 $request->uri->host( $request->header('Host') || $base->host );
72 $request->uri->port( $base->port );
74 my $hostname = gethostbyaddr( $connection->peeraddr, AF_INET );
76 my $http = Catalyst::Engine::HTTP::Base::struct->new(
77 address => $connection->peerhost,
78 hostname => $hostname || $connection->peerhost,
80 response => HTTP::Response->new
83 $class->handler($http);
84 $connection->send_response( $http->response );
96 L<Catalyst>, L<Catalyst::Engine>, L<Catalyst::Engine::HTTP::Base>,
101 Sebastian Riedel, C<sri@cpan.org>
102 Christian Hansen, C<ch@ngmedia.com>
106 This program is free software, you can redistribute it and/or modify it under
107 the same terms as Perl itself.
111 package Catalyst::Engine::HTTP::Daemon::Catalyst;
114 use base 'HTTP::Daemon';
117 "Catalyst/$Catalyst::VERSION";