Don't break the calling convention for the run method by making the server the last...
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine.pm
index 62dc3bc..e6c5d62 100644 (file)
@@ -304,7 +304,8 @@ sub finalize_error {
 </html>
 
 
-    # Trick IE
+    # Trick IE. Old versions of IE would display their own error page instead
+    # of ours if we'd give it less than 512 bytes.
     $c->res->{body} .= ( ' ' x 512 );
 
     # Return 500
@@ -743,19 +744,32 @@ header.
 
 The amount of input data that has already been read.
 
-=head2 $self->run($c)
+=head2 $self->run($app, $server)
 
-Start the engine. Implemented by the various engine classes.
+Start the engine. Builds a PSGI application and calls the
+run method on the server passed in..
 
 =cut
 
 sub run {
-    my ($self, $app, $server, @args) = @_;
+    my ($self, $app, @args) = @_;
+    my $server = pop @args if blessed $args[-1];
+    $server ||= Plack::Loader->auto(); # We're not being called from a script,
+                                       # so auto detect what backend to run on.
+                                       # This does *NOT* cover mod_perl.
     # FIXME - Do something sensible with the options we're passed
-    $server->run($self->_build_psgi_app($app, @args));
+    my $psgi = $self->build_psgi_app($app, @args);
+    $server->run($psgi);
 }
 
-sub _build_psgi_app {
+=head2 build_psgi_app ($app, @args)
+
+Builds and returns a PSGI application closure, wrapping it in the reverse proxy
+middleware if the using_frontend_proxy config setting is set.
+
+=cut
+
+sub build_psgi_app {
     my ($self, $app, @args) = @_;
 
     my $psgi_app = sub {