Don't break the calling convention for the run method by making the server the last...
[catagits/Catalyst-Runtime.git] / lib / Catalyst / ScriptRole.pm
index 535ed3d..e36ca2f 100644 (file)
@@ -1,5 +1,6 @@
 package Catalyst::ScriptRole;
 use Moose::Role;
+use Plack::Runner;
 use MooseX::Types::Moose qw/Str Bool/;
 use Pod::Usage;
 use MooseX::Getopt;
@@ -55,11 +56,23 @@ sub _application_args {
     ()
 }
 
+sub _plack_loader_args {
+    my @app_args = shift->_application_args;
+    return (port => $app_args[0]);
+}
+
 sub _run_application {
     my $self = shift;
     my $app = $self->application_name;
     Class::MOP::load_class($app);
-    $app->run($self->_application_args);
+    my $server;
+    if (my $e = $self->can('_plack_engine_name') ) {
+        $server = Plack::Loader->load($self->$e, $self->_plack_loader_args);
+    }
+    else {
+        $server = Plack::Loader->auto($self->_plack_loader_args);
+    }
+    $app->run($self->_application_args, $server);
 }
 
 1;