Removing C::E::CGI::NPH
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / HTTP.pm
CommitLineData
ca61af20 1package Catalyst::Engine::HTTP;
45374ac6 2
3use strict;
75fd617a 4use base 'Catalyst::Engine::Test';
45374ac6 5
6use IO::Socket qw(AF_INET);
7
8=head1 NAME
9
ca61af20 10Catalyst::Engine::HTTP - Catalyst HTTP Engine
45374ac6 11
12=head1 SYNOPSIS
13
ca61af20 14A script using the Catalyst::Engine::HTTP module might look like:
45374ac6 15
16 #!/usr/bin/perl -w
17
ca61af20 18 BEGIN { $ENV{CATALYST_ENGINE} = 'HTTP' }
45374ac6 19
20 use strict;
21 use lib '/path/to/MyApp/lib';
22 use MyApp;
23
24 MyApp->run;
25
26=head1 DESCRIPTION
27
28This is the Catalyst engine specialized for development and testing.
29
30=head1 OVERLOADED METHODS
31
75fd617a 32This class overloads some methods from C<Catalyst::Engine::Test>.
45374ac6 33
34=over 4
35
36=item $c->run
37
38=cut
39
40$SIG{'PIPE'} = 'IGNORE';
41
42sub run {
43 my $class = shift;
44 my $port = shift || 3000;
45
ca61af20 46 my $daemon = Catalyst::Engine::HTTP::Catalyst->new(
45374ac6 47 LocalPort => $port,
48 ReuseAddr => 1
49 );
50
66d9e175 51 unless ($daemon) {
52 die("Failed to create daemon: $!\n");
45374ac6 53 }
54
b333ca6b 55 my $base = URI->new( $daemon->url )->canonical;
56
57 printf( "You can connect to your server at %s\n", $base );
45374ac6 58
59 while ( my $connection = $daemon->accept ) {
60
61 while ( my $request = $connection->get_request ) {
62
63 $request->uri->scheme('http'); # Force URI::http
b333ca6b 64 $request->uri->host( $base->host );
523d44ec 65 $request->uri->port( $base->port );
45374ac6 66
75fd617a 67 my $lwp = Catalyst::Engine::Test::LWP->new(
45374ac6 68 request => $request,
69 address => $connection->peerhost,
70 hostname => gethostbyaddr( $connection->peeraddr, AF_INET )
71 );
72
6f4e1683 73 $class->handler($lwp);
74 $connection->send_response( $lwp->response );
45374ac6 75 }
76
77 $connection->close;
78 undef($connection);
79 }
80}
81
82=back
83
84=head1 SEE ALSO
85
86L<Catalyst>, L<HTTP::Daemon>.
87
88=head1 AUTHOR
89
90Sebastian Riedel, C<sri@cpan.org>
91Christian Hansen, C<ch@ngmedia.com>
92
93=head1 COPYRIGHT
94
95This program is free software, you can redistribute it and/or modify it under
96the same terms as Perl itself.
97
98=cut
99
ca61af20 100package Catalyst::Engine::HTTP::Catalyst;
45374ac6 101
102use strict;
103use base 'HTTP::Daemon';
104
105sub product_tokens {
106 "Catalyst/$Catalyst::VERSION";
107}
108
1091;