X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine%2FServer.pm;h=8db6d33cde9d873f513eae59532189e89fc4f9ee;hb=6f4e1683d466d0123cc7507b29a55b474ddca594;hp=47aa7f647788062f851d6c36ae59826f8374e788;hpb=a564a4be79ed0a4eb1dcba02a9ce19cef40b7452;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine/Server.pm b/lib/Catalyst/Engine/Server.pm index 47aa7f6..8db6d33 100644 --- a/lib/Catalyst/Engine/Server.pm +++ b/lib/Catalyst/Engine/Server.pm @@ -1,7 +1,7 @@ package Catalyst::Engine::Server; use strict; -use base 'Catalyst::Engine::CGI'; +use base 'Catalyst::Engine::LWP::Daemon'; =head1 NAME @@ -9,37 +9,27 @@ Catalyst::Engine::Server - Catalyst Server Engine =head1 SYNOPSIS -See L. +A script using the Catalyst::Engine::Server module might look like: -=head1 DESCRIPTION - -This is the Catalyst engine specialized for development and testing. - -=head1 OVERLOADED METHODS - -This class overloads some methods from C. - -=over 4 + #!/usr/bin/perl -w -=item $c->run - -=cut + BEGIN { + $ENV{CATALYST_ENGINE} = 'Server'; + } -sub run { - my $class = shift; - my $port = shift || 3000; + use strict; + use lib '/path/to/MyApp/lib'; + use MyApp; - my $server = Catalyst::Engine::Server::Simple->new($port); + MyApp->run; - $server->handler( sub { $class->handler } ); - $server->run; -} +=head1 DESCRIPTION -=back +This is the Catalyst engine specialized for development and testing. =head1 SEE ALSO -L, L. +L, L. =head1 AUTHOR @@ -53,83 +43,4 @@ the same terms as Perl itself. =cut -package Catalyst::Engine::Server::Simple; - -use strict; -use base 'HTTP::Server::Simple'; - -my %CLEAN_ENV = %ENV; - -sub handler { - my $self = shift; - - if (@_) { - $self->{handler} = shift; - } - - else { - $self->{handler}->(); - } -} - -sub print_banner { - my $self = shift; - - printf( - "You can connect to your server at http://%s:%d/\n", - $self->host || 'localhost', - $self->port - ); -} - -sub accept_hook { - %ENV = ( %CLEAN_ENV, SERVER_SOFTWARE => "Catalyst/$Catalyst::VERSION" ); -} - -our %env_mapping = ( - protocol => "SERVER_PROTOCOL", - localport => "SERVER_PORT", - localname => "SERVER_NAME", - path => "PATH_INFO", - request_uri => "REQUEST_URI", - method => "REQUEST_METHOD", - peeraddr => "REMOTE_ADDR", - peername => "REMOTE_HOST", - query_string => "QUERY_STRING", -); - -sub setup { - no warnings 'uninitialized'; - my $self = shift; - - while ( my ( $item, $value ) = splice @_, 0, 2 ) { - if ( $self->can($item) ) { - $self->$item($value); - } - elsif ( my $k = $env_mapping{$item} ) { - $ENV{$k} = $value; - } - } -} - -sub headers { - my $self = shift; - my $headers = shift; - - while ( my ( $tag, $value ) = splice @{$headers}, 0, 2 ) { - $tag = uc($tag); - $tag =~ s/^COOKIES$/COOKIE/; - $tag =~ s/-/_/g; - $tag = "HTTP_" . $tag - unless $tag =~ m/^CONTENT_(?:LENGTH|TYPE)$/; - - if ( exists $ENV{$tag} ) { - $ENV{$tag} .= "; $value"; - } - else { - $ENV{$tag} = $value; - } - } -} - 1;